steps.py 4.0 KB

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