本文整理汇总了Python中unittest.TestCase类的典型用法代码示例。如果您正苦于以下问题:Python TestCase类的具体用法?Python TestCase怎么用?Python TestCase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestCase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
def check(self, tc, exp_log, cachedMsg):
exp_level, exp_msgs = exp_log
act_msgs = cachedMsg[1:]
if exp_level is 'INFO':
TestCase.assertEqual(tc, exp_msgs, act_msgs)
if exp_level is 'ERROR':
pass #
示例2: failUnlessRaises
def failUnlessRaises(self, excClass, callableObj, *args, **kwargs):
try:
TestCase.failUnlessRaises(self, excClass, callableObj, *args, **kwargs)
except:
self.kmod.stop()
self.kmod.save_logs(self.destdir)
raise
示例3: failIfAlmostEqual
def failIfAlmostEqual(self, first, second, places = 7, msg = None):
try:
TestCase.failIfAlmostEqual(self, first, second, places, msg)
except:
self.kmod.stop()
self.kmod.save_logs(self.destdir)
raise
示例4: what_is_session
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))
示例5: setUpClass
def setUpClass(cls):
TestCase.setUpClass()
virtwho.parser.VIRTWHO_CONF_DIR = '/this/does/not/exist'
virtwho.parser.VIRTWHO_GENERAL_CONF_PATH = '/this/does/not/exist.conf'
cls.queue = Queue()
cls.sam = FakeSam(cls.queue)
cls.sam.start()
示例6: setup_db
def setup_db(cls_obj: TestCase, table_paths: list):
cls_obj.db_client = pymongo.MongoClient()
cls_obj.collection_clients = dict()
for table_path in table_paths:
assert len(table_path) == 2, "must be a valid table path for MongoDB!"
cls_obj.collection_clients[table_path] = cls_obj.db_client[table_path[0]][table_path[1]]
示例7: test_status_raises_exception
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)
示例8: test_update
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'
示例9: test_del
def test_del(self):
person1 = db.add_person(p_first_name='Marc', p_last_name='SCHNEIDER',
p_birthdate=datetime.date(1973, 4, 24))
person2 = db.add_person(p_first_name='Monthy', p_last_name='PYTHON',
p_birthdate=datetime.date(1981, 4, 24))
person3 = db.add_person(p_first_name='Alberto', p_last_name='MATE',
p_birthdate=datetime.date(1947, 8, 6))
user1 = db.add_user_account(a_login='mschneider', a_password='IwontGiveIt', a_person_id=person1.id)
user2 = db.add_user_account(a_login='lonely', a_password='boy', a_person_id=person2.id)
user3 = db.add_user_account(a_login='domo', a_password='gik', a_person_id=person3.id)
user3_id = user3.id
user_acc_del = db.del_user_account(user3.id)
assert user_acc_del.id == user3_id
assert len(db.list_persons()) == 3
l_user = db.list_user_accounts()
assert len(l_user) == 2
for user in l_user:
assert user.login != 'domo'
person1_id = person1.id
person_del = db.del_person(person1.id)
assert person_del.id == person1_id
assert len(db.list_persons()) == 2
assert len(db.list_user_accounts()) == 1
try:
db.del_person(12345678910)
TestCase.fail(self, "Person does not exist, an exception should have been raised")
except DbHelperException:
pass
try:
db.del_user_account(12345678910)
TestCase.fail(self, "User account does not exist, an exception should have been raised")
except DbHelperException:
pass
示例10: tearDown
def tearDown(self):
TestCase.tearDown(self)
os.chdir(self.oldcwd)
rmtree(self.repo_parent)
rmtree(self.repo_one)
rmtree(self.repo_two)
示例11: __init__
def __init__(self, method='runTest'):
TestCase.__init__(self, method)
self.method = method
self.pdb_script = None
self.fnull = None
self.debugger = None
self.netbeans_port = 3219
示例12: check
def check(put: unittest.TestCase,
arrangement: Arrangement,
expectation: Expectation):
actor = ActorThatRecordsSteps(
arrangement.test_case_generator.recorder,
arrangement.actor)
def action(std_files: StdOutputFiles) -> PartialExeResult:
exe_conf = ExecutionConfiguration(dict(os.environ),
DEFAULT_ATC_OS_PROCESS_EXECUTOR,
sandbox_root_name_resolver.for_test(),
exe_atc_and_skip_assertions=std_files)
with home_directory_structure() as hds:
conf_phase_values = ConfPhaseValues(actor,
hds,
timeout_in_seconds=arrangement.timeout_in_seconds)
return sut.execute(arrangement.test_case_generator.test_case,
exe_conf,
conf_phase_values,
setup.default_settings(),
False,
)
out_files, partial_result = capture_stdout_err(action)
expectation.result.apply_with_message(put, partial_result,
'partial result')
put.assertEqual(expectation.step_recordings,
arrangement.test_case_generator.recorder.recorded_elements,
'steps')
expectation.atc_stdout_output.apply_with_message(put, out_files.out,
'stdout')
expectation.atc_stderr_output.apply_with_message(put, out_files.err,
'stderr')
示例13: setUp
def setUp(self):
TestCase.setUp(self)
self.root = "/tmp/lstestdir/"
self.link_file_src = "/tmp/mylink.txt"
self.date_string = self.todays_date()
self.remove_folder_structure()
self.create_folder_structure()
示例14: assert_same_html
def assert_same_html(asserter: TestCase, actual: str, expected: str):
"""
Tests whether two HTML strings are 'equivalent'
"""
bactual = HTMLBeautifier.beautify(actual)
bexpected = HTMLBeautifier.beautify(expected)
asserter.assertMultiLineEqual(bactual, bexpected)
示例15: _check_type
def _check_type(self,
put: unittest.TestCase,
actual,
message_builder: asrt.MessageBuilder
):
put.assertIsInstance(actual, self._expected_type,
message_builder.apply('Actual value is expected to be a ' + str(self._expected_type)))