PageRenderTime 62ms CodeModel.GetById 34ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/tests/app/test_env.py

https://bitbucket.org/prologic/circuits/
Python | 123 lines | 81 code | 41 blank | 1 comment | 8 complexity | 7e212efc25868cc2198acc573060581c MD5 | raw file
  1#!/usr/bin/env python
  2
  3import pytest
  4
  5
  6def pytest_funcarg__path(request):
  7    tmpdir = request.getfuncargvalue("tmpdir")
  8    return tmpdir.join("env")
  9
 10
 11def pytest_funcarg__env(request):
 12    return request.cached_setup(
 13            setup=lambda: setup_env(request),
 14            teardown=lambda env: teardown_env(env),
 15            scope="function")
 16
 17
 18def setup_env(request):
 19    from circuits.app.env import Environment
 20
 21    path = request.getfuncargvalue("path")
 22
 23    env = Environment(str(path), "test")
 24
 25    env.start()
 26
 27    return env
 28
 29
 30def teardown_env(env):
 31    env.stop()
 32
 33
 34def test_create(env, path):
 35    from circuits.app.env import Create
 36
 37    env.fire(Create())
 38    assert pytest.wait_event(env, "create_success")
 39
 40    files = ("conf/test.ini", "README", "VERSION")
 41
 42    for filename in files:
 43        assert path.join(filename).check(exists=True, file=True)
 44
 45
 46def test_load(env, path):
 47    from circuits.app.env import Create, Load
 48
 49    env.fire(Create())
 50
 51    assert pytest.wait_event(env, "create_success")
 52
 53    files = ("conf/test.ini", "README", "VERSION")
 54
 55    for filename in files:
 56        assert path.join(filename).check(exists=True, file=True)
 57
 58    env.fire(Load())
 59
 60    assert pytest.wait_event(env, "load_success")
 61
 62
 63def test_load_verify(env, path):
 64    from circuits.app.env import Create, Load
 65
 66    env.fire(Create())
 67
 68    assert pytest.wait_event(env, "create_success")
 69
 70    files = ("conf/test.ini", "README", "VERSION")
 71
 72    for filename in files:
 73        assert path.join(filename).check(exists=True, file=True)
 74
 75    env.fire(Load(verify=True))
 76
 77    assert pytest.wait_event(env, "load_success")
 78
 79
 80def test_load_verify_fail(env, path):
 81    from circuits.app.env import Create, Load
 82    from circuits.app.env import EnvironmentError, ERRORS
 83
 84    env.fire(Create())
 85
 86    assert pytest.wait_event(env, "create_success")
 87
 88    files = ("conf/test.ini", "README", "VERSION")
 89
 90    for filename in files:
 91        assert path.join(filename).check(exists=True, file=True)
 92
 93    path.join("VERSION").write("")
 94
 95    v = env.fire(Load(verify=True))
 96
 97    assert pytest.wait_event(env, "verify_failure")
 98
 99    assert isinstance(v[1], EnvironmentError)
100    assert v[1].args == ERRORS[0]
101
102
103def test_load_verify_upgrade(env, path):
104    from circuits.app.env import Create, Load
105    from circuits.app.env import EnvironmentError, ERRORS
106
107    env.fire(Create())
108
109    assert pytest.wait_event(env, "create_success")
110
111    files = ("conf/test.ini", "README", "VERSION")
112
113    for filename in files:
114        assert path.join(filename).check(exists=True, file=True)
115
116    env.version = 100
117
118    v = env.fire(Load(verify=True))
119
120    assert pytest.wait_event(env, "verify_failure")
121
122    assert isinstance(v[1], EnvironmentError)
123    assert v[1].args == ERRORS[1]