steps.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2011 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. #
  16. # This file contains a number of common steps that are general and may be used
  17. # By a lot of feature files.
  18. #
  19. from lettuce import *
  20. import os
  21. @step('stop process (\w+)')
  22. def stop_a_named_process(step, process_name):
  23. """
  24. Stop the process with the given name.
  25. Parameters:
  26. process_name ('process <name>'): Name of the process to stop.
  27. """
  28. world.processes.stop_process(process_name)
  29. @step('wait for (new )?(\w+) stderr message (\w+)')
  30. def wait_for_message(step, new, process_name, message):
  31. """
  32. Block until the given message is printed to the given process's stderr
  33. output.
  34. Parameter:
  35. new: (' new', optional): Only check the output printed since last time
  36. this step was used for this process.
  37. process_name ('<name> stderr'): Name of the process to check the output of.
  38. message ('message <message>'): Output (part) to wait for.
  39. Fails if the message is not found after 10 seconds.
  40. """
  41. world.processes.wait_for_stderr_str(process_name, [message], new)
  42. @step('wait for (new )?(\w+) stdout message (\w+)')
  43. def wait_for_message(step, process_name, message):
  44. """
  45. Block until the given message is printed to the given process's stdout
  46. output.
  47. Parameter:
  48. new: (' new', optional): Only check the output printed since last time
  49. this step was used for this process.
  50. process_name ('<name> stderr'): Name of the process to check the output of.
  51. message ('message <message>'): Output (part) to wait for.
  52. Fails if the message is not found after 10 seconds.
  53. """
  54. world.processes.wait_for_stdout_str(process_name, [message], new)
  55. @step('the file (\S+) should (not )?exist')
  56. def check_existence(step, file_name, should_not_exist):
  57. """
  58. Check the existence of the given file.
  59. Parameters:
  60. file_name ('file <name>'): File to check existence of.
  61. should_not_exist ('not', optional): Whether it should or should not exist.
  62. Fails if the file should exist and does not, or vice versa.
  63. """
  64. if should_not_exist is None:
  65. assert os.path.exists(file_name), file_name + " does not exist"
  66. else:
  67. assert not os.path.exists(file_name), file_name + " exists"