steps.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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+)(?: not (\w+))?')
  30. def wait_for_message(step, new, process_name, message, not_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. not_message ('not <message>'): Output (part) to wait for, and fail
  40. Fails if the message is not found after 10 seconds.
  41. """
  42. strings = [message]
  43. if not_message is not None:
  44. strings.append(not_message)
  45. (found, line) = world.processes.wait_for_stderr_str(process_name, strings, new)
  46. if not_message is not None:
  47. assert found != not_message, line
  48. @step('wait for (new )?(\w+) stdout message (\w+)(?: not (\w+))?')
  49. def wait_for_message(step, process_name, message, not_message):
  50. """
  51. Block until the given message is printed to the given process's stdout
  52. output.
  53. Parameter:
  54. new: (' new', optional): Only check the output printed since last time
  55. this step was used for this process.
  56. process_name ('<name> stderr'): Name of the process to check the output of.
  57. message ('message <message>'): Output (part) to wait for, and succeed.
  58. not_message ('not <message>'): Output (part) to wait for, and fail
  59. Fails if the message is not found after 10 seconds.
  60. """
  61. strings = [message]
  62. if not_message is not None:
  63. strings.append(not_message)
  64. (found, line) = world.processes.wait_for_stdout_str(process_name, strings, new)
  65. if not_message is not None:
  66. assert found != not_message, line
  67. @step('the file (\S+) should (not )?exist')
  68. def check_existence(step, file_name, should_not_exist):
  69. """
  70. Check the existence of the given file.
  71. Parameters:
  72. file_name ('file <name>'): File to check existence of.
  73. should_not_exist ('not', optional): Whether it should or should not exist.
  74. Fails if the file should exist and does not, or vice versa.
  75. """
  76. if should_not_exist is None:
  77. assert os.path.exists(file_name), file_name + " does not exist"
  78. else:
  79. assert not os.path.exists(file_name), file_name + " exists"