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


Python utils.raises函数代码示例

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


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

示例1: test_contains_the_test_function_name_in_the_exception_string

def test_contains_the_test_function_name_in_the_exception_string():

    calls = [0]

    @given(integers(), settings=Settings(max_iterations=10, max_examples=10))
    def this_has_a_totally_unique_name(x):
        calls[0] += 1
        assume(False)

    with raises(Unsatisfiable) as e:
        this_has_a_totally_unique_name()
        print(u'Called %d times' % tuple(calls))

    assert this_has_a_totally_unique_name.__name__ in e.value.args[0]

    calls2 = [0]

    class Foo(object):

        @given(integers(), settings=Settings(
            max_iterations=10, max_examples=10))
        def this_has_a_unique_name_and_lives_on_a_class(self, x):
            calls2[0] += 1
            assume(False)

    with raises(Unsatisfiable) as e:
        Foo().this_has_a_unique_name_and_lives_on_a_class()
        print(u'Called %d times' % tuple(calls2))

    assert (
        Foo.this_has_a_unique_name_and_lives_on_a_class.__name__
    ) in e.value.args[0]
开发者ID:rbtcollins,项目名称:hypothesis,代码行数:32,代码来源:test_testdecorators.py

示例2: 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

示例3: test_contains_the_test_function_name_in_the_exception_string

def test_contains_the_test_function_name_in_the_exception_string():
    look_for_one = settings(
        max_examples=1, suppress_health_check=HealthCheck.all())

    @given(integers())
    @look_for_one
    def this_has_a_totally_unique_name(x):
        reject()

    with raises(Unsatisfiable) as e:
        this_has_a_totally_unique_name()
    assert this_has_a_totally_unique_name.__name__ in e.value.args[0]

    class Foo(object):

        @given(integers())
        @look_for_one
        def this_has_a_unique_name_and_lives_on_a_class(self, x):
            reject()

    with raises(Unsatisfiable) as e:
        Foo().this_has_a_unique_name_and_lives_on_a_class()
    assert (
        Foo.this_has_a_unique_name_and_lives_on_a_class.__name__
    ) in e.value.args[0]
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:25,代码来源:test_testdecorators.py

示例4: test_rejects_invalid_step_sizes_in_data

def test_rejects_invalid_step_sizes_in_data():
    runner = DepthMachine.find_breaking_runner()
    strategy = StateMachineSearchStrategy()
    basic = strategy.to_basic(runner)
    assert isinstance(basic[2], int)
    basic[2] = -1
    with raises(BadData):
        strategy.from_basic(basic)
    basic[2] = 1000000
    with raises(BadData):
        strategy.from_basic(basic)
开发者ID:GMadorell,项目名称:hypothesis,代码行数:11,代码来源:test_stateful.py

示例5: test_errors_on_extra_kwargs

def test_errors_on_extra_kwargs():
    def foo(a):
        pass

    with raises(TypeError) as e:
        convert_keyword_arguments(foo, (1,), {'b': 1})
    assert 'keyword' in e.value.args[0]

    with raises(TypeError) as e2:
        convert_keyword_arguments(foo, (1,), {'b': 1, 'c': 2})
    assert 'keyword' in e2.value.args[0]
开发者ID:doismellburning,项目名称:hypothesis,代码行数:11,代码来源:test_reflection.py

示例6: test_can_run_without_database

def test_can_run_without_database():
    @given(integers())
    @settings(database=None)
    def test_blah(x):
        assert False
    with raises(AssertionError):
        test_blah()
开发者ID:adamtheturtle,项目名称:hypothesis,代码行数:7,代码来源:test_testdecorators.py

示例7: test_positional_errors_if_given_duplicate_kwargs

def test_positional_errors_if_given_duplicate_kwargs():
    def foo(a):
        pass

    with raises(TypeError) as e:
        convert_positional_arguments(foo, (2,), {'a': 1})
    assert 'multiple values' in e.value.args[0]
开发者ID:doismellburning,项目名称:hypothesis,代码行数:7,代码来源:test_reflection.py

示例8: test_positional_errors_if_given_bad_kwargs

def test_positional_errors_if_given_bad_kwargs():
    def foo(a):
        pass

    with raises(TypeError) as e:
        convert_positional_arguments(foo, (), {'b': 1})
    assert 'unexpected keyword argument' in e.value.args[0]
开发者ID:doismellburning,项目名称:hypothesis,代码行数:7,代码来源:test_reflection.py

示例9: test_positional_errors_if_too_many_args

def test_positional_errors_if_too_many_args():
    def foo(a):
        pass

    with raises(TypeError) as e:
        convert_positional_arguments(foo, (1, 2), {})
    assert '2 given' in e.value.args[0]
开发者ID:doismellburning,项目名称:hypothesis,代码行数:7,代码来源:test_reflection.py

示例10: test_errors_even_if_does_not_error_on_final_call

def test_errors_even_if_does_not_error_on_final_call():
    @given(integers())
    def rude(x):
        assert not any(t[3] == u"best_satisfying_template" for t in inspect.getouterframes(inspect.currentframe()))

    with raises(Flaky):
        rude()
开发者ID:jwg4,项目名称:hypothesis,代码行数:7,代码来源:test_testdecorators.py

示例11: test_machine_with_no_terminals_is_invalid

def test_machine_with_no_terminals_is_invalid():
    class NonTerminalMachine(RuleBasedStateMachine):
        @rule(value=Bundle(u"hi"))
        def bye(self, hi):
            pass

    with raises(InvalidDefinition):
        NonTerminalMachine.TestCase().runTest()
开发者ID:HypothesisWorks,项目名称:hypothesis-python,代码行数:8,代码来源:test_stateful.py

示例12: test_does_not_accept_random_if_derandomize

def test_does_not_accept_random_if_derandomize():
    with raises(InvalidArgument):

        @given(integers(), settings=Settings(derandomize=True), random=Random())
        def test_blah(x):
            pass

        test_blah()
开发者ID:jwg4,项目名称:hypothesis,代码行数:8,代码来源:test_testdecorators.py

示例13: test_reports_repr_diff_in_flaky_error

def test_reports_repr_diff_in_flaky_error():
    @given(builds(DifferentReprEachTime))
    def rude(x):
        assert not any(t[3] == u"best_satisfying_template" for t in inspect.getouterframes(inspect.currentframe()))

    with raises(Flaky) as e:
        rude()
    assert u"Call 1:" in e.value.args[0]
开发者ID:jwg4,项目名称:hypothesis,代码行数:8,代码来源:test_testdecorators.py

示例14: test_does_not_attempt_to_shrink_flaky_errors

def test_does_not_attempt_to_shrink_flaky_errors():
    values = []

    @given(integers())
    def test(x):
        values.append(x)
        assert len(values) != 1
    with raises(Flaky):
        test()
    assert len(set(values)) == 1
开发者ID:Julian,项目名称:hypothesis,代码行数:10,代码来源:test_testdecorators.py

示例15: test_still_minimizes_on_non_assertion_failures

def test_still_minimizes_on_non_assertion_failures():
    @given(integers(), settings=Settings(max_examples=50))
    def is_not_too_large(x):
        if x >= 10:
            raise ValueError(u'No, %s is just too large. Sorry' % x)

    with raises(ValueError) as exinfo:
        is_not_too_large()

    assert u' 10 ' in exinfo.value.args[0]
开发者ID:rbtcollins,项目名称:hypothesis,代码行数:10,代码来源:test_testdecorators.py


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