def test_cleanup_executes_on_leaving_build_context(): data = [] with bc(): cleanup(lambda: data.append(1)) assert not data assert data == [1] assert _current_build_context.value is None
def test_raises_error_if_cleanup_fails_but_block_does_not(): with pytest.raises(CleanupFailed): with bc(): def foo(): raise ValueError() cleanup(foo) assert _current_build_context.value is None
def test_raises_error_if_cleanup_fails_but_block_does_not(): with pytest.raises(CleanupFailed): with BuildContext(): def foo(): raise ValueError() cleanup(foo)
def test_can_nest_build_context(): data = [] with BuildContext(): cleanup(lambda: data.append(1)) with BuildContext(): cleanup(lambda: data.append(2)) assert not data assert data == [2] assert data == [2, 1]
def reify(self, template): def write_back(): s = template.last_strategy if s is not None: template.data = template.last_strategy.to_basic( template.last_template) cleanup(write_back) return template
def reify(self, template): def write_back(): s = template.last_strategy if s is not None: template.data = template.last_strategy.to_basic( template.last_template ) cleanup(write_back) return template
def test_suppresses_exceptions_in_teardown(): with capture_out() as o: with pytest.raises(AssertionError): with BuildContext(): def foo(): raise ValueError() cleanup(foo) assert False assert u'ValueError' in o.getvalue()
def test_can_nest_build_context(): data = [] with bc(): cleanup(lambda: data.append(1)) with bc(): cleanup(lambda: data.append(2)) assert not data assert data == [2] assert data == [2, 1] assert _current_build_context.value is None
def reify(self, template): strategy = template.current_strategy def fix_morpher_in_response_to_changes(): if strategy is not None and template.current_strategy is None: template.install(strategy) else: template.flush() cleanup(fix_morpher_in_response_to_changes) template.clear() return template
def test_suppresses_exceptions_in_teardown(): with capture_out() as o: with pytest.raises(AssertionError): with bc(): def foo(): raise ValueError() cleanup(foo) assert False assert u"ValueError" in o.getvalue() assert _current_build_context.value is None
def test_suppresses_exceptions_in_teardown(): with capture_out() as o: with pytest.raises(AssertionError): with bc(): def foo(): raise ValueError() cleanup(foo) raise AssertionError assert "ValueError" in o.getvalue() assert _current_build_context.value is None
def test_runs_multiple_cleanup_with_teardown(): with capture_out() as o: with pytest.raises(AssertionError): with BuildContext(): def foo(): raise ValueError() cleanup(foo) def bar(): raise TypeError() cleanup(foo) cleanup(bar) assert False assert u'ValueError' in o.getvalue() assert u'TypeError' in o.getvalue()
def test_runs_multiple_cleanup_with_teardown(): with capture_out() as o: with pytest.raises(AssertionError): with bc(): def foo(): raise ValueError() cleanup(foo) def bar(): raise TypeError() cleanup(foo) cleanup(bar) assert False assert u"ValueError" in o.getvalue() assert u"TypeError" in o.getvalue() assert _current_build_context.value is None
def test_runs_multiple_cleanup_with_teardown(): with capture_out() as o: with pytest.raises(AssertionError): with bc(): def foo(): raise ValueError() cleanup(foo) def bar(): raise TypeError() cleanup(foo) cleanup(bar) raise AssertionError assert "ValueError" in o.getvalue() assert "TypeError" in o.getvalue() assert _current_build_context.value is None
def test_cannot_cleanup_with_no_context(): with pytest.raises(InvalidArgument): cleanup(lambda: None) assert _current_build_context.value is None
def seed_random(seed): state = random.getstate() random.seed(seed) cleanup(lambda: random.setstate(state)) return RandomSeeder(seed)
def test_cannot_cleanup_with_no_context(): with pytest.raises(InvalidArgument): cleanup(lambda: None)
def test_cleanup_executes_on_leaving_build_context(): data = [] with BuildContext(): cleanup(lambda: data.append(1)) assert not data assert data == [1]