def testSimpleGroupsWithMultiplePaths(self): path_info = dependency_manager.LocalPathInfo( [['file1', 'file2', 'file3']]) self.assertTrue(path_info.IsPathInLocalPaths('file1')) self.assertTrue(path_info.IsPathInLocalPaths('file2')) self.assertTrue(path_info.IsPathInLocalPaths('file3')) _CreateFile('file1') _CreateFile('file2') _CreateFile('file3') s = os.stat('file1') time0 = s.st_mtime _ChangeFileTime('file1', time0, 4) _ChangeFileTime('file2', time0, 2) _ChangeFileTime('file3', time0, 0) self.assertEqual('file1', path_info.GetLocalPath()) _ChangeFileTime('file1', time0, 0) _ChangeFileTime('file2', time0, 4) _ChangeFileTime('file3', time0, 2) self.assertEqual('file2', path_info.GetLocalPath()) _ChangeFileTime('file1', time0, 2) _ChangeFileTime('file2', time0, 0) _ChangeFileTime('file3', time0, 4) self.assertEqual('file3', path_info.GetLocalPath())
def testSimpleGroupWithOnePath(self): path_info = dependency_manager.LocalPathInfo(['file.txt']) self.assertTrue(path_info.IsPathInLocalPaths('file.txt')) self.assertFalse(path_info.IsPathInLocalPaths('other.txt')) # GetLocalPath returns None if the file doesn't exist. # Otherwise it will return the file path. self.assertIsNone(path_info.GetLocalPath()) _CreateFile('file.txt') self.assertEqual('file.txt', path_info.GetLocalPath())
def testInitLocalPaths(self): local_path_info = dependency_manager.LocalPathInfo(['path0', 'path1']) dep_info = dependency_manager.DependencyInfo('dep', 'platform', 'config_path', local_path_info) self.assertEqual('dep', dep_info.dependency) self.assertEqual('platform', dep_info.platform) self.assertEqual(['config_path'], dep_info.config_paths) self.assertEqual(local_path_info, dep_info._local_path_info) self.assertFalse(dep_info.has_cloud_storage_info)
def setUp(self): self.lp_info012 = dependency_manager.LocalPathInfo( ['path0', 'path1', 'path2']) self.cloud_storage_info = dependency_manager.CloudStorageInfo( 'cs_bucket', 'cs_hash', 'download_path', 'cs_remote_path') self.dep_info = dependency_manager.DependencyInfo( 'dep', 'platform', 'config_file', local_path_info=self.lp_info012, cloud_storage_info=self.cloud_storage_info) self.setUpPyfakefs()
def testMultipleGroupsWithSinglePaths(self): path_info = dependency_manager.LocalPathInfo( ['file1', 'file2', 'file3']) self.assertTrue(path_info.IsPathInLocalPaths('file1')) self.assertTrue(path_info.IsPathInLocalPaths('file2')) self.assertTrue(path_info.IsPathInLocalPaths('file3')) self.assertIsNone(path_info.GetLocalPath()) _CreateFile('file3') self.assertEqual('file3', path_info.GetLocalPath()) _CreateFile('file2') self.assertEqual('file2', path_info.GetLocalPath()) _CreateFile('file1') self.assertEqual('file1', path_info.GetLocalPath())
def testUpdate(self): path_info1 = dependency_manager.LocalPathInfo( [['file1', 'file2']]) # One group with two files. path_info2 = dependency_manager.LocalPathInfo( ['file1', 'file2', 'file3']) # Three groups self.assertTrue(path_info1.IsPathInLocalPaths('file1')) self.assertTrue(path_info1.IsPathInLocalPaths('file2')) self.assertFalse(path_info1.IsPathInLocalPaths('file3')) _CreateFile('file3') self.assertIsNone(path_info1.GetLocalPath()) path_info1.Update(path_info2) self.assertTrue(path_info1.IsPathInLocalPaths('file1')) self.assertTrue(path_info1.IsPathInLocalPaths('file2')) self.assertTrue(path_info1.IsPathInLocalPaths('file3')) self.assertEqual('file3', path_info1.GetLocalPath()) _CreateFile('file1') time0 = os.stat('file1').st_mtime _ChangeFileTime('file3', time0, 2) # Make file3 more recent. # Check that file3 is in a later group. self.assertEqual('file1', path_info1.GetLocalPath())
def testUpdateRequiredArgsConflicts(self): lp_info = dependency_manager.LocalPathInfo(['path0', 'path2']) dep_info1 = dependency_manager.DependencyInfo('dep1', 'platform1', 'config_path1', local_path_info=lp_info) dep_info2 = dependency_manager.DependencyInfo('dep1', 'platform2', 'config_path2', local_path_info=lp_info) dep_info3 = dependency_manager.DependencyInfo('dep2', 'platform1', 'config_path3', local_path_info=lp_info) self.assertRaises(ValueError, dep_info1.Update, dep_info2) self.assertRaises(ValueError, dep_info1.Update, dep_info3) self.assertRaises(ValueError, dep_info3.Update, dep_info2)
def testMultipleGroupsWithMultiplePaths(self): path_info = dependency_manager.LocalPathInfo([['file1', 'file2'], ['file3', 'file4']]) self.assertTrue(path_info.IsPathInLocalPaths('file1')) self.assertTrue(path_info.IsPathInLocalPaths('file2')) self.assertTrue(path_info.IsPathInLocalPaths('file3')) self.assertTrue(path_info.IsPathInLocalPaths('file4')) _CreateFile('file1') _CreateFile('file3') s = os.stat('file1') time0 = s.st_mtime # Check that file1 is always returned, even if it is not the most recent # file, because it is part of the first group and exists. _ChangeFileTime('file1', time0, 2) _ChangeFileTime('file3', time0, 0) self.assertEqual('file1', path_info.GetLocalPath()) _ChangeFileTime('file1', time0, 0) _ChangeFileTime('file3', time0, 2) self.assertEqual('file1', path_info.GetLocalPath())
def testEmptyInstance(self): path_info = dependency_manager.LocalPathInfo(None) self.assertIsNone(path_info.GetLocalPath()) self.assertFalse(path_info.IsPathInLocalPaths('file.txt'))
def testUpdateAllInfo(self): lp_info1 = dependency_manager.LocalPathInfo(['path1']) dep_info1 = dependency_manager.DependencyInfo('dep1', 'platform1', 'config_path1', local_path_info=lp_info1) cs_info2 = dependency_manager.CloudStorageInfo( cs_bucket='cs_bucket2', cs_hash='cs_hash2', download_path='download_path2', cs_remote_path='cs_remote_path2') lp_info2 = dependency_manager.LocalPathInfo(['path2']) dep_info2 = dependency_manager.DependencyInfo( 'dep1', 'platform1', 'config_path2', local_path_info=lp_info2, cloud_storage_info=cs_info2) lp_info3 = dependency_manager.LocalPathInfo(['path3']) dep_info3 = dependency_manager.DependencyInfo('dep1', 'platform1', 'config_path3', local_path_info=lp_info3) lp_info4 = dependency_manager.LocalPathInfo(['path4']) cs_info4 = dependency_manager.CloudStorageInfo( cs_bucket='cs_bucket4', cs_hash='cs_hash4', download_path='download_path4', cs_remote_path='cs_remote_path4') dep_info4 = dependency_manager.DependencyInfo( 'dep1', 'platform1', 'config_path4', local_path_info=lp_info4, cloud_storage_info=cs_info4) self.assertTrue(dep_info1._local_path_info.IsPathInLocalPaths('path1')) self.assertFalse( dep_info1._local_path_info.IsPathInLocalPaths('path2')) self.assertFalse( dep_info1._local_path_info.IsPathInLocalPaths('path3')) self.assertFalse( dep_info1._local_path_info.IsPathInLocalPaths('path4')) dep_info1.Update(dep_info2) cs_info = dep_info1._cloud_storage_info self.assertEqual(cs_info, cs_info2) self.assertEqual('cs_bucket2', cs_info._cs_bucket) self.assertEqual('cs_hash2', cs_info._cs_hash) self.assertEqual('download_path2', cs_info._download_path) self.assertEqual('cs_remote_path2', cs_info._cs_remote_path) self.assertTrue(dep_info1._local_path_info.IsPathInLocalPaths('path1')) self.assertTrue(dep_info1._local_path_info.IsPathInLocalPaths('path2')) self.assertFalse( dep_info1._local_path_info.IsPathInLocalPaths('path3')) self.assertFalse( dep_info1._local_path_info.IsPathInLocalPaths('path4')) dep_info1.Update(dep_info3) cs_info = dep_info1._cloud_storage_info self.assertEqual(cs_info, cs_info2) self.assertEqual('cs_bucket2', cs_info._cs_bucket) self.assertEqual('cs_hash2', cs_info._cs_hash) self.assertEqual('download_path2', cs_info._download_path) self.assertEqual('cs_remote_path2', cs_info._cs_remote_path) self.assertTrue(dep_info1._local_path_info.IsPathInLocalPaths('path1')) self.assertTrue(dep_info1._local_path_info.IsPathInLocalPaths('path2')) self.assertTrue(dep_info1._local_path_info.IsPathInLocalPaths('path3')) self.assertFalse( dep_info1._local_path_info.IsPathInLocalPaths('path4')) self.assertRaises(ValueError, dep_info1.Update, dep_info4)