本文整理汇总了Python中unittest.TestCase.fail方法的典型用法代码示例。如果您正苦于以下问题:Python TestCase.fail方法的具体用法?Python TestCase.fail怎么用?Python TestCase.fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.TestCase
的用法示例。
在下文中一共展示了TestCase.fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def test_update(self):
person = db.add_person(p_first_name='Marc', p_last_name='SCHNEIDER',
p_birthdate=datetime.date(1973, 4, 24))
person_u = db.update_person(p_id=person.id, p_first_name='Marco', p_last_name='SCHNEIDERO',
p_birthdate=datetime.date(1981, 4, 24))
assert str(person_u.birthdate) == str(datetime.date(1981, 4, 24))
assert person_u.last_name == 'SCHNEIDERO'
assert person_u.first_name == 'Marco'
user_acc = db.add_user_account(a_login='mschneider', a_password='IwontGiveIt',
a_person_id=person_u.id, a_is_admin=True)
assert not db.change_password(999999999, 'IwontGiveIt', 'foo')
assert db.change_password(user_acc.id, 'IwontGiveIt', 'OkIWill')
assert not db.change_password(user_acc.id, 'DontKnow', 'foo')
user_acc_u = db.update_user_account(a_id=user_acc.id, a_new_login='mschneider2', a_is_admin=False)
assert not user_acc_u.is_admin
try:
db.update_user_account(a_id=user_acc.id, a_person_id=999999999)
TestCase.fail(self, "An exception should have been raised : person id does not exist")
except DbHelperException:
pass
user_acc_u = db.update_user_account_with_person(a_id=user_acc.id, a_login='mschneider3',
p_first_name='Bob', p_last_name='Marley',
p_birthdate=datetime.date(1991, 4, 24),
a_is_admin=True, a_skin_used='skins/crocodile')
assert user_acc_u.login == 'mschneider3'
assert user_acc_u.person.first_name == 'Bob'
assert user_acc_u.person.last_name == 'Marley'
assert str(user_acc_u.person.birthdate) == str(datetime.date(1991, 4, 24))
assert user_acc_u.is_admin
assert user_acc_u.skin_used == 'skins/crocodile'
示例2: fail
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def fail(self, msg = None):
try:
TestCase.fail(self, msg)
except:
self.kmod.stop()
self.kmod.save_logs(self.destdir)
raise
示例3: test_fill_with_bad_operator
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def test_fill_with_bad_operator(self):
try:
self._obj.fill({'operator': "bad"})
except:
pass
else:
TestCase.fail(self, "Operator 'bad' doesn't exist, exception should be raised")
示例4: test_del
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def test_del(self):
dt1 = db.add_device_technology('x10', 'x10', 'desc dt1')
dty1 = db.add_device_type(dty_id='x10.switch', dty_name='x10 Switch', dty_description='desc1', dt_id=dt1.id)
du1 = db.add_device_usage('du1_id', 'du1')
du2 = db.add_device_usage('du2_id', 'du2')
device1 = db.add_device(d_name='device1', d_address='A1',
d_type_id=dty1.id, d_usage_id=du1.id, d_description='desc1')
device2 = db.add_device(d_name='device2', d_address='A2',
d_type_id=dty1.id, d_usage_id=du1.id, d_description='desc1')
db.add_device_stat(make_ts(2010, 04, 9, 12, 0), 'val2', 1, device2.id)
db.add_device_stat(make_ts(2010, 04, 9, 12, 1), 'val1', 2, device2.id)
assert len(db.list_device_stats(device2.id)) == 2
device3 = db.add_device(d_name='device3', d_address='A3', d_type_id=dty1.id, d_usage_id=du1.id)
device_del = device2
device2_id = device2.id
db.del_device(device2.id)
# Check cascade deletion
assert len(db.list_device_stats(device2.id)) == 0
assert len(db.list_devices()) == 2
for dev in db.list_devices():
assert dev.address in ('A1', 'A3')
assert device_del.id == device2.id
try:
db.del_device(12345678910)
TestCase.fail(self, "Device does not exist, an exception should have been raised")
except DbHelperException:
pass
示例5: test_status_raises_exception
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def test_status_raises_exception(self):
try:
self.presto_cli.status(self.mock_env)
except Exception as e:
self.assertEqual(repr(e), 'ClientComponentHasNoStatus()')
return
TestCase.fail(self)
示例6: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def _apply(self,
put: unittest.TestCase,
value,
message_builder: MessageBuilder):
put.assertIsInstance(value, sh.SuccessOrHardError)
if not value.is_success:
put.fail('\n'.join([
'Expected: success',
'Actual : hard_error: ' + str(value.failure_message)
]))
示例7: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def _apply(self,
put: unittest.TestCase,
value: T,
message_builder: MessageBuilder):
try:
self.assertion.apply(put, value, message_builder)
except put.failureException:
pass
else:
put.fail(message_builder.apply('NOT ' + self.assertion_name))
示例8: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def _apply(self,
put: unittest.TestCase,
value,
message_builder: MessageBuilder):
put.assertIsInstance(value, svh.SuccessOrValidationErrorOrHardError)
if not value.is_success:
put.fail('\n'.join([
'Expected: ' + svh.SuccessOrValidationErrorOrHardErrorEnum.SUCCESS.name,
'Actual : {st}: {msg}'.format(
st=value.status.name,
msg=repr(value.failure_message))
]))
示例9: test_add
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def test_add(self):
dt1 = db.add_device_technology('x10', 'x10', 'desc dt1')
try:
db.add_device_type(dty_id='x10.switch', dty_name='Switch', dty_description='desc1', dt_id=u'99999999999')
TestCase.fail(self, "An exception should have been raised : device techno id does not exist")
except DbHelperException:
pass
dty1 = db.add_device_type(dty_id='x10.switch', dty_name='Switch', dty_description='desc1', dt_id=dt1.id)
print(dty1)
assert dty1.name == 'Switch'
assert dty1.description == 'desc1'
assert dty1.device_technology_id == dt1.id
dty2 = db.add_device_type(dty_id='x10.dimmer', dty_name='Dimmer', dty_description='desc2', dt_id=dt1.id)
assert len(db.list_device_types()) == 2
assert self.has_item(db.list_device_types(), ['Switch', 'Dimmer'])
示例10: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def _apply(self,
put: unittest.TestCase,
value,
message_builder: asrt.MessageBuilder):
if isinstance(value, CrossReferenceId):
cross_reference_id_va.is_any.apply_with_message(put,
value,
str(CrossReferenceId))
elif isinstance(value, struct.SeeAlsoUrlInfo):
is_see_also_url_info.apply_with_message(put, value,
str(struct.SeeAlsoUrlInfo))
else:
put.fail('Not a {}: {}'.format(SeeAlsoTarget,
value
))
示例11: _check
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def _check(put: unittest.TestCase,
arrangement: Arrangement,
expectation: Expectation):
actual = sut.parse_from_parse_source(arrangement.grammar,
arrangement.source)
if expectation.expression != actual:
put.fail('Unexpected expression.\nExpected: {}\nActual : {}'.format(
str(expectation.expression),
str(actual),
))
put.assertEqual(expectation.expression,
actual,
'parsed expression: ' + str(actual))
expectation.source.apply_with_message(put,
arrangement.source,
'source after parse')
示例12: fail_if_test_case_does_not_pass
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def fail_if_test_case_does_not_pass(put: unittest.TestCase,
root_file_path_argument: Path,
tc_definition: TestCaseDefinitionForMainProgram,
):
# SETUP #
command_line_arguments = [
str(root_file_path_argument),
]
# ACT & ASSERT #
sub_process_result = run_main_program_and_collect_process_result(
command_line_arguments,
main_program_config(tc_definition)
)
if sub_process_result.exitcode != 0:
put.fail('Exit code is non zero. Error message: ' + sub_process_result.stderr)
示例13: _check_stdout
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def _check_stdout(self,
put: unittest.TestCase,
root_path: pathlib.Path,
actual_result: SubProcessResult):
expected_lines = self.expected_stdout_lines(root_path)
if expected_lines is not None:
actual_lines = self._translate_actual_stdout_before_assertion(actual_result.stdout).splitlines()
line_number = 0
for expected_line, actual_line in zip(expected_lines, actual_lines):
if isinstance(expected_line, str):
put.assertEqual(expected_line, actual_line,
'Output of line ' + str(line_number))
else:
match = expected_line.fullmatch(actual_line)
if match is None:
put.fail('Expecting match of "%s" (actual: "%s")' % (str(expected_line), actual_line))
put.assertEqual(len(expected_lines),
len(actual_lines),
'Expecting ' + str(len(expected_lines)) + ' lines')
示例14: assert_interpreter_is_available
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def assert_interpreter_is_available(puc: unittest.TestCase):
if not sys.executable:
puc.fail('Cannot execute test since the name of the Python 3 interpreter is not found in sys.executable.')
示例15: run
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import fail [as 别名]
def run(self, put: unittest.TestCase, arguments: List[str]) -> SubProcessResult:
if self._main_program_path is None:
put.fail('Cannot find executable "%s" in path.' % self._executable_file_name_base)
cmd_and_args = [self._main_program_path] + arguments
stdin_contents = ''
return run_subprocess(cmd_and_args, stdin_contents)