本文整理汇总了Python中mocker.Mocker.verify方法的典型用法代码示例。如果您正苦于以下问题:Python Mocker.verify方法的具体用法?Python Mocker.verify怎么用?Python Mocker.verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mocker.Mocker
的用法示例。
在下文中一共展示了Mocker.verify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_tags
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_read_tags(self):
mocker = Mocker()
csv_reader = mocker.mock()
headers = [
'title', 'isbn', 'publisher', 'list_price', 'publish_date',
'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
'barcode', 'comments', 'audience', 'awards']
first_line = [
'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a',
'blahblahblah', 'ms', 'annual']
field_map = {'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7,
'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }
csv_reader.next() # read headers
mocker.result(headers)
csv_reader.next() # read first line
mocker.result(first_line)
mocker.replay()
reader = CatalogReader(csv_reader, field_map)
item = reader.read()
self.assertIsInstance(item, CatalogItem)
self.assertEquals(2, len(item.tags))
self.assertEquals('ms', item.tags['audience'])
self.assertEquals('annual', item.tags['awards'])
mocker.restore()
mocker.verify()
示例2: test_required_field_missing
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_required_field_missing(self):
mocker = Mocker()
csv_reader = mocker.mock()
headers = [
'title', 'isbn', 'publisher', 'list_price', 'publish_date',
'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
'barcode']
first_line = [
'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a']
field_map = {
'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7,
'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }
csv_reader.next() # read headers
mocker.result(headers)
csv_reader.next() # read first line
mocker.result(first_line)
mocker.replay()
reader = CatalogReader(csv_reader, field_map)
item = reader.read()
self.assertIsNone(item.comments)
mocker.restore()
mocker.verify()
示例3: BundleDeserializationTests
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
class BundleDeserializationTests(TestCaseWithScenarios):
scenarios = [
('dummy_import_failure', {
'pathname': '/public/personal/admin/',
'is_public': 'true',
'content': 'bogus',
'content_filename': 'test1.json',
}),
]
def setUp(self):
super(BundleDeserializationTests, self).setUp()
self.bundle = fixtures.create_bundle(
self.pathname, self.content, self.content_filename)
self.mocker = Mocker()
def tearDown(self):
self.bundle.delete_files()
self.mocker.restore()
self.mocker.verify()
super(BundleDeserializationTests, self).tearDown()
def test_deserialize_failure_leaves_trace(self):
mock = self.mocker.patch(self.bundle)
expect(mock._do_deserialize(False)).throw(Exception("boom"))
self.mocker.replay()
self.bundle.deserialize(False)
self.assertFalse(self.bundle.is_deserialized)
self.assertEqual(self.bundle.deserialization_error.error_message, "boom")
def test_deserialize_ignores_deserialized_bundles(self):
# just reply as we're not using mocker in this test case
self.mocker.replay()
self.bundle.is_deserialized = True
self.bundle.deserialize(False)
self.assertTrue(self.bundle.is_deserialized)
def test_deserialize_sets_is_serialized_on_success(self):
mock = self.mocker.patch(self.bundle)
expect(mock._do_deserialize(False))
self.mocker.replay()
self.bundle.deserialize(False)
self.assertTrue(self.bundle.is_deserialized)
def test_deserialize_clears_old_error_on_success(self):
BundleDeserializationError.objects.create(
bundle=self.bundle,
error_message="not important").save()
mock = self.mocker.patch(self.bundle)
expect(mock._do_deserialize(False))
self.mocker.replay()
self.bundle.deserialize(False)
# note we cannot check for self.bundle.deserialization_error
# directly due to the way django handles operations that affect
# existing instances (it does not touch them like storm would
# IIRC).
self.assertRaises(
BundleDeserializationError.DoesNotExist,
BundleDeserializationError.objects.get, bundle=self.bundle)
示例4: test_read_basic_fields
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_read_basic_fields(self):
mocker = Mocker()
csv_reader = mocker.mock()
csv_reader.next()
header_line = [
'title', 'isbn', 'publisher', 'list_price', 'publish_date',
'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
'barcode', 'comments']
mocker.result(header_line)
csv_reader.next()
first_line = [
'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a',
'blahblahblah' ]
mocker.result(first_line)
mocker.replay()
field_map = {'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7,
'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }
reader = CatalogReader(csv_reader, field_map)
item = reader.read()
self.assertIsInstance(item, CatalogItem)
mocker.restore()
mocker.verify()
示例5: test_find_match_not_matched
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_find_match_not_matched(self):
key1 = "chr1:154000-230000"
mocker = Mocker()
junction = mocker.mock()
junction.coverage
mocker.result(40)
container1 = mocker.mock()
container2 = mocker.mock()
container1.keys()
mocker.result([key1])
container1[key1]
mocker.result(junction)
container2[key1]
mocker.throw(KeyError)
mocker.count(1)
mocker.replay()
self.common, self.diff = jc.findMatch(container1, container2)
self.assertEqual(self.common.keys(), [])
self.assertEqual(self.diff.keys(), [key1])
mocker.restore()
mocker.verify()
示例6: test_find_match_matched
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_find_match_matched(self):
key = "chr1:154000-230000"
mocker = Mocker()
junction = mocker.mock()
junction.coverage
mocker.result(40)
mocker.count(1, None)
container = mocker.mock()
container.keys()
mocker.result([key])
container[key]
mocker.result(junction)
mocker.count(1, None)
mocker.replay()
self.common, self.diff = jc.findMatch(container, container)
self.assertEqual(self.common.keys(), ["chr1:154000-230000"])
self.assertEqual(self.diff.keys(), [])
mocker.restore()
mocker.verify()
示例7: test_write
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_write(self):
mocker = Mocker()
db = mocker.mock()
insert_book ='''
insert into book (title, isbn, publisher, list_price,
publish_date, class, sheet_numbers, folio, print_type,
author, barcode, comments) values
('a', '1234', 'aph', '30', '2012', 'I.',
18, '4', 'mono', 'sb', 'a', 'blahblahblah')
'''
db.query(insert_book)
insert_tags = '''
'''
db.query(insert_tags)
db.commit()
mocker.replay()
writer = CatalogMySQLWriter(db)
item = CatalogItem(
'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb',
'a', 'blahblahblah', { 'audience': 'ms', 'awards': 'annual' })
writer.write(item)
mocker.restore()
mocker.verify()
示例8: test_without_when
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_without_when(self):
mocker = Mocker()
mock_time = mocker.replace('time.time')
mock_time()
mocker.result(1.0)
mock_time()
mocker.result(2.0)
mock_time()
mocker.result(3.0)
mock_time()
mocker.result(4.0)
mock_time()
mocker.result(5.0)
mocker.replay()
controller = pid.PID(P = 0.5, I = 0.5, D = 0.5,
setpoint = 0, initial = 12)
self.assertEqual(controller.calculate_response(6), -3)
self.assertEqual(controller.calculate_response(3), -4.5)
self.assertEqual(controller.calculate_response(-1.5), -0.75)
self.assertEqual(controller.calculate_response(-2.25), -1.125)
mocker.restore()
mocker.verify()
示例9: test_result_is_cached
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_result_is_cached(self):
viewlet = self.get_viewlet()
viewlet.update()
self.assertNotIn('purple', viewlet.generate_css(),
'Unexpectedly found "purple" in the CSS')
# Setting a custom style automatically invalidates the cache.
# For testing that things are cached, we stub the cache invalidation,
# so that the cache persists.
mocker = Mocker()
invalidate_cache_mock = mocker.replace(invalidate_cache)
expect(invalidate_cache_mock()).count(1, None)
mocker.replay()
ICustomStyles(self.layer['portal']).set('css.body-background', 'purple')
self.assertNotIn('purple', viewlet.generate_css(),
'The result was not cached.')
# Removing the stub and invalidating the cache should update the result.
mocker.restore()
mocker.verify()
invalidate_cache()
self.assertIn('purple', viewlet.generate_css(),
'Expected "purple" in CSS - does the style'
' css.body-background no longer work?')
示例10: mocker
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def mocker(verify_calls=True):
m = Mocker()
try:
yield m
finally:
m.restore()
if verify_calls:
m.verify()
示例11: test_default_opener
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_default_opener(self):
mocker = Mocker()
DeliciousAPI = mocker.replace("deliciousapi.DeliciousAPI")
dapi = DeliciousAPI()
dapi.get_user("test_user", "test_pass")
mocker.result(OPENER_RESULT)
mocker.replay()
default_opener("test_user", "test_pass")
mocker.verify()
示例12: test_fill_order
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_fill_order():
order = Order("item #1", 50)
mocker = Mocker()
inventory = mocker.mock()
inventory.remove("item #1", 50)
mocker.replay()
order.fill(inventory)
mocker.verify()
assert order.filled
示例13: test_healthcheck_returns_500_if_the_mysql_server_is_off
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_healthcheck_returns_500_if_the_mysql_server_is_off(self):
mocker = Mocker()
obj = mocker.replace("mysqlapi.api.models.DatabaseManager.is_up")
obj()
mocker.result(False)
mocker.replay()
request = RequestFactory().get("/resources/g8mysql/status/")
view = Healthcheck()
fake = mocks.FakeEC2Client()
view._client = fake
response = view.get(request, "g8mysql")
self.assertEqual(500, response.status_code)
mocker.verify()
示例14: test_import_urls_from_delicious
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_import_urls_from_delicious(self):
mocker = Mocker()
opener = mocker.mock()
opener("test_user", "test_pass")
mocker.result(OPENER_RESULT)
mocker.replay()
urls = import_urls_from_delicious("test_user", "test_pass", opener)
self.assertEquals("http://example.com/", urls[0].url)
self.assertEquals("http://google.com/", urls[1].url)
self.assertEquals("http://yahoo.com/", urls[2].url)
mocker.verify()
示例15: test_order_not_filled
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import verify [as 别名]
def test_order_not_filled():
order = Order("item #1", 1)
mocker = Mocker()
inventory = mocker.mock()
inventory.remove("item #1", 1)
mocker.throw(QuantityError)
mocker.replay()
order.fill(inventory)
mocker.verify()
assert not order.filled