本文整理汇总了Python中tests.common.utils.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: test_does_not_catch_interrupt_during_falsify
def test_does_not_catch_interrupt_during_falsify():
calls = [0]
@given(integers())
def flaky_base_exception(x):
if not calls[0]:
calls[0] = 1
raise KeyboardInterrupt()
with raises(KeyboardInterrupt):
flaky_base_exception()
开发者ID:rbtcollins,项目名称:hypothesis,代码行数:10,代码来源:test_testdecorators.py
示例17: test_prints_notes_once_on_failure
def test_prints_notes_once_on_failure():
@given(lists(integers()), settings=Settings(database=None))
def test(xs):
note('Hi there')
assert sum(xs) > 100
with capture_out() as out:
with reporting.with_reporter(reporting.default):
with raises(AssertionError):
test()
lines = out.getvalue().strip().splitlines()
assert len(lines) == 2
assert 'Hi there' in lines
开发者ID:Julian,项目名称:hypothesis,代码行数:12,代码来源:test_testdecorators.py
示例18: test_bad_machines_fail
def test_bad_machines_fail(machine):
test_class = machine.TestCase
try:
with capture_out() as o:
with raises(AssertionError):
test_class().runTest()
except Exception:
print_unicode(o.getvalue())
raise
v = o.getvalue()
print_unicode(v)
assert u'Step #1' in v
assert u'Step #50' not in v
开发者ID:AWhetter,项目名称:hypothesis-python,代码行数:13,代码来源:test_stateful.py
示例19: test_prints_on_failure_by_default
def test_prints_on_failure_by_default():
@given(integers(), integers(), settings=Settings(max_examples=200, timeout=-1))
def test_ints_are_sorted(balthazar, evans):
assume(evans >= 0)
assert balthazar <= evans
with raises(AssertionError):
with capture_out() as out:
with reporting.with_reporter(reporting.default):
test_ints_are_sorted()
out = out.getvalue()
lines = [l.strip() for l in out.split(u"\n")]
assert u"Falsifying example: test_ints_are_sorted(balthazar=1, evans=0)" in lines
开发者ID:jwg4,项目名称:hypothesis,代码行数:13,代码来源:test_testdecorators.py
示例20: test_can_serialize_statemachine_execution
def test_can_serialize_statemachine_execution(machine):
runner = machine.find_breaking_runner()
strategy = StateMachineSearchStrategy()
new_runner = strategy.from_basic(strategy.to_basic(runner))
with raises(AssertionError):
new_runner.run(machine())
r = Random(1)
for simplifier in strategy.simplifiers(r, new_runner):
try:
next(simplifier(r, new_runner))
except StopIteration:
pass
开发者ID:GMadorell,项目名称:hypothesis,代码行数:13,代码来源:test_stateful.py
注:本文中的tests.common.utils.raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论