当前位置: 首页>>代码示例>>Python>>正文


Python utils.capture_out函数代码示例

本文整理汇总了Python中tests.common.utils.capture_out函数的典型用法代码示例。如果您正苦于以下问题:Python capture_out函数的具体用法?Python capture_out怎么用?Python capture_out使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了capture_out函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_stability

def test_stability():
    @given(
        st.lists(st.text(min_size=1, max_size=1), unique=True, min_size=5),
        st.choices(),
    )
    @settings(
        database=ExampleDatabase(),
    )
    def test_choose_and_then_fail(ls, choice):
        for _ in hrange(100):
            choice(ls)
        assert False

    # Run once first for easier debugging
    with raises(AssertionError):
        test_choose_and_then_fail()

    with capture_out() as o:
        with raises(AssertionError):
            test_choose_and_then_fail()
    out1 = o.getvalue()
    with capture_out() as o:
        with raises(AssertionError):
            test_choose_and_then_fail()
    out2 = o.getvalue()
    assert out1 == out2
    assert 'Choice #100:' in out1
开发者ID:KrzysiekJ,项目名称:hypothesis-python,代码行数:27,代码来源:test_choices.py

示例2: test_does_print_on_reuse_from_database

def test_does_print_on_reuse_from_database():
    passes_healthcheck = False

    database = InMemoryExampleDatabase()

    @settings(database=database)
    @given(st.integers())
    def test(i):
        assume(passes_healthcheck)
        raise ValueError()

    with capture_out() as o:
        with pytest.raises(FailedHealthCheck):
            test()

    assert '@seed' in o.getvalue()

    passes_healthcheck = True

    with capture_out() as o:
        with pytest.raises(ValueError):
            test()

    assert all_values(database)
    assert '@seed' not in o.getvalue()

    passes_healthcheck = False

    with capture_out() as o:
        with pytest.raises(FailedHealthCheck):
            test()

    assert '@seed' in o.getvalue()
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:33,代码来源:test_seed_printing.py

示例3: test_initialize_rule

def test_initialize_rule():
    class WithInitializeRules(RuleBasedStateMachine):
        initialized = []

        @initialize()
        def initialize_a(self):
            self.initialized.append('a')

        @initialize()
        def initialize_b(self):
            self.initialized.append('b')

        @initialize()
        def initialize_c(self):
            self.initialized.append('c')

        @rule()
        def fail_fast(self):
            assert False

    with capture_out() as o:
        with pytest.raises(AssertionError):
            run_state_machine_as_test(WithInitializeRules)

    assert set(WithInitializeRules.initialized[-3:]) == {'a', 'b', 'c'}
    result = o.getvalue().splitlines()
    assert result[0] == 'state = WithInitializeRules()'
    # Initialize rules call order is shuffled
    assert {result[1], result[2], result[3]} == {
        'state.initialize_a()', 'state.initialize_b()', 'state.initialize_c()'
    }
    assert result[4] == 'state.fail_fast()'
    assert result[5] == 'state.teardown()'
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:33,代码来源:test_stateful.py

示例4: test_prints_debug_on_no_simplification

def test_prints_debug_on_no_simplification():
    with Settings(verbosity=Verbosity.debug):
        with capture_out() as o:
            find(just(u"hi"), bool)
    v = o.getvalue()
    print(v)
    assert u"No simplifiers" in v
开发者ID:GMadorell,项目名称:hypothesis,代码行数:7,代码来源:test_reporting.py

示例5: test_initialize_rule_populate_bundle

def test_initialize_rule_populate_bundle():
    class WithInitializeBundleRules(RuleBasedStateMachine):
        a = Bundle("a")

        @initialize(target=a, dep=just("dep"))
        def initialize_a(self, dep):
            return "a v1 with (%s)" % dep

        @rule(param=a)
        def fail_fast(self, param):
            assert False

    WithInitializeBundleRules.TestCase.settings = NO_BLOB_SETTINGS
    with capture_out() as o:
        with pytest.raises(AssertionError):
            run_state_machine_as_test(WithInitializeBundleRules)

    result = o.getvalue()
    assert (
        result
        == """\
Falsifying example: run_state_machine(\
factory=WithInitializeBundleRules, data=data(...))
state = WithInitializeBundleRules()
v1 = state.initialize_a(dep='dep')
state.fail_fast(param=v1)
state.teardown()
"""
    )
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:29,代码来源:test_stateful.py

示例6: test_prints_equal_values_with_correct_variable_name

def test_prints_equal_values_with_correct_variable_name():
    class MovesBetweenBundles(RuleBasedStateMachine):
        b1 = Bundle("b1")
        b2 = Bundle("b2")

        @rule(target=b1)
        def create(self):
            return []

        @rule(target=b2, source=b1)
        def transfer(self, source):
            return source

        @rule(source=b2)
        def fail(self, source):
            assert False

    with capture_out() as o:
        with pytest.raises(AssertionError):
            run_state_machine_as_test(MovesBetweenBundles)

    result = o.getvalue()
    for m in ["create", "transfer", "fail"]:
        assert result.count("state." + m) == 1
    assert "v1 = state.create()" in result
    assert "v2 = state.transfer(source=v1)" in result
    assert "state.fail(source=v2)" in result
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:27,代码来源:test_stateful.py

示例7: test_can_manually_call_initialize_rule

def test_can_manually_call_initialize_rule():
    class StateMachine(RuleBasedStateMachine):
        initialize_called_counter = 0

        @initialize()
        def initialize(self):
            self.initialize_called_counter += 1
            return self.initialize_called_counter

        @rule()
        def fail_eventually(self):
            assert self.initialize() <= 2

    StateMachine.TestCase.settings = NO_BLOB_SETTINGS
    with capture_out() as o:
        with pytest.raises(AssertionError):
            run_state_machine_as_test(StateMachine)

    result = o.getvalue()
    assert (
        result
        == """\
Falsifying example: run_state_machine(factory=StateMachine, data=data(...))
state = StateMachine()
state.initialize()
state.fail_eventually()
state.fail_eventually()
state.teardown()
"""
    )
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:30,代码来源:test_stateful.py

示例8: test_initialize_rule_in_state_machine_with_inheritance

def test_initialize_rule_in_state_machine_with_inheritance():
    class ParentStateMachine(RuleBasedStateMachine):
        initialized = []

        @initialize()
        def initialize_a(self):
            self.initialized.append('a')

    class ChildStateMachine(ParentStateMachine):

        @initialize()
        def initialize_b(self):
            self.initialized.append('b')

        @rule()
        def fail_fast(self):
            assert False

    with capture_out() as o:
        with pytest.raises(AssertionError):
            run_state_machine_as_test(ChildStateMachine)

    assert set(ChildStateMachine.initialized[-2:]) == {'a', 'b'}
    result = o.getvalue().splitlines()
    assert result[0] == 'state = ChildStateMachine()'
    # Initialize rules call order is shuffled
    assert {result[1], result[2]} == {
        'state.initialize_a()', 'state.initialize_b()'}
    assert result[3] == 'state.fail_fast()'
    assert result[4] == 'state.teardown()'
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:30,代码来源:test_stateful.py

示例9: test_shrinks_both_failures

def test_shrinks_both_failures():
    first_has_failed = [False]
    duds = set()
    second_target = [None]

    @given(st.integers())
    def test(i):
        if i >= 10000:
            first_has_failed[0] = True
            assert False
        assert i < 10000
        if first_has_failed[0]:
            if second_target[0] is None:
                for j in range(10000):
                    if j not in duds:
                        second_target[0] = j
                        break
            assert i < second_target[0]
        else:
            duds.add(i)

    with capture_out() as o:
        with pytest.raises(MultipleFailures):
            test()

    assert 'test(i=10000)' in o.getvalue()
    assert 'test(i=%d)' % (second_target[0],) in o.getvalue()
开发者ID:doismellburning,项目名称:hypothesis,代码行数:27,代码来源:test_slippage.py

示例10: test_prints_seed_on_exception

def test_prints_seed_on_exception(monkeypatch, in_pytest, fail_healthcheck):
    monkeypatch.setattr(core, 'running_under_pytest', in_pytest)

    strategy = st.integers()
    if fail_healthcheck:
        def slow_map(i):
            time.sleep(10)
            return i
        strategy = strategy.map(slow_map)
        expected_exc = FailedHealthCheck
    else:
        expected_exc = AssertionError

    @given(strategy)
    def test(i):
        assert False

    with capture_out() as o:
        with pytest.raises(expected_exc):
            test()

    output = o.getvalue()

    seed = test._hypothesis_internal_use_generated_seed
    assert seed is not None
    assert '@seed(%d)' % (seed,) in output
    contains_pytest_instruction = ('--hypothesis-seed=%d' % (seed,)) in output
    assert contains_pytest_instruction == in_pytest
开发者ID:doismellburning,项目名称:hypothesis,代码行数:28,代码来源:test_seed_printing.py

示例11: test_multiple_rules_same_func

def test_multiple_rules_same_func():
    test_class = MultipleRulesSameFuncMachine.TestCase
    with capture_out() as o:
        test_class().runTest()
    output = o.getvalue()
    assert 'rule1data' in output
    assert 'rule2data' in output
开发者ID:AWhetter,项目名称:hypothesis-python,代码行数:7,代码来源:test_stateful.py

示例12: test_prints_equal_values_with_correct_variable_name

def test_prints_equal_values_with_correct_variable_name():
    class MovesBetweenBundles(RuleBasedStateMachine):
        b1 = Bundle('b1')
        b2 = Bundle('b2')

        @rule(target=b1)
        def create(self):
            return []

        @rule(target=b2, source=b1)
        def transfer(self, source):
            return source

        @rule(source=b2)
        def fail(self, source):
            assert False

    with capture_out() as o:
        with pytest.raises(AssertionError):
            run_state_machine_as_test(MovesBetweenBundles)

    result = o.getvalue()
    for m in ['create', 'transfer', 'fail']:
        assert result.count(m) == 1
    assert 'v1 = state.create()' in result
    assert 'v2 = state.transfer(source=v1)' in result
    assert 'state.fail(source=v2)' in result
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:27,代码来源:test_stateful.py

示例13: test_does_not_print_notes_if_all_succeed

def test_does_not_print_notes_if_all_succeed():
    @given(integers())
    def test(i):
        note('Hi there')
    with capture_out() as out:
        with reporting.with_reporter(reporting.default):
            test()
        assert not out.getvalue()
开发者ID:Julian,项目名称:hypothesis,代码行数:8,代码来源:test_testdecorators.py

示例14: test_does_print_debug_in_debug

def test_does_print_debug_in_debug():
    @given(integers())
    @settings(verbosity=Verbosity.debug)
    def f(x):
        debug_report("Hi")

    with capture_out() as o:
        f()
    assert u"Hi" in o.getvalue()
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:9,代码来源:test_reporting.py

示例15: test_can_seed_random

def test_can_seed_random():
    with capture_out() as out:
        with reporting.with_reporter(reporting.default):
            with pytest.raises(AssertionError):
                @given(st.random_module())
                def test(r):
                    assert False
                test()
    assert 'random.seed(0)' in out.getvalue()
开发者ID:AWhetter,项目名称:hypothesis-python,代码行数:9,代码来源:test_random_module.py


注:本文中的tests.common.utils.capture_out函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。