def testBinaryManagerInitialized(self, needs_init_mock, init_mock, _): needs_init_mock.return_value = False bm = local_first_binary_manager.LocalFirstBinaryManager( None, None, None, None, None, None) bm._FetchBinaryManagerPath(None) self.assertEqual(needs_init_mock.call_count, 1) self.assertEqual(init_mock.call_count, 0)
def testBinaryManagerPathReturned(self, needs_init_mock, fetch_mock): needs_init_mock.return_value = False fetch_mock.return_value = 'path' bm = local_first_binary_manager.LocalFirstBinaryManager( None, None, 'os', 'arch', None, 'os_version') self.assertEqual(bm._FetchBinaryManagerPath('dep'), 'path') self.assertEqual(needs_init_mock.call_count, 1) self.assertEqual(fetch_mock.call_count, 1) fetch_mock.assert_called_once_with('dep', 'os', 'arch', 'os_version')
def testRemotePathReturned(self, local_mock, remote_mock): local_mock.return_value = None remote_mock.return_value = 'path' bm = local_first_binary_manager.LocalFirstBinaryManager( None, None, None, None, None, None) path = bm.FetchPath('dep') self.assertEqual(path, 'path') local_mock.assert_called_once_with('dep') remote_mock.assert_called_once_with('dep') self.assertEqual(local_mock.call_count, 1) self.assertEqual(remote_mock.call_count, 1)
def testLocalPathReturned(self, local_mock, remote_mock): local_mock.return_value = 'path' bm = local_first_binary_manager.LocalFirstBinaryManager( None, None, None, None, None, None) path = bm.FetchPath('dep') self.assertEqual(path, 'path') local_mock.assert_called_once_with('dep') # mock's built-in call counting appears to be broken, as the following will # pass at the time of writing: # local_mock.assert_not_called() # local_mock.assert_called_once() # However, manually checking the call counts works, so use that. self.assertEqual(local_mock.call_count, 1) self.assertEqual(remote_mock.call_count, 0)
def testRemotePathException(self, local_mock, remote_mock): def RaiseException(_): raise binary_manager.NoPathFoundError(None, None) local_mock.return_value = None remote_mock.side_effect = RaiseException bm = local_first_binary_manager.LocalFirstBinaryManager( None, None, None, None, None, None) path = bm.FetchPath('dep') self.assertEqual(path, None) # Ensure the value is cached. self.assertIn('dep', bm._dependency_cache) local_mock.assert_called_once_with('dep') remote_mock.assert_called_once_with('dep') self.assertEqual(local_mock.call_count, 1) self.assertEqual(remote_mock.call_count, 1)
def testValidDependency(self): bm = local_first_binary_manager.LocalFirstBinaryManager( self._build_dir, None, None, None, [], None) dep_path = os.path.join(self._build_dir, 'dep') open(dep_path, 'w').close() self.assertEqual(bm._FetchLocalPath('dep'), dep_path)
def testMissingDependency(self): bm = local_first_binary_manager.LocalFirstBinaryManager( self._build_dir, None, None, None, [], None) self.assertIsNone(bm._FetchLocalPath('dep'))
def testIgnoredDependency(self): bm = local_first_binary_manager.LocalFirstBinaryManager( self._build_dir, None, None, None, ['ignored_dep'], None) open(os.path.join(self._build_dir, 'ignored_dep'), 'w').close() self.assertIsNone(bm._FetchLocalPath('ignored_dep'))
def testNoBuildDirectory(self): bm = local_first_binary_manager.LocalFirstBinaryManager( None, None, None, None, None, None) self.assertIsNone(bm._FetchLocalPath('dep'))