本文整理汇总了Python中assertpy.fail函数的典型用法代码示例。如果您正苦于以下问题:Python fail函数的具体用法?Python fail怎么用?Python fail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fail函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_expected_exception_all_failure
def test_expected_exception_all_failure():
try:
assert_that(func_noop).raises(RuntimeError).when_called_with('a', 'b', 3, 4, foo=1, bar=2, baz='dog')
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).is_equal_to(
"Expected <func_noop> to raise <RuntimeError> when called with ('a', 'b', 3, 4, 'bar': 2, 'baz': 'dog', 'foo': 1).")
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:7,代码来源:test_expected_exception.py
示例2: test_is_greater_than_failure
def test_is_greater_than_failure(self):
try:
t2 = datetime.timedelta(seconds=90)
assert_that(self.t1).is_greater_than(t2)
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).matches('Expected <\d{1,2}:\d{2}:\d{2}> to be greater than <\d{1,2}:\d{2}:\d{2}>, but was not.')
开发者ID:ghostsquad,项目名称:assertpy,代码行数:7,代码来源:test_datetime.py
示例3: test_is_less_than_or_equal_to_failure
def test_is_less_than_or_equal_to_failure(self):
try:
t2 = datetime.timedelta(seconds=90)
assert_that(t2).is_less_than_or_equal_to(self.t1)
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).matches('Expected <\d{1,2}:\d{2}:\d{2}> to be less than or equal to <\d{1,2}:\d{2}:\d{2}>, but was not.')
开发者ID:ghostsquad,项目名称:assertpy,代码行数:7,代码来源:test_datetime.py
示例4: test_check_iterable_not_iterable
def test_check_iterable_not_iterable():
try:
ab = assert_that(None)
ab._check_iterable(123, name='my-int')
fail('should have raised error')
except TypeError as e:
assert_that(str(e)).contains('my-int <int> is not iterable')
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:7,代码来源:test_custom_list.py
示例5: test_check_iterable_no_getitem
def test_check_iterable_no_getitem():
try:
ab = assert_that(None)
ab._check_iterable(set([1]), name='my-set')
fail('should have raised error')
except TypeError as e:
assert_that(str(e)).contains('my-set <set> does not have [] accessor')
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:7,代码来源:test_custom_list.py
示例6: test_traceback
def test_traceback():
try:
assert_that('foo').is_equal_to('bar')
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).is_equal_to('Expected <foo> to be equal to <bar>, but was not.')
assert_that(ex).is_type_of(AssertionError)
# extract all stack frames from the traceback
_, _, tb = sys.exc_info()
assert_that(tb).is_not_none()
# walk_tb added in 3.5
if sys.version_info[0] == 3 and sys.version_info[1] >= 5:
frames = [(f.f_code.co_filename, f.f_code.co_name, lineno) for f,lineno in traceback.walk_tb(tb)]
assert_that(frames).is_length(3)
assert_that(frames[0][0]).ends_with('test_traceback.py')
assert_that(frames[0][1]).is_equal_to('test_traceback')
assert_that(frames[0][2]).is_equal_to(35)
assert_that(frames[1][0]).ends_with('assertpy.py')
assert_that(frames[1][1]).is_equal_to('is_equal_to')
assert_that(frames[1][2]).is_greater_than(160)
assert_that(frames[2][0]).ends_with('assertpy.py')
assert_that(frames[2][1]).is_equal_to('_err')
assert_that(frames[2][2]).is_greater_than(1000)
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:29,代码来源:test_traceback.py
示例7: step_impl
def step_impl( context, ammount ) :
for i in range( 0, ammount ):
id = 'sim-sampler-' + str( i )
try:
context.driver.find_element_by_id( id )
except:
fail( 'live plot ' + id + ' is not found' )
开发者ID:Eelco81,项目名称:server-test-project,代码行数:7,代码来源:web-client-steps.py
示例8: test_is_before_failure
def test_is_before_failure():
try:
d2 = datetime.datetime.today()
assert_that(d2).is_before(d1)
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be before <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:7,代码来源:test_datetime.py
示例9: test_expected_exception_one_arg_failure
def test_expected_exception_one_arg_failure():
try:
assert_that(func_noop).raises(RuntimeError).when_called_with('foo')
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).is_equal_to(
"Expected <func_noop> to raise <RuntimeError> when called with ('foo').")
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:7,代码来源:test_expected_exception.py
示例10: test_extracting_dict_missing_key_failure
def test_extracting_dict_missing_key_failure(self):
people_as_dicts = [{'first_name': p.first_name, 'last_name': p.last_name} for p in self.people]
try:
assert_that(people_as_dicts).extracting('foo')
fail('should have raised error')
except ValueError as ex:
assert_that(str(ex)).matches(r'item keys \[.*\] did not contain key <foo>')
开发者ID:ghostsquad,项目名称:assertpy,代码行数:7,代码来源:test_extracting.py
示例11: test_is_type_of_subclass_failure
def test_is_type_of_subclass_failure(self):
try:
assert_that(Bar()).is_type_of(Foo)
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).starts_with('Expected <')
assert_that(str(ex)).ends_with(':Bar> to be of type <Foo>, but was not.')
开发者ID:ramab1988,项目名称:assertpy,代码行数:7,代码来源:test_type.py
示例12: test_failure
def test_failure():
try:
with soft_assertions():
assert_that('foo').is_length(4)
assert_that('foo').is_empty()
assert_that('foo').is_false()
assert_that('foo').is_digit()
assert_that('123').is_alpha()
assert_that('foo').is_upper()
assert_that('FOO').is_lower()
assert_that('foo').is_equal_to('bar')
assert_that('foo').is_not_equal_to('foo')
assert_that('foo').is_equal_to_ignoring_case('BAR')
assert_that({'a': 1}).has_a(2)
assert_that({'a': 1}).has_foo(1)
fail('should have raised error')
except AssertionError as e:
out = str(e)
assert_that(out).contains('Expected <foo> to be of length <4>, but was <3>.')
assert_that(out).contains('Expected <foo> to be empty string, but was not.')
assert_that(out).contains('Expected <False>, but was not.')
assert_that(out).contains('Expected <foo> to contain only digits, but did not.')
assert_that(out).contains('Expected <123> to contain only alphabetic chars, but did not.')
assert_that(out).contains('Expected <foo> to contain only uppercase chars, but did not.')
assert_that(out).contains('Expected <FOO> to contain only lowercase chars, but did not.')
assert_that(out).contains('Expected <foo> to be equal to <bar>, but was not.')
assert_that(out).contains('Expected <foo> to be not equal to <foo>, but was.')
assert_that(out).contains('Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
assert_that(out).contains('Expected <1> to be equal to <2> on key <a>, but was not.')
assert_that(out).contains('Expected key <foo>, but val has no key <foo>.')
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:30,代码来源:test_soft.py
示例13: test_is_close_to_failure
def test_is_close_to_failure(self):
try:
d2 = self.d1 + datetime.timedelta(minutes=5)
assert_that(self.d1).is_close_to(d2, datetime.timedelta(minutes=1))
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be close to <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> within tolerance <\d+:\d{2}:\d{2}>, but was not.')
开发者ID:ramab1988,项目名称:assertpy,代码行数:7,代码来源:test_date.py
示例14: test_is_between_bad_arg2_type_failure
def test_is_between_bad_arg2_type_failure(self):
try:
d2 = datetime.datetime.today()
assert_that(self.d1).is_between(d2, 123)
fail('should have raised error')
except TypeError as ex:
assert_that(str(ex)).is_equal_to('given high arg must be datetime, but was <int>')
开发者ID:ramab1988,项目名称:assertpy,代码行数:7,代码来源:test_date.py
示例15: test_is_close_to_bad_tolerance_arg_type_failure
def test_is_close_to_bad_tolerance_arg_type_failure(self):
try:
d2 = datetime.datetime.today()
assert_that(self.d1).is_close_to(d2, 123)
fail('should have raised error')
except TypeError as ex:
assert_that(str(ex)).is_equal_to('given tolerance arg must be timedelta, but was <int>')
开发者ID:ramab1988,项目名称:assertpy,代码行数:7,代码来源:test_date.py
示例16: test_soft_assertions
def test_soft_assertions(self):
try:
with soft_assertions():
assert_that('foo').is_length(4)
assert_that('foo').is_empty()
assert_that('foo').is_false()
assert_that('foo').is_digit()
assert_that('123').is_alpha()
assert_that('foo').is_upper()
assert_that('FOO').is_lower()
assert_that('foo').is_equal_to('bar')
assert_that('foo').is_not_equal_to('foo')
assert_that('foo').is_equal_to_ignoring_case('BAR')
fail('should have raised error')
except AssertionError as e:
assert_that(str(e)).contains('1. Expected <foo> to be of length <4>, but was <3>.')
assert_that(str(e)).contains('2. Expected <foo> to be empty string, but was not.')
assert_that(str(e)).contains('3. Expected <False>, but was not.')
assert_that(str(e)).contains('4. Expected <foo> to contain only digits, but did not.')
assert_that(str(e)).contains('5. Expected <123> to contain only alphabetic chars, but did not.')
assert_that(str(e)).contains('6. Expected <foo> to contain only uppercase chars, but did not.')
assert_that(str(e)).contains('7. Expected <FOO> to contain only lowercase chars, but did not.')
assert_that(str(e)).contains('8. Expected <foo> to be equal to <bar>, but was not.')
assert_that(str(e)).contains('9. Expected <foo> to be not equal to <foo>, but was.')
assert_that(str(e)).contains('10. Expected <foo> to be case-insensitive equal to <BAR>, but was not.')
开发者ID:skippyprime,项目名称:assertpy,代码行数:25,代码来源:test_readme.py
示例17: test_is_after_failure
def test_is_after_failure(self):
try:
d2 = datetime.datetime.today()
assert_that(self.d1).is_after(d2)
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be after <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
开发者ID:ramab1988,项目名称:assertpy,代码行数:7,代码来源:test_date.py
示例18: test_is_file_directory_failure
def test_is_file_directory_failure(self):
try:
dirname = os.path.dirname(self.tmp.name)
assert_that(dirname).is_file()
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).matches('Expected <.*> to be a file, but was not.')
开发者ID:ghostsquad,项目名称:assertpy,代码行数:7,代码来源:test_file.py
示例19: test_check_dict_like_no_getitem
def test_check_dict_like_no_getitem():
try:
ab = assert_that(None)
ab._check_dict_like(CustomDictNoGetitem())
fail('should have raised error')
except TypeError as e:
assert_that(str(e)).contains('is not dict-like: missing [] accessor')
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:7,代码来源:test_custom_dict.py
示例20: test_is_not_same_as_failure
def test_is_not_same_as_failure():
for obj in [object(), 1, 'foo', True, None, 123.456]:
try:
assert_that(obj).is_not_same_as(obj)
fail('should have raised error')
except AssertionError as ex:
assert_that(str(ex)).matches('Expected <.+> to be not identical to <.+>, but was.')
开发者ID:ActivisionGameScience,项目名称:assertpy,代码行数:7,代码来源:test_same_as.py
注:本文中的assertpy.fail函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论