terrain.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #
  2. # This is the 'terrain' in which the lettuce lives. By convention, this is
  3. # where global setup and teardown is defined.
  4. #
  5. # We declare some attributes of the global 'world' variables here, so the
  6. # tests can safely assume they are present.
  7. #
  8. # We also use it to provide scenario invariants, such as resetting data.
  9. #
  10. from lettuce import *
  11. import subprocess
  12. import os.path
  13. import shutil
  14. # This is a list of files that are freshly copied before each scenario
  15. # The first element is the original, the second is the target that will be
  16. # used by the tests that need them
  17. copylist = [
  18. ["configurations/example.org.config.orig", "configurations/example.org.config"]
  19. ]
  20. @before.each_scenario
  21. def initialize(feature):
  22. # just make sure our cleanup won't fail if we never did
  23. # run the bind10 instance
  24. world.processes = {}
  25. world.processes_stdout = {}
  26. world.processes_stderr = {}
  27. world.last_query_result = None
  28. # Some tests can modify the settings. If the tests fail half-way, or
  29. # don't clean up, this can leave configurations or data in a bad state,
  30. # so we copy them from originals before each scenario
  31. for item in copylist:
  32. shutil.copy(item[0], item[1])
  33. @after.each_scenario
  34. def cleanup(feature):
  35. # Stop any running processes we may have had around
  36. for name in world.processes:
  37. world.processes[name].terminate()
  38. world.processes[name].wait()
  39. world.processes_stdout[name] = []
  40. world.processes_stderr[name] = []
  41. @world.absorb
  42. def stop_process(process_name):
  43. if process_name in world.processes:
  44. p = world.processes[process_name]
  45. p.terminate()
  46. p.wait()
  47. del world.processes[process_name]