Beispiel #1
0
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_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
Beispiel #5
0
def test_raises_error_if_cleanup_fails_but_block_does_not():
    with pytest.raises(CleanupFailed):
        with BuildContext():

            def foo():
                raise ValueError()

            cleanup(foo)
Beispiel #6
0
def test_raises_error_if_cleanup_fails_but_block_does_not():
    with pytest.raises(CleanupFailed):
        with BuildContext():

            def foo():
                raise ValueError()

            cleanup(foo)
Beispiel #7
0
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]
Beispiel #8
0
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]
Beispiel #9
0
    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
Beispiel #10
0
 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
Beispiel #11
0
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
Beispiel #13
0
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 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()
Beispiel #15
0
    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
Beispiel #16
0
    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
Beispiel #18
0
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()
Beispiel #20
0
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
Beispiel #22
0
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
Beispiel #24
0
def test_cannot_cleanup_with_no_context():
    with pytest.raises(InvalidArgument):
        cleanup(lambda: None)
    assert _current_build_context.value is None
Beispiel #25
0
 def seed_random(seed):
     state = random.getstate()
     random.seed(seed)
     cleanup(lambda: random.setstate(state))
     return RandomSeeder(seed)
Beispiel #26
0
def test_cannot_cleanup_with_no_context():
    with pytest.raises(InvalidArgument):
        cleanup(lambda: None)
Beispiel #27
0
def test_cleanup_executes_on_leaving_build_context():
    data = []
    with BuildContext():
        cleanup(lambda: data.append(1))
        assert not data
    assert data == [1]
Beispiel #28
0
def test_cleanup_executes_on_leaving_build_context():
    data = []
    with BuildContext():
        cleanup(lambda: data.append(1))
        assert not data
    assert data == [1]
Beispiel #29
0
 def seed_random(seed):
     state = random.getstate()
     random.seed(seed)
     cleanup(lambda: random.setstate(state))
     return RandomSeeder(seed)
Beispiel #30
0
def test_cannot_cleanup_with_no_context():
    with pytest.raises(InvalidArgument):
        cleanup(lambda: None)