本文整理汇总了Python中mocker.Mocker.restore方法的典型用法代码示例。如果您正苦于以下问题:Python Mocker.restore方法的具体用法?Python Mocker.restore怎么用?Python Mocker.restore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mocker.Mocker
的用法示例。
在下文中一共展示了Mocker.restore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_match_matched
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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()
示例2: test_find_match_not_matched
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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()
示例3: test_required_field_missing
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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()
示例4: test_read_tags
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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()
示例5: test_without_when
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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()
示例6: BundleDeserializationTests
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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)
示例7: test_write
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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_read_basic_fields
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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()
示例9: test_result_is_cached
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [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 restore [as 别名]
def mocker(verify_calls=True):
m = Mocker()
try:
yield m
finally:
m.restore()
if verify_calls:
m.verify()
示例11: test_without_when
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [as 别名]
def test_without_when(self):
mocker = Mocker()
mock_time = mocker.replace('time.time')
mock_time()
mocker.result(1.0)
mocker.replay()
controller = pid.PID(P=0.5, I=0.5, D=0.5, setpoint=0, initial=12)
mocker.restore()
mocker.verify()
self.assertEqual(controller.gains, (0.5, 0.5, 0.5))
self.assertAlmostEqual(controller.setpoint[0], 0.0)
self.assertEqual(len(controller.setpoint), 1)
self.assertAlmostEqual(controller.previous_time, 1.0)
self.assertAlmostEqual(controller.previous_error, -12.0)
self.assertAlmostEqual(controller.integrated_error, 0)
示例12: MockEnvironment
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [as 别名]
class MockEnvironment(object):
def __init__(self):
self.mocker = Mocker()
_setup_fileio(self.mocker)
_setup_mysqlclient(self.mocker)
_setup_subprocess(self.mocker)
def replace_environment(self):
self.mocker.replay()
def restore_environment(self):
# restore MySQLClient
# restore normal file io
# restore normal subprocess
self.mocker.restore()
示例13: test_delete
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [as 别名]
def test_delete(self):
to_test_dir = path('some\\non-existing\\file')
to_test_file = path(self.fn1)
mocker = Mocker()
mock_exists = mocker.replace(to_test_file.exists)
mock_exists()
mocker.result(True)
mocker.replay()
to_test_file.delete()
mocker.restore()
mocker.verify()
self.assertFalse(os.path.exists(self.fn1), msg='File was not deleted: "%s"' % self.fn1)
self.assertRaises(ValueError, to_test_dir.delete)
示例14: test_rmdir
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [as 别名]
def test_rmdir(self):
to_test_dir = path(self.tmpdir2)
to_test_file = path(self.fn1)
mocker = Mocker()
mock_is_dir = mocker.replace(to_test_dir.isdir)
mock_is_dir()
mocker.result(True)
mocker.replay()
to_test_dir.rmdir()
mocker.restore()
mocker.verify()
self.assertFalse(os.path.exists(self.tmpdir2), msg='Directory was not deleted: "%s"' % self.tmpdir2)
self.assertRaises(ValueError, to_test_file.rmdir)
示例15: test_authorized_when_plugin_returns_True
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import restore [as 别名]
def test_authorized_when_plugin_returns_True(self):
clientmanager = getUtility(IClientManager)
client = clientmanager.get_client_by_id('foo')
mocker = Mocker()
request = DummyRequest(headers={'X-BRIDGE-ORIGIN': 'foo'})
plugin = mocker.mock()
expect(plugin(request)).result(plugin)
expect(plugin.is_authorized(client)).result(True)
sm = get_current_registry()
sm.registerAdapter(plugin, [Interface], IAuthorizationPlugin,
name='foo', event=False)
mocker.replay()
manager = queryAdapter(request, IAuthorizationManager)
self.assertTrue(manager.authorize())
mocker.restore()
mocker.verify()