Python mock.call() Examples
The following are 30
code examples of mock.call().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mock
, or try the search function
.
Example #1
Source File: test_arctic_fsck.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
def test_main(): with patch('arctic.scripts.arctic_fsck.Arctic') as Arctic, \ patch('arctic.scripts.arctic_fsck.get_mongodb_uri') as get_mongodb_uri, \ patch('arctic.scripts.arctic_fsck.do_db_auth') as do_db_auth: run_as_main(main, '--host', '%s:%s' % (sentinel.host, sentinel.port), '-v', '--library', 'sentinel.library', 'lib2', '-f') get_mongodb_uri.assert_called_once_with('sentinel.host:sentinel.port') Arctic.assert_called_once_with(get_mongodb_uri.return_value) assert do_db_auth.call_args_list == [call('%s:%s' % (sentinel.host, sentinel.port), Arctic.return_value._conn, 'arctic_sentinel'), call('%s:%s' % (sentinel.host, sentinel.port), Arctic.return_value._conn, 'arctic')] assert Arctic.return_value.__getitem__.return_value._fsck.call_args_list == [call(False), call(False), ]
Example #2
Source File: test_toplevel.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
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)]
Example #3
Source File: test_tickstore.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
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())}}
Example #4
Source File: test_copy_data.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
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'
Example #5
Source File: test_config_driver.py From toolium with Apache License 2.0 | 6 votes |
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')
Example #6
Source File: test_copy_data.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
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'
Example #7
Source File: test_copy_data.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
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'
Example #8
Source File: test_copy_data.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
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'
Example #9
Source File: test_arctic_create_user.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
def test_main_with_db_write(): with patch('arctic.scripts.arctic_create_user.MongoClient', autospec=True) as MC, \ patch('arctic.scripts.arctic_create_user.get_mongodb_uri', autospec=True) as get_mongodb_uri, \ patch('arctic.scripts.arctic_create_user.do_db_auth', autospec=True) as do_db_auth: run_as_main(main, '--host', 'some_host', '--db', 'some_db', '--write', 'jblackburn') get_mongodb_uri.assert_called_once_with('some_host') MC.assert_called_once_with(get_mongodb_uri.return_value) assert do_db_auth.call_args_list == [call('some_host', MC.return_value, 'some_db')] assert MC.return_value.__getitem__.call_args_list == [call('some_db')] db = MC.return_value.__getitem__.return_value assert [call('jblackburn', ANY, read_only=False)] == db.add_user.call_args_list
Example #10
Source File: installer_test.py From glazier with Apache License 2.0 | 6 votes |
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()
Example #11
Source File: ntp_test.py From glazier with Apache License 2.0 | 6 votes |
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)
Example #12
Source File: gitattr_checker_test.py From recipes-py with Apache License 2.0 | 6 votes |
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'), ])
Example #13
Source File: gitattr_checker_test.py From recipes-py with Apache License 2.0 | 6 votes |
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']), ])
Example #14
Source File: gitattr_checker_test.py From recipes-py with Apache License 2.0 | 6 votes |
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']), ])
Example #15
Source File: gitattr_checker_test.py From recipes-py with Apache License 2.0 | 6 votes |
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'), ])
Example #16
Source File: test_dockerapi.py From Paradrop with Apache License 2.0 | 6 votes |
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")])
Example #17
Source File: test_utils.py From arctic with GNU Lesser General Public License v2.1 | 6 votes |
def test_do_db_auth_role(): # Create the user agains the current mongo database admin_creds = Mock() user_creds = Mock() connection = MagicMock() with patch('arctic.scripts.utils.logger', autospec=True) as logger, \ patch('arctic.scripts.utils.get_auth', autospec=True, side_effect=[admin_creds, user_creds]) as get_auth: assert do_db_auth('hostname', connection, 'arctic_user') assert get_auth.call_args_list == [call('hostname', 'admin', 'admin'), call('hostname', 'arctic', 'arctic_user')] connection.admin.authenticate.assert_called_once_with(admin_creds.user, admin_creds.password) # Must also ensure that we auth against the user's db too ; the user # may well have read-only access to the admin database, but not to their user_db! connection.__getitem__.assert_called_once_with('arctic_user') connection.__getitem__.return_value.authenticate.assert_called_once_with(user_creds.user, user_creds.password) assert logger.error.call_count == 0
Example #18
Source File: device_model_test.py From loaner with Apache License 2.0 | 6 votes |
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='/')
Example #19
Source File: test_bricknil.py From bricknil with Apache License 2.0 | 5 votes |
def test_motor(self): m = TrainMotor('motor') m.set_output = Mock(side_effect=coroutine(lambda x,y :'the awaitable should return this')) await m.set_speed(10) assert m.set_output.call_args == call(0, 10)
Example #20
Source File: test_arctic_fsck.py From arctic with GNU Lesser General Public License v2.1 | 5 votes |
def test_main_dry_run(): with patch('arctic.scripts.arctic_fsck.Arctic') as Arctic, \ patch('arctic.scripts.arctic_fsck.get_mongodb_uri') as get_mongodb_uri, \ patch('arctic.scripts.arctic_fsck.do_db_auth') as do_db_auth: run_as_main(main, '--host', '%s:%s' % (sentinel.host, sentinel.port), '-v', '--library', 'sentinel.library', 'sentinel.lib2') get_mongodb_uri.assert_called_once_with('sentinel.host:sentinel.port') Arctic.assert_called_once_with(get_mongodb_uri.return_value) assert do_db_auth.call_count == 0 assert Arctic.return_value.__getitem__.return_value._fsck.call_args_list == [call(True), call(True), ]
Example #21
Source File: test_utils.py From arctic with GNU Lesser General Public License v2.1 | 5 votes |
def test_do_db_auth_no_user_creds(): user_creds = Mock() connection = MagicMock() with patch('arctic.scripts.utils.logger', autospec=True) as logger, \ patch('arctic.scripts.utils.get_auth', side_effect=[None, user_creds], autospec=True) as get_auth: connection['arctic_user'].authenticate.return_value = False assert not do_db_auth('hostname', connection, 'arctic_user') assert get_auth.call_args_list == [call('hostname', 'admin', 'admin'), call('hostname', 'arctic', 'arctic_user')] logger.error.assert_called_once_with("Failed to authenticate to db 'arctic_user' on 'hostname'," " using user credentials")
Example #22
Source File: test_utils.py From arctic with GNU Lesser General Public License v2.1 | 5 votes |
def test_do_db_auth_no_admin(): user_creds = Mock() connection = MagicMock() # Create the user agains the current mongo database with patch('arctic.scripts.utils.logger', autospec=True) as logger, \ patch('arctic.scripts.utils.get_auth', side_effect=[None, user_creds], autospec=True) as get_auth: connection.admin.authenticate.return_value = False assert do_db_auth('hostname', connection, 'arctic_user') assert logger.call_count == 0 assert get_auth.call_args_list == [call('hostname', 'admin', 'admin'), call('hostname', 'arctic', 'arctic_user')] connection['arctic_user'].authenticate.assert_called_once_with(user_creds.user, user_creds.password)
Example #23
Source File: test_ts_read.py From arctic with GNU Lesser General Public License v2.1 | 5 votes |
def test_read_allow_secondary(tickstore_lib): data = [{'ASK': 1545.25, 'ASKSIZE': 1002.0, 'BID': 1545.0, 'BIDSIZE': 55.0, 'CUMVOL': 2187387.0, 'DELETED_TIME': 0, 'INSTRTYPE': 'FUT', 'PRICE': 1545.0, 'SIZE': 1.0, 'TICK_STATUS': 0, 'TRADEHIGH': 1561.75, 'TRADELOW': 1537.25, 'index': 1185076787070}, {'CUMVOL': 354.0, 'DELETED_TIME': 0, 'PRICE': 1543.75, 'SIZE': 354.0, 'TRADEHIGH': 1543.75, 'TRADELOW': 1543.75, 'index': 1185141600600}] tickstore_lib.write('FEED::SYMBOL', data) with patch('pymongo.collection.Collection.find', side_effect=tickstore_lib._collection.find) as find: with patch('pymongo.collection.Collection.with_options', side_effect=tickstore_lib._collection.with_options) as with_options: with patch.object(tickstore_lib, '_read_preference', side_effect=tickstore_lib._read_preference) as read_pref: df = tickstore_lib.read('FEED::SYMBOL', columns=['BID', 'ASK', 'PRICE'], allow_secondary=True) assert read_pref.call_args_list == [call(True)] assert with_options.call_args_list == [call(read_preference=ReadPreference.NEAREST)] assert find.call_args_list == [call({'sy': 'FEED::SYMBOL'}, sort=[('s', 1)], projection={'s': 1, '_id': 0}), call({'sy': 'FEED::SYMBOL', 's': {'$lte': dt(2007, 8, 21, 3, 59, 47, 70000)}}, projection={'sy': 1, 'cs.PRICE': 1, 'i': 1, 'cs.BID': 1, 's': 1, 'im': 1, 'v': 1, 'cs.ASK': 1})] assert_array_equal(df['ASK'].values, np.array([1545.25, np.nan])) assert tickstore_lib._collection.find_one()['c'] == 2
Example #24
Source File: box_predictor_builder_test.py From vehicle_counting_tensorflow with MIT License | 5 votes |
def test_build_box_predictor_with_convlve_then_upsample_masks(self): box_predictor_proto = box_predictor_pb2.BoxPredictor() box_predictor_proto.mask_rcnn_box_predictor.fc_hyperparams.op = ( hyperparams_pb2.Hyperparams.FC) box_predictor_proto.mask_rcnn_box_predictor.conv_hyperparams.op = ( hyperparams_pb2.Hyperparams.CONV) box_predictor_proto.mask_rcnn_box_predictor.predict_instance_masks = True box_predictor_proto.mask_rcnn_box_predictor.mask_prediction_conv_depth = 512 box_predictor_proto.mask_rcnn_box_predictor.mask_height = 24 box_predictor_proto.mask_rcnn_box_predictor.mask_width = 24 box_predictor_proto.mask_rcnn_box_predictor.convolve_then_upsample_masks = ( True) mock_argscope_fn = mock.Mock(return_value='arg_scope') box_predictor = box_predictor_builder.build( argscope_fn=mock_argscope_fn, box_predictor_config=box_predictor_proto, is_training=True, num_classes=90) mock_argscope_fn.assert_has_calls( [mock.call(box_predictor_proto.mask_rcnn_box_predictor.fc_hyperparams, True), mock.call(box_predictor_proto.mask_rcnn_box_predictor.conv_hyperparams, True)], any_order=True) box_head = box_predictor._box_prediction_head class_head = box_predictor._class_prediction_head third_stage_heads = box_predictor._third_stage_heads self.assertFalse(box_head._use_dropout) self.assertFalse(class_head._use_dropout) self.assertAlmostEqual(box_head._dropout_keep_prob, 0.5) self.assertAlmostEqual(class_head._dropout_keep_prob, 0.5) self.assertEqual(box_predictor.num_classes, 90) self.assertTrue(box_predictor._is_training) self.assertEqual(box_head._box_code_size, 4) self.assertTrue( mask_rcnn_box_predictor.MASK_PREDICTIONS in third_stage_heads) self.assertEqual( third_stage_heads[mask_rcnn_box_predictor.MASK_PREDICTIONS] ._mask_prediction_conv_depth, 512) self.assertTrue(third_stage_heads[mask_rcnn_box_predictor.MASK_PREDICTIONS] ._convolve_then_upsample)
Example #25
Source File: box_predictor_builder_test.py From vehicle_counting_tensorflow with MIT License | 5 votes |
def test_build_box_predictor_with_mask_branch(self): box_predictor_proto = box_predictor_pb2.BoxPredictor() box_predictor_proto.mask_rcnn_box_predictor.fc_hyperparams.op = ( hyperparams_pb2.Hyperparams.FC) box_predictor_proto.mask_rcnn_box_predictor.conv_hyperparams.op = ( hyperparams_pb2.Hyperparams.CONV) box_predictor_proto.mask_rcnn_box_predictor.predict_instance_masks = True box_predictor_proto.mask_rcnn_box_predictor.mask_prediction_conv_depth = 512 box_predictor_proto.mask_rcnn_box_predictor.mask_height = 16 box_predictor_proto.mask_rcnn_box_predictor.mask_width = 16 mock_argscope_fn = mock.Mock(return_value='arg_scope') box_predictor = box_predictor_builder.build( argscope_fn=mock_argscope_fn, box_predictor_config=box_predictor_proto, is_training=True, num_classes=90) mock_argscope_fn.assert_has_calls( [mock.call(box_predictor_proto.mask_rcnn_box_predictor.fc_hyperparams, True), mock.call(box_predictor_proto.mask_rcnn_box_predictor.conv_hyperparams, True)], any_order=True) box_head = box_predictor._box_prediction_head class_head = box_predictor._class_prediction_head third_stage_heads = box_predictor._third_stage_heads self.assertFalse(box_head._use_dropout) self.assertFalse(class_head._use_dropout) self.assertAlmostEqual(box_head._dropout_keep_prob, 0.5) self.assertAlmostEqual(class_head._dropout_keep_prob, 0.5) self.assertEqual(box_predictor.num_classes, 90) self.assertTrue(box_predictor._is_training) self.assertEqual(box_head._box_code_size, 4) self.assertTrue( mask_rcnn_box_predictor.MASK_PREDICTIONS in third_stage_heads) self.assertEqual( third_stage_heads[mask_rcnn_box_predictor.MASK_PREDICTIONS] ._mask_prediction_conv_depth, 512)
Example #26
Source File: test_connection.py From pylxd with Apache License 2.0 | 5 votes |
def test_get_ws(self, host, result, mock_ws, _): conn = connection.LXDConnection(host) conn.get_ws('/fake/path') mock_ws.assert_has_calls([mock.call(result), mock.call().connect()])
Example #27
Source File: test_hosts.py From arctic with GNU Lesser General Public License v2.1 | 5 votes |
def test_get_arctic_lib_with_known_host(): with patch('arctic.arctic.Arctic') as Arctic: get_arctic_lib("foo@bar") assert Arctic.call_args_list == [call('bar')]
Example #28
Source File: bootstrap_test.py From loaner with Apache License 2.0 | 5 votes |
def test_bootstrap_load_config_yaml( self, mock_config, mock_load_config_from_yaml): """Tests if config_defaults.yaml is loaded into datastore.""" mock_config.get.return_value = True bootstrap.bootstrap_load_config_yaml() mock_config.set.assert_has_calls([ mock.call('test_name', 'test_value', False), mock.call('bootstrap_started', True, False)], any_order=True)
Example #29
Source File: process_action_test.py From loaner with Apache License 2.0 | 5 votes |
def test_process_action_handler(self, mock_importactions, mock_loginfo): """Test the ProcessActionHandler, which imports the sample action.""" class ActionSample(object): ACTION_NAME = 'sample' FRIENDLY_NAME = 'Sample action' def run(self, device=None, shelf=None): """Run the action.""" del shelf # Unused. info = 'Action with a %s.' % device.__class__.__name__ logging.info(info) mock_importactions.return_value = { 'async': { 'sample1': ActionSample(), 'sample2': ActionSample() }} test_device = device_model.Device() payload = pickle.dumps({ 'device': test_device, 'shelf': None, 'async_actions': ['sample1', 'sample2']}) response = self.testapp.post(r'/_ah/queue/process-action', payload) self.assertEqual(response.status_int, 200) expected_calls = [ mock.call('ProcessActionHandler loaded %d async actions: %s', 2, "['sample1', 'sample2']"), mock.call('Action with a Device.') ] mock_loginfo.assert_has_calls(expected_calls) # Task for sample1 Action created a task for sample2 Action. self.assertLen(self.taskqueue_add.mock_calls, 1) task_payload = pickle.loads( self.taskqueue_add.call_args_list[0][1]['payload']) self.assertEqual(task_payload['async_actions'], ['sample2'])
Example #30
Source File: run_custom_events_test.py From loaner with Apache License 2.0 | 5 votes |
def test_events_devices_and_shelves(self): """Tests with events, one returns one Device, other many Shelves.""" self.setup_events() self.setup_devices() # pylint: disable=no-value-for-parameter self.setup_shelves() self.device1.last_known_healthy = _NOW - datetime.timedelta(days=4) self.device1.put() self.device2.last_known_healthy = _NOW - datetime.timedelta(days=2) self.device2.put() # Will trigger one shelf rule self.shelf1.last_audit_time = _NOW - datetime.timedelta(days=4) self.shelf1.put() # Will trigger both shelf rules because capacity=24 self.shelf2.last_audit_time = _NOW - datetime.timedelta(days=4) self.shelf2.put() self.testbed.mock_raiseevent.reset_mock() response = self.testapp.get(r'/_cron/run_custom_events') self.assertEqual(response.status_int, 200) self.assertTrue(self.testbed.mock_raiseevent.called) expected_calls = [ mock.call(event_name='device_event', device=self.device1, shelf=None), mock.call(event_name='shelf_event_1', device=None, shelf=self.shelf1), mock.call(event_name='shelf_event_1', device=None, shelf=self.shelf2), mock.call(event_name='shelf_event_2', device=None, shelf=self.shelf2), ] for call in expected_calls: self.assertIn(call, self.testbed.mock_raiseevent.mock_calls) self.assertEqual( len(self.testbed.mock_raiseevent.mock_calls), len(expected_calls))