本文整理汇总了Python中assertpy.assert_that函数的典型用法代码示例。如果您正苦于以下问题:Python assert_that函数的具体用法?Python assert_that怎么用?Python assert_that使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_that函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_valid
def test_valid(self):
msg = CommandMessage(original_text='.count ham',
text='ham',
sender='[email protected]/Oklahomer')
assert_that(hipchat_count(msg, {})) \
.described_as(".count command increments count") \
.is_equal_to('1')
示例2: 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>')
示例3: test_is_equal_to_ignoring_milliseconds_failure
def test_is_equal_to_ignoring_milliseconds_failure(self):
try:
d2 = datetime.datetime.today() + datetime.timedelta(days=1)
assert_that(self.d1).is_equal_to_ignoring_milliseconds(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 equal to <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
示例4: devices_do_not_contain_places
def devices_do_not_contain_places(self, device_id: str) -> list:
""" The opposite of `device_and_place_contain_each_other`."""
device, _ = self.get(self.DEVICES, '', device_id)
assert_that(device).does_not_contain('place')
for component_id in device.get('components', []):
component, _ = self.get(self.DEVICES, '', component_id)
assert_that(component).does_not_contain('place')
示例5: 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>')
示例6: 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>')
示例7: 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.')
示例8: 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.')
示例9: step_impl
def step_impl(context):
for row in context.table:
assert_that(bucket.head_object(row["name"]).status_code
).is_equal_to(404 if row["deleted"] == "1" else 200)
for row in context.table:
bucket.delete_object(row["name"])
示例10: test_expected_exceptions
def test_expected_exceptions(self):
def some_func(arg):
raise RuntimeError('some err')
assert_that(some_func).raises(RuntimeError).when_called_with('foo')
assert_that(some_func).raises(RuntimeError).when_called_with('foo')\
.is_length(8).starts_with('some').is_equal_to('some err')
示例11: 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.')
示例12: wait_future_finish
def wait_future_finish(self, future):
sleep(.5) # Why would I need this line?? Check later.
ret = concurrent.futures.wait([future], 5, return_when=ALL_COMPLETED)
if len(ret.not_done) > 0:
logging.error("Jobs are not finished.")
assert_that(ret.done).contains(future)
示例13: test__init
def test__init(self):
msg = CommandMessage(original_text='.hello',
text='',
sender='[email protected]/ham')
response = hipchat_hello(msg, {})
assert_that(response) \
.described_as(".hello initiates conversation.") \
.is_instance_of(UserContext) \
.has_message("Hello. How are you feeling today?")
assert_that(response.input_options) \
.described_as("User has two options to respond.") \
.is_length(2)
assert_that([o.next_step.__name__ for o in response.input_options]) \
.described_as("Those options include 'Good' and 'Bad'") \
.contains(hipchat_user_feeling_good.__name__,
hipchat_user_feeling_bad.__name__)
assert_that(response.input_options[0].next_step("Good", {})) \
.described_as("When 'Good,' just return text.") \
.is_equal_to("Good to hear that.")
assert_that(response.input_options[1].next_step("Bad", {})) \
.described_as("When 'Bad,' continue to ask health status") \
.is_instance_of(UserContext)
示例14: test_multiple_calls_with_same_word
def test_multiple_calls_with_same_word(self):
msg = CommandMessage(original_text='.count ham',
text='ham',
sender='[email protected]/Oklahomer')
assert_that(hipchat_count(msg, {})) \
.described_as("First count returns 1") \
.is_equal_to('1')
other_msg = CommandMessage(original_text='.count ham',
text='ham',
sender='[email protected]/Oklahomer')
assert_that(hipchat_count(other_msg, {})) \
.described_as("Different counter for different message") \
.is_equal_to('1')
assert_that(hipchat_count(msg, {})) \
.described_as("Same message results in incremented count") \
.is_equal_to('2')
reset_msg = CommandMessage(original_text='.reset_count',
text='',
sender='[email protected]/Oklahomer')
assert_that(hipchat_reset_count(reset_msg, {})) \
.described_as(".reset_count command resets current count") \
.is_equal_to("restart counting")
assert_that(hipchat_count(msg, {})) \
.described_as("Count restarts") \
.is_equal_to('1')
示例15: step_impl
def step_impl(context):
ok = True
for row in context.table:
if row["name"] not in context.output:
ok = False
break
assert_that(ok).is_equal_to(True)