def testExtractTo(self): flist = filelist.FileList() tf = filelist_test.TempFileSystem() tf.Clear() tf.Make() flist.AddFile(tf.root_in_tmp, tf.test_txt) flist.AddSymLink(tf.root_in_tmp, tf.sym_dir) bundle_zip = os.path.join(tf.root_tmp, 'bundle.zip') car = cobalt_archive.CobaltArchive(bundle_zip) car.MakeArchive(platform_name='fake', platform_sdk_version='fake_sdk', config='devel', file_list=flist) out_dir = os.path.join(tf.root_tmp, 'out') car.ExtractTo(out_dir) out_from_dir = os.path.join(out_dir, 'from_dir') out_from_dir_lnk = os.path.join(out_dir, 'from_dir_lnk') self.assertEqual(filelist.GetFileType(out_from_dir), filelist.TYPE_DIRECTORY) self.assertEqual(filelist.GetFileType(out_from_dir_lnk), filelist.TYPE_SYMLINK_DIR) resolved_from_link_path = os.path.join( out_dir, port_symlink.ReadSymLink(out_from_dir_lnk)) self.assertEqual(os.path.abspath(out_from_dir), os.path.abspath(resolved_from_link_path))
def testMakesDeployInfo(self): flist = filelist.FileList() tf = filelist_test.TempFileSystem() tf.Clear() tf.Make() bundle_zip = os.path.join(tf.root_tmp, 'bundle.zip') car = cobalt_archive.CobaltArchive(bundle_zip) car.MakeArchive(platform_name='fake', platform_sdk_version='fake_sdk', config='devel', file_list=flist) out_dir = os.path.join(tf.root_tmp, 'out') car.ExtractTo(out_dir) out_metadata_file = os.path.join(out_dir, cobalt_archive._OUT_METADATA_PATH) self.assertEqual(filelist.GetFileType(out_metadata_file), filelist.TYPE_FILE) with open(out_metadata_file) as fd: text = fd.read() js = json.loads(text) self.assertTrue(js) self.assertEqual(js['sdk_version'], 'fake_sdk') self.assertEqual(js['platform'], 'fake') self.assertEqual(js['config'], 'devel')
def testTempFileSystem(self): """Sanity test to ensure TempFileSystem works correctly on the platform.""" tf = TempFileSystem() tf.Clear() self.assertEqual(filelist.GetFileType(tf.sym_dir), filelist.TYPE_NONE) self.assertEqual(filelist.GetFileType(tf.root_tmp), filelist.TYPE_NONE) self.assertEqual(filelist.GetFileType(tf.root_in_tmp), filelist.TYPE_NONE) self.assertEqual(filelist.GetFileType(tf.from_dir), filelist.TYPE_NONE) self.assertEqual(filelist.GetFileType(tf.test_txt), filelist.TYPE_NONE) tf.Make() self.assertEqual(filelist.GetFileType(tf.sym_dir), filelist.TYPE_SYMLINK_DIR) self.assertEqual(filelist.GetFileType(tf.root_tmp), filelist.TYPE_DIRECTORY) self.assertEqual(filelist.GetFileType(tf.root_in_tmp), filelist.TYPE_DIRECTORY) self.assertEqual(filelist.GetFileType(tf.from_dir), filelist.TYPE_DIRECTORY) self.assertEqual(filelist.GetFileType(tf.test_txt), filelist.TYPE_FILE) tf.Clear() self.assertEqual(filelist.GetFileType(tf.sym_dir), filelist.TYPE_NONE) self.assertEqual(filelist.GetFileType(tf.root_tmp), filelist.TYPE_NONE) self.assertEqual(filelist.GetFileType(tf.root_in_tmp), filelist.TYPE_NONE) self.assertEqual(filelist.GetFileType(tf.from_dir), filelist.TYPE_NONE) self.assertEqual(filelist.GetFileType(tf.test_txt), filelist.TYPE_NONE)
def P(f): t = filelist.GetFileType(f) print '{:<13} {}'.format(t, f)