本文整理匯總了Python中mock.call方法的典型用法代碼示例。如果您正苦於以下問題:Python mock.call方法的具體用法?Python mock.call怎麽用?Python mock.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mock
的用法示例。
在下文中一共展示了mock.call方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_buildImage_worker
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_buildImage_worker():
update = MagicMock()
service = MagicMock()
client = MagicMock()
client.build.return_value = [
'{"message": "Message1"}',
'{"message": "[===> ] FOO"}',
'{"message": "Message3 "}'
]
res = dockerapi._build_image(update, service, client, True)
assert res is None
# The second message should be suppressed as well as the whitespace after Message3.
update.progress.assert_has_calls([call("Message1"), call("Message3")])
示例2: testSyncClockToNtp
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def testSyncClockToNtp(self, request, subproc, sleep):
os.environ['TZ'] = 'UTC'
time.tzset()
return_time = mock.Mock()
return_time.ref_time = 1453220630.64458
request.side_effect = iter([None, None, None, return_time])
subproc.return_value = True
# Too Few Retries
self.assertRaises(ntp.NtpException, ntp.SyncClockToNtp)
sleep.assert_has_calls([mock.call(30), mock.call(30)])
# Sufficient Retries
ntp.SyncClockToNtp(retries=3, server='time.google.com')
request.assert_called_with(mock.ANY, 'time.google.com', version=3)
subproc.assert_has_calls([
mock.call(
r'X:\Windows\System32\cmd.exe /c date 01-19-2016', shell=True),
mock.call(r'X:\Windows\System32\cmd.exe /c time 16:23:50', shell=True)
])
# Socket Error
request.side_effect = ntp.socket.gaierror
self.assertRaises(ntp.NtpException, ntp.SyncClockToNtp)
# NTP lib error
request.side_effect = ntp.ntplib.NTPException
self.assertRaises(ntp.NtpException, ntp.SyncClockToNtp)
示例3: testBuildInfoSave
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def testBuildInfoSave(self, build_info, sv):
fs = fake_filesystem.FakeFilesystem()
installer.open = fake_filesystem.FakeFileOpen(fs)
installer.os = fake_filesystem.FakeOsModule(fs)
timer_root = r'{0}\{1}'.format(installer.constants.REG_ROOT, 'Timers')
fs.CreateFile(
'{}/build_info.yaml'.format(installer.constants.SYS_CACHE),
contents='{BUILD: {opt 1: true, TIMER_opt 2: some value, opt 3: 12345}}\n'
)
s = installer.BuildInfoSave(None, build_info)
s.Run()
sv.assert_has_calls([
mock.call('opt 1', True, 'HKLM', installer.constants.REG_ROOT),
mock.call('TIMER_opt 2', 'some value', 'HKLM', timer_root),
mock.call('opt 3', 12345, 'HKLM', installer.constants.REG_ROOT),
], any_order=True)
s.Run()
示例4: test_create_chrome_options
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_create_chrome_options(webdriver_mock, config):
config.add_section('ChromePreferences')
config.set('ChromePreferences', 'download.default_directory', '/tmp')
config.add_section('ChromeMobileEmulation')
config.set('ChromeMobileEmulation', 'deviceName', 'Google Nexus 5')
config.add_section('ChromeArguments')
config.set('ChromeArguments', 'lang', 'es')
config_driver = ConfigDriver(config)
config_driver._create_chrome_options()
webdriver_mock.ChromeOptions.assert_called_once_with()
webdriver_mock.ChromeOptions().add_experimental_option.assert_has_calls(
[mock.call('prefs', {'download.default_directory': '/tmp'}),
mock.call('mobileEmulation', {'deviceName': 'Google Nexus 5'})]
)
webdriver_mock.ChromeOptions().add_argument.assert_called_once_with('lang=es')
示例5: testCachesGitattributesFiles
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def testCachesGitattributesFiles(self):
self.assertEqual(
self._attr_checker.check_files('rev1', ['foo', 'bar', 'baz/foo']),
[True, False, True]
)
self.assertNewCalls([
mock.call(['cat-file', '--batch-check=%(objectname)'],
'rev1:.gitattributes\nrev1:baz/.gitattributes'),
mock.call(['cat-file', 'blob', 'blob1']),
])
# The revision changed, but the .gitattributes files did not. We shouldn't
# ask git for information about file blobs.
self.assertEqual(
self._attr_checker.check_files('rev2', ['foo', 'bar', 'baz/foo']),
[True, False, True]
)
self.assertNewCalls([
mock.call(['cat-file', '--batch-check=%(objectname)'],
'rev2:.gitattributes\nrev2:baz/.gitattributes'),
])
示例6: testQueriesNewGitattributesFile
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def testQueriesNewGitattributesFile(self):
self.assertEqual(
self._attr_checker.check_files('rev2', ['foo', 'bar', 'baz/foo']),
[True, False, True]
)
self.assertNewCalls([
mock.call(['cat-file', '--batch-check=%(objectname)'],
'rev2:.gitattributes\nrev2:baz/.gitattributes'),
mock.call(['cat-file', 'blob', 'blob1']),
])
# A new .gitattribute file was added, but the old one hasn't changed.
self.assertEqual(
self._attr_checker.check_files('rev3', ['foo', 'bar', 'baz/foo']),
[True, False, False]
)
self.assertNewCalls([
mock.call(['cat-file', '--batch-check=%(objectname)'],
'rev3:.gitattributes\nrev3:baz/.gitattributes'),
mock.call(['cat-file', 'blob', 'blob3']),
])
示例7: testQueriesModifiedGitattributesFile
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def testQueriesModifiedGitattributesFile(self):
self.assertEqual(
self._attr_checker.check_files('rev3', ['foo', 'bar', 'baz/foo']),
[True, False, False]
)
self.assertNewCalls([
mock.call(['cat-file', '--batch-check=%(objectname)'],
'rev3:.gitattributes\nrev3:baz/.gitattributes'),
mock.call(['cat-file', 'blob', 'blob1']),
mock.call(['cat-file', 'blob', 'blob3']),
])
# The .gitattribute file was modified
self.assertEqual(
self._attr_checker.check_files('rev4', ['foo', 'bar', 'baz/foo']),
[True, True, False]
)
self.assertNewCalls([
mock.call(['cat-file', '--batch-check=%(objectname)'],
'rev4:.gitattributes\nrev4:baz/.gitattributes'),
mock.call(['cat-file', 'blob', 'blob4']),
])
示例8: testDeletedGitattributesFile
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def testDeletedGitattributesFile(self):
self.assertEqual(
self._attr_checker.check_files('rev1', ['foo', 'bar', 'baz/foo']),
[True, False, True]
)
self.assertNewCalls([
mock.call(['cat-file', '--batch-check=%(objectname)'],
'rev1:.gitattributes\nrev1:baz/.gitattributes'),
mock.call(['cat-file', 'blob', 'blob1']),
])
# The .gitattribute file was deleted
self.assertEqual(
self._attr_checker.check_files('rev5', ['foo', 'bar', 'baz/foo']),
[False, False, False]
)
self.assertNewCalls([
mock.call(['cat-file', '--batch-check=%(objectname)'],
'rev5:.gitattributes\nrev5:baz/.gitattributes'),
])
示例9: test_unenroll
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_unenroll(self, mock_return):
self.enroll_test_device(loanertest.TEST_DIR_DEVICE_DEFAULT)
self.test_device.assigned_user = loanertest.USER_EMAIL
self.testbed.mock_raiseevent.return_value = self.test_device
self.test_device.unenroll(loanertest.USER_EMAIL)
mock_return.assert_called_once_with(loanertest.USER_EMAIL)
self.mock_directoryclient.move_chrome_device_org_unit.assert_has_calls([
mock.call(
device_id=self.test_device.chrome_device_id,
org_unit_path=constants.ORG_UNIT_DICT['DEFAULT']),
mock.call(
device_id=self.test_device.chrome_device_id, org_unit_path='/')])
self.assertFalse(self.test_device.enrolled)
self.assertIsNone(self.test_device.assigned_user)
self.assertIsNone(self.test_device.assignment_date)
self.assertIsNone(self.test_device.due_date)
self.assertIsNone(self.test_device.last_reminder)
self.assertIsNone(self.test_device.next_reminder)
self.assertIsNone(self.test_device.mark_pending_return_date)
self.assertEqual(self.test_device.current_ou, '/')
self.mock_directoryclient.move_chrome_device_org_unit.assert_any_call(
device_id=u'unique_id', org_unit_path='/')
示例10: test_copy_data_no_force
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_copy_data_no_force(arctic, mongo_host):
src = 'user.library'
dest = 'user.library2'
# Put ts, ts1 in library
arctic[src].write('some_ts', ts1)
arctic[src].write('some_ts1', ts1)
# Put some other value for ts in library2
arctic[dest].write('some_ts', ts)
# Create the user against the current mongo database
src_host = 'arctic_' + src + '@' + mongo_host
dest_host = 'arctic_' + dest + '@' + mongo_host
with patch('arctic.scripts.arctic_copy_data.logger') as logger:
run_as_main(mcd.main, '--src', src_host, '--dest', dest_host, '--log', 'CR101', 'some_ts', 'some_ts1')
assert_frame_equal(ts, arctic[dest].read('some_ts').data)
assert_frame_equal(ts1, arctic[dest].read('some_ts1').data)
assert logger.info.call_args_list == [call('Copying data from %s -> %s' % (src_host, dest_host)),
call('Copying: 2 symbols')]
assert logger.warn.call_args_list == [call('Symbol: some_ts already exists in %s, use --force to overwrite or --splice to join with existing data' % dest_host)]
assert arctic[dest].read_audit_log('some_ts1')[0]['message'] == 'CR101'
示例11: test_copy_data_force
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_copy_data_force(arctic, mongo_host):
src = 'user.library'
dest = 'user.library2'
# Put ts, ts1 in library
arctic[src].write('some_ts', ts)
arctic[src].write('some_ts1', ts1)
# Put some other value for ts in library2
arctic[dest].write('some_ts', ts1)
# Create the user against the current mongo database
src_host = src + '@' + mongo_host
dest_host = dest + '@' + mongo_host
with patch('arctic.scripts.arctic_copy_data.logger') as logger:
run_as_main(mcd.main, '--src', src_host, '--dest', dest_host, '--log', 'CR101', '--force', 'some_ts', 'some_ts1')
assert_frame_equal(ts, arctic[dest].read('some_ts').data)
assert_frame_equal(ts1, arctic[dest].read('some_ts1').data)
assert logger.info.call_args_list == [call('Copying data from %s -> %s' % (src_host, dest_host)),
call('Copying: 2 symbols')]
assert logger.warn.call_args_list == [call('Symbol: some_ts already exists in destination, OVERWRITING')]
assert arctic[dest].read_audit_log('some_ts1')[0]['message'] == 'CR101'
示例12: test_copy_data_splice
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_copy_data_splice(arctic, mongo_host):
src = 'user.library'
dest = 'user.library2'
# Put ts, ts1 in library
arctic[src].write('some_ts', ts2)
arctic[src].write('some_ts1', ts1)
# Put some other value for ts in library2
arctic[dest].write('some_ts', ts)
# Create the user against the current mongo database
src_host = src + '@' + mongo_host
dest_host = dest + '@' + mongo_host
with patch('arctic.scripts.arctic_copy_data.logger') as logger:
run_as_main(mcd.main, '--src', src_host, '--dest', dest_host, '--log', 'CR101', '--splice', 'some_ts', 'some_ts1')
assert_frame_equal(ts3, arctic[dest].read('some_ts').data)
assert_frame_equal(ts1, arctic[dest].read('some_ts1').data)
assert logger.info.call_args_list == [call('Copying data from %s -> %s' % (src_host, dest_host)),
call('Copying: 2 symbols')]
assert logger.warn.call_args_list == [call('Symbol: some_ts already exists in destination, splicing in new data')]
assert arctic[dest].read_audit_log('some_ts')[0]['message'] == 'CR101'
示例13: test_copy_data_wild
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_copy_data_wild(arctic, mongo_host):
src = 'user.library'
dest = 'user.library2'
# Put ts, ts1 in library
arctic[src].write('some_a_ts', ts)
arctic[src].write('some_a_ts1', ts1)
arctic[src].write('some_b_ts1', ts1)
arctic[src].write('some_c_ts1', ts1)
# Create the user against the current mongo database
src_host = 'arctic_' + src + '@' + mongo_host
dest_host = 'arctic_' + dest + '@' + mongo_host
with patch('arctic.scripts.arctic_copy_data.logger') as logger:
run_as_main(mcd.main, '--src', src_host, '--dest', dest_host, '--log', 'CR101', '.*_a_.*', '.*_b_.*')
assert_frame_equal(ts, arctic[dest].read('some_a_ts').data)
assert_frame_equal(ts1, arctic[dest].read('some_a_ts1').data)
assert_frame_equal(ts1, arctic[dest].read('some_b_ts1').data)
assert logger.info.call_args_list == [call('Copying data from %s -> %s' % (src_host, dest_host)),
call('Copying: 3 symbols')]
assert arctic[dest].read_audit_log('some_a_ts1')[0]['message'] == 'CR101'
示例14: test_read
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_read():
self = create_autospec(TopLevelTickStore)
tsl = TickStoreLibrary(create_autospec(TickStore), create_autospec(DateRange))
self._get_libraries.return_value = [tsl, tsl]
dr = create_autospec(DateRange)
with patch('pandas.concat') as concat:
res = TopLevelTickStore.read(self, sentinel.symbol, dr,
columns=sentinel.include_columns,
include_images=sentinel.include_images)
assert concat.call_args_list == [call([tsl.library.read.return_value,
tsl.library.read.return_value])]
assert res == concat.return_value
assert tsl.library.read.call_args_list == [call(sentinel.symbol, tsl.date_range.intersection.return_value,
sentinel.include_columns, include_images=sentinel.include_images),
call(sentinel.symbol, tsl.date_range.intersection.return_value,
sentinel.include_columns, include_images=sentinel.include_images)]
示例15: test_mongo_date_range_query
# 需要導入模塊: import mock [as 別名]
# 或者: from mock import call [as 別名]
def test_mongo_date_range_query():
self = create_autospec(TickStore)
self._collection = create_autospec(Collection)
self._symbol_query.return_value = {"sy": {"$in" : ["s1" , "s2"]}}
self._collection.aggregate.return_value = iter([{"_id": "s1", "start": dt(2014, 1, 1, 0, 0, tzinfo=mktz())},
{"_id": "s2", "start": dt(2014, 1, 1, 12, 0, tzinfo=mktz())}])
self._collection.find_one.side_effect = [
{'e': dt(2014, 1, 1, 15, 0, tzinfo=mktz())},
{'e': dt(2014, 1, 2, 12, 0, tzinfo=mktz())}]
query = TickStore._mongo_date_range_query(self, 'sym', DateRange(dt(2014, 1, 2, 0, 0, tzinfo=mktz()),
dt(2014, 1, 3, 0, 0, tzinfo=mktz())))
assert self._collection.aggregate.call_args_list == [call([
{"$match": {"s": {"$lte": dt(2014, 1, 2, 0, 0, tzinfo=mktz())}, "sy": {"$in" : ["s1" , "s2"]}}},
{"$project": {"_id": 0, "s": 1, "sy": 1}},
{"$group": {"_id": "$sy", "start": {"$max": "$s"}}},
{"$sort": {"start": 1}}])]
assert self._collection.find_one.call_args_list == [
call({'sy': 's1', 's': dt(2014, 1, 1, 0, 0, tzinfo=mktz())}, {'e': 1}),
call({'sy': 's2', 's': dt(2014, 1, 1, 12, 0, tzinfo=mktz())}, {'e': 1})]
assert query == {'s': {'$gte': dt(2014, 1, 1, 12, 0, tzinfo=mktz()), '$lte': dt(2014, 1, 3, 0, 0, tzinfo=mktz())}}