本文整理汇总了Python中unittest.TestCase.assertTrue方法的典型用法代码示例。如果您正苦于以下问题:Python TestCase.assertTrue方法的具体用法?Python TestCase.assertTrue怎么用?Python TestCase.assertTrue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.TestCase
的用法示例。
在下文中一共展示了TestCase.assertTrue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: what_is_session
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def what_is_session():
with DocumentStore() as store:
store.initialize()
# region session_usage_1
with store.open_session() as session:
entity = Company(name= "Company")
session.store(entity)
session.save_changes()
company_id = entity.Id
with store.open_session() as session:
entity = session.load(company_id, object_type= Company)
print(entity.name)
# endregion
# region session_usage_2
with store.open_session() as session:
entity = session.load(company_id, object_type=Company)
entity.name = "Another Company"
session.save_changes()
# endregion
with store.open_session() as session:
# region session_usage_3
TestCase.assertTrue(session.load(company_id, object_type=Company)
is session.load(company_id, object_type=Company))
示例2: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def _apply(self,
put: unittest.TestCase,
value: spe.ResultAndStderr,
message_builder: asrt.MessageBuilder):
put.assertIsInstance(value, spe.ResultAndStderr)
put.assertTrue(value.result.is_success,
message_builder.apply('Result is expected to indicate success'))
示例3: test_hideHud
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def test_hideHud(self):
self.game.showHud('playerHud')
TestCase.assertTrue(self,
self.game.tilemap.layers['playerHud'].visible)
self.game.hideHud('playerHud')
TestCase.assertFalse(self,
self.game.tilemap.layers['playerHud'].visible)
示例4: check_both_single_and_multiple_line_source
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def check_both_single_and_multiple_line_source(
self,
put: unittest.TestCase,
first_source_line_instruction_argument_source_template: str,
act_phase_source_lines: list,
expected_cmd_and_args: ValueAssertion,
hds_contents: home_populators.HomePopulator = home_populators.empty()):
instruction_argument_source = first_source_line_instruction_argument_source_template.format_map(
self.format_map_for_template_string)
for source, source_assertion in equivalent_source_variants_with_assertion(put, instruction_argument_source):
# ARRANGE #
os_process_executor = AtcOsProcessExecutorThatRecordsArguments()
arrangement = Arrangement(source,
act_phase_source_lines,
atc_os_process_executor=os_process_executor,
hds_contents=hds_contents)
expectation = Expectation(source_after_parse=source_assertion)
# ACT #
check(put, arrangement, expectation)
# ASSERT #
put.assertFalse(os_process_executor.command.shell,
'Command should not indicate shell execution')
actual_cmd_and_args = os_process_executor.command.args
put.assertIsInstance(actual_cmd_and_args, list,
'Arguments of command to execute should be a list of arguments')
put.assertTrue(len(actual_cmd_and_args) > 0,
'List of arguments is expected to contain at least the file|interpreter argument')
expected_cmd_and_args.apply_with_message(put, actual_cmd_and_args, 'actual_cmd_and_args')
示例5: test_main
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def test_main(self):
url = "http://" + str(settings.getIpAddress()) + ":" + str(settings.globalVars.portNumber)
url = url.strip()
print('TEST SERVER @ ' + url)
website = urllib2.urlopen(url)
website_html = str(website.read())
flag = website_html.__contains__("<pre>")
TestCase.assertTrue(self,flag, "Invalid Server Response")
pass
示例6: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def _apply(self,
put: unittest.TestCase,
value: T,
message_builder: MessageBuilder = MessageBuilder()):
msg = message_builder.apply(self.message)
if self.expected:
put.assertTrue(value, msg)
else:
put.assertFalse(value, msg)
示例7: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def _apply(self,
put: unittest.TestCase,
value: T,
message_builder: MessageBuilder):
file_path = pathlib.Path(self.path_name)
put.assertTrue(file_path.exists(),
message_builder.apply('Path should exist'))
put.assertTrue(file_path.is_dir(),
message_builder.apply('Path should be a directory'))
示例8: _assert_table_contains
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def _assert_table_contains(put: unittest.TestCase,
table: sut.SymbolTable,
expected_symbol: NameAndValue):
put.assertTrue(table.contains(expected_symbol.name),
'table SHOULD contain the value')
put.assertIn(expected_symbol.name,
table.names_set,
'names set should contain the value')
put.assertIs(expected_symbol.value,
table.lookup(expected_symbol.name),
'lookup should fins the value')
示例9: assert_is_success_and_output_dir_contains_at_least_result_files
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def assert_is_success_and_output_dir_contains_at_least_result_files(put: unittest.TestCase,
expected: SubProcessResult,
actual: sut.Result):
put.assertTrue(actual.is_success,
'Result should indicate success')
put.assertEqual(expected.exitcode,
actual.exit_code,
'Exit code')
contents_assertion = assert_dir_contains_at_least_result_files(PROCESS_OUTPUT_WITH_NON_ZERO_EXIT_STATUS,
actual.file_names)
contents_assertion.apply(put, actual.output_dir_path)
示例10: first_line_should_be_exit_identifier
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def first_line_should_be_exit_identifier(put: unittest.TestCase,
output: str,
expected_exit_value: ExitValue):
lines = output.split()
put.assertTrue(len(lines) > 0,
'There should be at least one line (found {})'.format(len(lines)))
first_line = lines[0]
put.assertEqual(expected_exit_value.exit_identifier,
first_line,
'first line')
示例11: _assert_source_is_not_at_eof_and_has_current_whole_line
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def _assert_source_is_not_at_eof_and_has_current_whole_line(put: unittest.TestCase,
source: ParseSource,
expected_current_line: str):
put.assertTrue(source.has_current_line,
'There should be remaining lines in the source')
put.assertFalse(source.is_at_eof,
'There should be remaining source')
put.assertEqual(expected_current_line,
source.current_line_text,
'Should should have given current line')
put.assertEqual(expected_current_line,
source.remaining_part_of_current_line,
'Current line should be identical to remaining-part-of-current-line')
示例12: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def _apply(self,
put: unittest.TestCase,
actual: Pattern,
message_builder: MessageBuilder):
put.assertEqual(self.pattern_string,
actual.pattern,
'regex pattern string')
for matching_string in self.matching_string_list:
put.assertTrue(bool(actual.search(matching_string)),
'reg-ex should match "{}"'.format(matching_string))
put.assertFalse(bool(actual.search(self.non_matching_string)),
'reg-ex should not match "{}"'.format(self.non_matching_string))
示例13: _apply
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def _apply(self,
put: unittest.TestCase,
value,
message_builder: asrt.MessageBuilder):
put.assertIsInstance(value, ConstantStringFragmentResolver)
assert isinstance(value, ConstantStringFragmentResolver) # Type info for IDE
put.assertTrue(value.is_string_constant,
message_builder.apply('is_string_constant'))
put.assertEqual(self.expected.string_constant,
value.string_constant,
message_builder.apply('string_constant'))
示例14: assert_equal_failure_details
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def assert_equal_failure_details(unit_tc: unittest.TestCase,
expected: FailureDetails,
actual: FailureDetails):
if expected.is_only_failure_message:
unit_tc.assertTrue(actual.is_only_failure_message,
'An error message is expected')
unit_tc.assertEqual(expected.failure_message,
actual.failure_message,
'The failure message should be the expected')
else:
unit_tc.assertFalse(actual.is_only_failure_message,
'An exception is expected')
unit_tc.assertEqual(expected.exception,
actual.exception,
'The exception should be the expected')
示例15: assert_is_file_with_contents
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertTrue [as 别名]
def assert_is_file_with_contents(test: unittest.TestCase,
file_path: pathlib.Path,
expected_content: str,
msg=None):
file_name = str(file_path)
test.assertTrue(file_path.exists(),
'File should exist: ' + file_name)
test.assertTrue(file_path.is_file(),
'Should be a regular file: ' + file_name)
f = open(str(file_path))
actual_contents = f.read()
f.close()
if msg is None:
msg = 'Contents of:' + file_name
test.assertEqual(expected_content,
actual_contents,
msg)