コード例 #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
コード例 #2
0
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
コード例 #3
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
コード例 #4
0
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
コード例 #5
0
ファイル: test_control.py プロジェクト: jwg4/hypothesis
def test_raises_error_if_cleanup_fails_but_block_does_not():
    with pytest.raises(CleanupFailed):
        with BuildContext():

            def foo():
                raise ValueError()

            cleanup(foo)
コード例 #6
0
ファイル: test_control.py プロジェクト: thedrow/hypothesis
def test_raises_error_if_cleanup_fails_but_block_does_not():
    with pytest.raises(CleanupFailed):
        with BuildContext():

            def foo():
                raise ValueError()

            cleanup(foo)
コード例 #7
0
ファイル: test_control.py プロジェクト: jwg4/hypothesis
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]
コード例 #8
0
ファイル: test_control.py プロジェクト: trowt/hypothesis
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]
コード例 #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
コード例 #10
0
ファイル: morphers.py プロジェクト: degustaf/hypothesis
 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
コード例 #11
0
ファイル: test_control.py プロジェクト: trowt/hypothesis
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()
コード例 #12
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
コード例 #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
コード例 #14
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()
コード例 #15
0
ファイル: morphers.py プロジェクト: zooming-tan/hypothesis
    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
コード例 #16
0
ファイル: morphers.py プロジェクト: kevinleestone/hypothesis
    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
コード例 #17
0
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
コード例 #18
0
ファイル: test_control.py プロジェクト: vlulla/hypothesis
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
コード例 #19
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()
コード例 #20
0
ファイル: test_control.py プロジェクト: trowt/hypothesis
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()
コード例 #21
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)
                assert False

    assert u"ValueError" in o.getvalue()
    assert u"TypeError" in o.getvalue()
    assert _current_build_context.value is None
コード例 #22
0
ファイル: test_control.py プロジェクト: vlulla/hypothesis
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
コード例 #23
0
def test_cannot_cleanup_with_no_context():
    with pytest.raises(InvalidArgument):
        cleanup(lambda: None)
    assert _current_build_context.value is None
コード例 #24
0
def test_cannot_cleanup_with_no_context():
    with pytest.raises(InvalidArgument):
        cleanup(lambda: None)
    assert _current_build_context.value is None
コード例 #25
0
 def seed_random(seed):
     state = random.getstate()
     random.seed(seed)
     cleanup(lambda: random.setstate(state))
     return RandomSeeder(seed)
コード例 #26
0
ファイル: test_control.py プロジェクト: trowt/hypothesis
def test_cannot_cleanup_with_no_context():
    with pytest.raises(InvalidArgument):
        cleanup(lambda: None)
コード例 #27
0
ファイル: test_control.py プロジェクト: trowt/hypothesis
def test_cleanup_executes_on_leaving_build_context():
    data = []
    with BuildContext():
        cleanup(lambda: data.append(1))
        assert not data
    assert data == [1]
コード例 #28
0
ファイル: test_control.py プロジェクト: jwg4/hypothesis
def test_cleanup_executes_on_leaving_build_context():
    data = []
    with BuildContext():
        cleanup(lambda: data.append(1))
        assert not data
    assert data == [1]
コード例 #29
0
ファイル: strategies.py プロジェクト: tokenrove/hypothesis
 def seed_random(seed):
     state = random.getstate()
     random.seed(seed)
     cleanup(lambda: random.setstate(state))
     return RandomSeeder(seed)
コード例 #30
0
ファイル: test_control.py プロジェクト: jwg4/hypothesis
def test_cannot_cleanup_with_no_context():
    with pytest.raises(InvalidArgument):
        cleanup(lambda: None)