• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.capture_out函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_does_not_print_reproduction_for_simple_examples_by_default

def test_does_not_print_reproduction_for_simple_examples_by_default():
    @given(st.integers())
    def test(i):
        assert False

    with capture_out() as o:
        with pytest.raises(AssertionError):
            test()
    assert '@reproduce_failure' not in o.getvalue()
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:9,代码来源:test_reproduce_failure.py


示例17: test_does_print_verbose_in_debug

def test_does_print_verbose_in_debug():
    @given(integers())
    @settings(verbosity=Verbosity.debug)
    def f(x):
        verbose_report('Hi')

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


示例18: test_does_not_print_debug_in_verbose

def test_does_not_print_debug_in_verbose():
    @given(integers())
    @settings(verbosity=Verbosity.verbose)
    def f(x):
        debug_report('Hi')

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


示例19: test_prints_output_by_default

def test_prints_output_by_default():
    @given(integers())
    def test_int(x):
        assert False

    with capture_out() as o:
        with reporting.with_reporter(reporting.default):
            with pytest.raises(AssertionError):
                test_int()
    assert u'Falsifying example' in o.getvalue()
开发者ID:KrzysiekJ,项目名称:hypothesis-python,代码行数:10,代码来源:test_reporting.py


示例20: test_can_suppress_output

def test_can_suppress_output():
    @given(integers())
    def test_int(x):
        assert False

    with capture_out() as o:
        with reporting.with_reporter(reporting.silent):
            with pytest.raises(AssertionError):
                test_int()
    assert u'Falsifying example' not in o.getvalue()
开发者ID:KrzysiekJ,项目名称:hypothesis-python,代码行数:10,代码来源:test_reporting.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.raises函数代码示例发布时间:2022-05-27
下一篇:
Python test_dimensions.create_uncompressed_text_dimension函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap