steps.py 3.8 KB

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