/tests/app/test_env.py

https://bitbucket.org/prologic/circuits/ · Python · 123 lines · 68 code · 54 blank · 1 comment · 5 complexity · 7e212efc25868cc2198acc573060581c MD5 · raw file

  1. #!/usr/bin/env python
  2. import pytest
  3. def pytest_funcarg__path(request):
  4. tmpdir = request.getfuncargvalue("tmpdir")
  5. return tmpdir.join("env")
  6. def pytest_funcarg__env(request):
  7. return request.cached_setup(
  8. setup=lambda: setup_env(request),
  9. teardown=lambda env: teardown_env(env),
  10. scope="function")
  11. def setup_env(request):
  12. from circuits.app.env import Environment
  13. path = request.getfuncargvalue("path")
  14. env = Environment(str(path), "test")
  15. env.start()
  16. return env
  17. def teardown_env(env):
  18. env.stop()
  19. def test_create(env, path):
  20. from circuits.app.env import Create
  21. env.fire(Create())
  22. assert pytest.wait_event(env, "create_success")
  23. files = ("conf/test.ini", "README", "VERSION")
  24. for filename in files:
  25. assert path.join(filename).check(exists=True, file=True)
  26. def test_load(env, path):
  27. from circuits.app.env import Create, Load
  28. env.fire(Create())
  29. assert pytest.wait_event(env, "create_success")
  30. files = ("conf/test.ini", "README", "VERSION")
  31. for filename in files:
  32. assert path.join(filename).check(exists=True, file=True)
  33. env.fire(Load())
  34. assert pytest.wait_event(env, "load_success")
  35. def test_load_verify(env, path):
  36. from circuits.app.env import Create, Load
  37. env.fire(Create())
  38. assert pytest.wait_event(env, "create_success")
  39. files = ("conf/test.ini", "README", "VERSION")
  40. for filename in files:
  41. assert path.join(filename).check(exists=True, file=True)
  42. env.fire(Load(verify=True))
  43. assert pytest.wait_event(env, "load_success")
  44. def test_load_verify_fail(env, path):
  45. from circuits.app.env import Create, Load
  46. from circuits.app.env import EnvironmentError, ERRORS
  47. env.fire(Create())
  48. assert pytest.wait_event(env, "create_success")
  49. files = ("conf/test.ini", "README", "VERSION")
  50. for filename in files:
  51. assert path.join(filename).check(exists=True, file=True)
  52. path.join("VERSION").write("")
  53. v = env.fire(Load(verify=True))
  54. assert pytest.wait_event(env, "verify_failure")
  55. assert isinstance(v[1], EnvironmentError)
  56. assert v[1].args == ERRORS[0]
  57. def test_load_verify_upgrade(env, path):
  58. from circuits.app.env import Create, Load
  59. from circuits.app.env import EnvironmentError, ERRORS
  60. env.fire(Create())
  61. assert pytest.wait_event(env, "create_success")
  62. files = ("conf/test.ini", "README", "VERSION")
  63. for filename in files:
  64. assert path.join(filename).check(exists=True, file=True)
  65. env.version = 100
  66. v = env.fire(Load(verify=True))
  67. assert pytest.wait_event(env, "verify_failure")
  68. assert isinstance(v[1], EnvironmentError)
  69. assert v[1].args == ERRORS[1]