Lines Matching refs:self
49 def _verify(self, zip_file, zip_file_name, arcname, expected_hash, argument
55 self.assertEqual(int(expected_stat.st_mode), int(new_stat.st_mode))
56 self.assertEqual(int(expected_stat.st_mtime), int(new_stat.st_mtime))
63 self.assertEqual(info.date_time, (2009, 1, 1, 0, 0, 0))
67 self.assertEqual(mode, expected_mode)
70 self.assertEqual(info.compress_type, expected_compress_type)
77 self.assertEqual(expected_hash, sha1_hash.hexdigest())
78 self.assertIsNone(zip_file.testzip())
80 def _test_ZipWrite(self, contents, extra_zipwrite_args=None): argument
113 self._verify(zip_file, zip_file_name, arcname, sha1_hash.hexdigest(),
120 def _test_ZipWriteStr(self, zinfo_or_arcname, contents, extra_args=None): argument
145 self._verify(zip_file, zip_file_name, arcname, sha1(contents).hexdigest(),
151 def _test_ZipWriteStr_large_file(self, large, small, extra_args=None): argument
188 self._verify(zip_file, zip_file_name, arcname_large,
193 self._verify(zip_file, zip_file_name, arcname_small,
200 def _test_reset_ZIP64_LIMIT(self, func, *args): argument
202 self.assertEqual(default_limit, zipfile.ZIP64_LIMIT)
204 self.assertEqual(default_limit, zipfile.ZIP64_LIMIT)
206 def test_ZipWrite(self): argument
208 self._test_ZipWrite(file_contents)
210 def test_ZipWrite_with_opts(self): argument
212 self._test_ZipWrite(file_contents, {
217 self._test_ZipWrite(file_contents, {
223 def test_ZipWrite_large_file(self): argument
225 self._test_ZipWrite(file_contents, {
229 def test_ZipWrite_resets_ZIP64_LIMIT(self): argument
230 self._test_reset_ZIP64_LIMIT(self._test_ZipWrite, "")
232 def test_ZipWriteStr(self): argument
235 self._test_ZipWriteStr("foo", random_string)
239 self._test_ZipWriteStr(zinfo, random_string)
243 self._test_ZipWriteStr(zinfo, random_string)
245 def test_ZipWriteStr_with_opts(self): argument
248 self._test_ZipWriteStr("foo", random_string, {
252 self._test_ZipWriteStr("bar", random_string, {
258 self._test_ZipWriteStr(zinfo, random_string, {
261 self._test_ZipWriteStr(zinfo, random_string, {
266 def test_ZipWriteStr_large_file(self): argument
272 self._test_ZipWriteStr_large_file(long_string, short_string, {
276 def test_ZipWriteStr_resets_ZIP64_LIMIT(self): argument
277 self._test_reset_ZIP64_LIMIT(self._test_ZipWriteStr, "foo", "")
279 self._test_reset_ZIP64_LIMIT(self._test_ZipWriteStr, zinfo, "")
281 def test_bug21309935(self): argument
303 self._verify(zip_file, zip_file_name, "foo",
306 self._verify(zip_file, zip_file_name, "bar",
309 self._verify(zip_file, zip_file_name, "baz",
312 self._verify(zip_file, zip_file_name, "qux",
318 def test_ZipDelete(self): argument
334 self.assertTrue('Test1' in entries)
335 self.assertFalse('Test2' in entries)
336 self.assertTrue('Test3' in entries)
338 self.assertRaises(
342 self.assertTrue('Test1' in entries)
343 self.assertFalse('Test2' in entries)
344 self.assertTrue('Test3' in entries)
349 self.assertTrue('Test1' in entries)
350 self.assertFalse('Test2' in entries)
351 self.assertFalse('Test3' in entries)
356 self.assertFalse('Test1' in entries)
357 self.assertFalse('Test2' in entries)
358 self.assertFalse('Test3' in entries)
379 def test_UnzipTemp(self): argument
380 zip_file = self._test_UnzipTemp_createZipFile()
382 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test1')))
383 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test2')))
384 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Foo3')))
385 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
386 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))
388 def test_UnzipTemp_withPatterns(self): argument
389 zip_file = self._test_UnzipTemp_createZipFile()
392 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test1')))
393 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Test2')))
394 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Foo3')))
395 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
396 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))
399 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test1')))
400 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Test2')))
401 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Foo3')))
402 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
403 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))
406 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test1')))
407 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test2')))
408 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Foo3')))
409 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
410 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))
413 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test1')))
414 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Test2')))
415 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Foo3')))
416 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
417 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))
419 def test_UnzipTemp_withEmptyPatterns(self): argument
420 zip_file = self._test_UnzipTemp_createZipFile()
422 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Test1')))
423 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Test2')))
424 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Foo3')))
425 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
426 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))
428 def test_UnzipTemp_withPartiallyMatchingPatterns(self): argument
429 zip_file = self._test_UnzipTemp_createZipFile()
431 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test1')))
432 self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Test2')))
433 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Foo3')))
434 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
435 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))
437 def test_UnzipTemp_withNoMatchingPatterns(self): argument
438 zip_file = self._test_UnzipTemp_createZipFile()
440 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Test1')))
441 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Test2')))
442 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Foo3')))
443 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
444 self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))
492 def setUp(self): argument
493 self.testdata_dir = test_utils.get_testdata_dir()
506 def test_ReadApkCerts_NoncompressedApks(self): argument
507 target_files = self._write_apkcerts_txt(self.APKCERTS_TXT1)
511 self.assertDictEqual(self.APKCERTS_CERTMAP1, certmap)
512 self.assertIsNone(ext)
514 def test_ReadApkCerts_CompressedApks(self): argument
517 target_files = self._write_apkcerts_txt(
518 self.APKCERTS_TXT2,
524 self.assertDictEqual(self.APKCERTS_CERTMAP2, certmap)
525 self.assertEqual('.gz', ext)
528 target_files = self._write_apkcerts_txt(
529 self.APKCERTS_TXT3, ['Compressed4.apk.xz'])
534 self.assertDictEqual(self.APKCERTS_CERTMAP3, certmap)
535 self.assertEqual('.xz', ext)
537 def test_ReadApkCerts_CompressedAndNoncompressedApks(self): argument
538 target_files = self._write_apkcerts_txt(
539 self.APKCERTS_TXT1 + self.APKCERTS_TXT2,
545 certmap_merged = self.APKCERTS_CERTMAP1.copy()
546 certmap_merged.update(self.APKCERTS_CERTMAP2)
547 self.assertDictEqual(certmap_merged, certmap)
548 self.assertEqual('.gz', ext)
550 def test_ReadApkCerts_MultipleCompressionMethods(self): argument
551 target_files = self._write_apkcerts_txt(
552 self.APKCERTS_TXT2 + self.APKCERTS_TXT3,
556 self.assertRaises(ValueError, common.ReadApkCerts, input_zip)
558 def test_ReadApkCerts_MismatchingKeys(self): argument
563 target_files = self._write_apkcerts_txt(malformed_apkcerts_txt)
566 self.assertRaises(ValueError, common.ReadApkCerts, input_zip)
568 def test_ExtractPublicKey(self): argument
569 cert = os.path.join(self.testdata_dir, 'testkey.x509.pem')
570 pubkey = os.path.join(self.testdata_dir, 'testkey.pubkey.pem')
572 self.assertEqual(pubkey_fp.read(), common.ExtractPublicKey(cert))
574 def test_ExtractPublicKey_invalidInput(self): argument
575 wrong_input = os.path.join(self.testdata_dir, 'testkey.pk8')
576 self.assertRaises(AssertionError, common.ExtractPublicKey, wrong_input)
578 def test_ExtractAvbPublicKey(self): argument
579 privkey = os.path.join(self.testdata_dir, 'testkey.key')
580 pubkey = os.path.join(self.testdata_dir, 'testkey.pubkey.pem')
583 self.assertEqual(privkey_fp.read(), pubkey_fp.read())
585 def test_ParseCertificate(self): argument
586 cert = os.path.join(self.testdata_dir, 'testkey.x509.pem')
591 self.assertEqual(0, proc.returncode)
595 self.assertEqual(expected, actual)
597 def test_GetMinSdkVersion(self): argument
598 test_app = os.path.join(self.testdata_dir, 'TestApp.apk')
599 self.assertEqual('24', common.GetMinSdkVersion(test_app))
601 def test_GetMinSdkVersion_invalidInput(self): argument
602 self.assertRaises(
605 def test_GetMinSdkVersionInt(self): argument
606 test_app = os.path.join(self.testdata_dir, 'TestApp.apk')
607 self.assertEqual(24, common.GetMinSdkVersionInt(test_app, {}))
609 def test_GetMinSdkVersionInt_invalidInput(self): argument
610 self.assertRaises(
617 def setUp(self): argument
618 self.testdata_dir = test_utils.get_testdata_dir()
620 def test_GetSparseImage_emptyBlockMapFile(self): argument
637 self.assertDictEqual(
644 def test_GetSparseImage_missingImageFile(self): argument
645 self.assertRaises(
646 AssertionError, common.GetSparseImage, 'system2', self.testdata_dir,
648 self.assertRaises(
649 AssertionError, common.GetSparseImage, 'unknown', self.testdata_dir,
652 def test_GetSparseImage_missingBlockMapFile(self): argument
666 self.assertRaises(
670 def test_GetSparseImage_sharedBlocks_notAllowed(self): argument
688 self.assertRaises(
692 def test_GetSparseImage_sharedBlocks_allowed(self): argument
713 self.assertDictEqual(
724 self.assertTrue(
726 self.assertNotIn(
730 self.assertFalse(sparse_image.file_map['__COPY'].extra)
731 self.assertFalse(sparse_image.file_map['__NONZERO-0'].extra)
732 self.assertFalse(sparse_image.file_map['/system/file1'].extra)
734 def test_GetSparseImage_incompleteRanges(self): argument
754 self.assertFalse(sparse_image.file_map['/system/file1'].extra)
755 self.assertTrue(sparse_image.file_map['/system/file2'].extra['incomplete'])
757 def test_GetSparseImage_systemRootImage_filenameWithExtraLeadingSlash(self): argument
779 self.assertFalse(sparse_image.file_map['//system/file1'].extra)
780 self.assertTrue(sparse_image.file_map['//system/file2'].extra['incomplete'])
781 self.assertTrue(
784 def test_GetSparseImage_systemRootImage_nonSystemFiles(self): argument
803 self.assertFalse(sparse_image.file_map['//system/file1'].extra)
804 self.assertTrue(sparse_image.file_map['//init.rc'].extra['incomplete'])
806 def test_GetSparseImage_fileNotFound(self): argument
821 self.assertRaises(
825 def test_GetAvbChainedPartitionArg(self): argument
826 pubkey = os.path.join(self.testdata_dir, 'testkey.pubkey.pem')
833 self.assertEqual(3, len(args))
834 self.assertEqual('system', args[0])
835 self.assertEqual('2', args[1])
836 self.assertTrue(os.path.exists(args[2]))
838 def test_GetAvbChainedPartitionArg_withPrivateKey(self): argument
839 key = os.path.join(self.testdata_dir, 'testkey.key')
846 self.assertEqual(3, len(args))
847 self.assertEqual('product', args[0])
848 self.assertEqual('2', args[1])
849 self.assertTrue(os.path.exists(args[2]))
851 def test_GetAvbChainedPartitionArg_withSpecifiedKey(self): argument
857 pubkey = os.path.join(self.testdata_dir, 'testkey.pubkey.pem')
860 self.assertEqual(3, len(args))
861 self.assertEqual('system', args[0])
862 self.assertEqual('2', args[1])
863 self.assertTrue(os.path.exists(args[2]))
865 def test_GetAvbChainedPartitionArg_invalidKey(self): argument
866 pubkey = os.path.join(self.testdata_dir, 'testkey_with_passwd.x509.pem')
872 self.assertRaises(
903 def test_LoadInfoDict(self): argument
904 target_files = self._test_LoadInfoDict_createTargetFiles(
905 self.INFO_DICT_DEFAULT,
909 self.assertEqual(3, loaded_dict['recovery_api_version'])
910 self.assertEqual(2, loaded_dict['fstab_version'])
911 self.assertIn('/', loaded_dict['fstab'])
912 self.assertIn('/system', loaded_dict['fstab'])
914 def test_LoadInfoDict_legacyRecoveryFstabPath(self): argument
915 target_files = self._test_LoadInfoDict_createTargetFiles(
916 self.INFO_DICT_DEFAULT,
920 self.assertEqual(3, loaded_dict['recovery_api_version'])
921 self.assertEqual(2, loaded_dict['fstab_version'])
922 self.assertIn('/', loaded_dict['fstab'])
923 self.assertIn('/system', loaded_dict['fstab'])
925 def test_LoadInfoDict_dirInput(self): argument
926 target_files = self._test_LoadInfoDict_createTargetFiles(
927 self.INFO_DICT_DEFAULT,
931 self.assertEqual(3, loaded_dict['recovery_api_version'])
932 self.assertEqual(2, loaded_dict['fstab_version'])
933 self.assertIn('/', loaded_dict['fstab'])
934 self.assertIn('/system', loaded_dict['fstab'])
936 def test_LoadInfoDict_dirInput_legacyRecoveryFstabPath(self): argument
937 target_files = self._test_LoadInfoDict_createTargetFiles(
938 self.INFO_DICT_DEFAULT,
942 self.assertEqual(3, loaded_dict['recovery_api_version'])
943 self.assertEqual(2, loaded_dict['fstab_version'])
944 self.assertIn('/', loaded_dict['fstab'])
945 self.assertIn('/system', loaded_dict['fstab'])
947 def test_LoadInfoDict_systemRootImageFalse(self): argument
950 info_dict = copy.copy(self.INFO_DICT_DEFAULT)
954 target_files = self._test_LoadInfoDict_createTargetFiles(
959 self.assertEqual(3, loaded_dict['recovery_api_version'])
960 self.assertEqual(2, loaded_dict['fstab_version'])
961 self.assertNotIn('/', loaded_dict['fstab'])
962 self.assertIn('/system', loaded_dict['fstab'])
964 def test_LoadInfoDict_recoveryAsBootFalse(self): argument
967 info_dict = copy.copy(self.INFO_DICT_DEFAULT)
970 target_files = self._test_LoadInfoDict_createTargetFiles(
975 self.assertEqual(3, loaded_dict['recovery_api_version'])
976 self.assertEqual(2, loaded_dict['fstab_version'])
977 self.assertIn('/', loaded_dict['fstab'])
978 self.assertIn('/system', loaded_dict['fstab'])
980 def test_LoadInfoDict_noRecoveryTrue(self): argument
982 info_dict = copy.copy(self.INFO_DICT_DEFAULT)
984 target_files = self._test_LoadInfoDict_createTargetFiles(
989 self.assertEqual(3, loaded_dict['recovery_api_version'])
990 self.assertEqual(2, loaded_dict['fstab_version'])
991 self.assertIsNone(loaded_dict['fstab'])
993 def test_LoadInfoDict_missingMetaMiscInfoTxt(self): argument
994 target_files = self._test_LoadInfoDict_createTargetFiles(
995 self.INFO_DICT_DEFAULT,
999 self.assertRaises(ValueError, common.LoadInfoDict, target_files_zip)
1001 def test_LoadInfoDict_repacking(self): argument
1002 target_files = self._test_LoadInfoDict_createTargetFiles(
1003 self.INFO_DICT_DEFAULT,
1007 self.assertEqual(3, loaded_dict['recovery_api_version'])
1008 self.assertEqual(2, loaded_dict['fstab_version'])
1009 self.assertIn('/', loaded_dict['fstab'])
1010 self.assertIn('/system', loaded_dict['fstab'])
1011 self.assertEqual(
1013 self.assertEqual(
1017 def test_LoadInfoDict_repackingWithZipFileInput(self): argument
1018 target_files = self._test_LoadInfoDict_createTargetFiles(
1019 self.INFO_DICT_DEFAULT,
1022 self.assertRaises(
1032 def setUp(self): argument
1033 self._tempdir = common.MakeTempDir()
1035 self._info = {"fstab" : {}}
1039 self._info["fstab"] = common.LoadRecoveryFSTab("\n".join, 2, dummy_fstab)
1041 self.recovery_data = bytearray([
1047 self.boot_data = bytearray([
1052 def _out_tmp_sink(self, name, data, prefix="SYSTEM"): argument
1053 loc = os.path.join(self._tempdir, prefix, name)
1059 def test_full_recovery(self): argument
1060 recovery_image = common.File("recovery.img", self.recovery_data)
1061 boot_image = common.File("boot.img", self.boot_data)
1062 self._info["full_recovery_image"] = "true"
1064 common.MakeRecoveryPatch(self._tempdir, self._out_tmp_sink,
1065 recovery_image, boot_image, self._info)
1066 validate_target_files.ValidateInstallRecoveryScript(self._tempdir,
1067 self._info)
1069 def test_recovery_from_boot(self): argument
1070 recovery_image = common.File("recovery.img", self.recovery_data)
1071 self._out_tmp_sink("recovery.img", recovery_image.data, "IMAGES")
1072 boot_image = common.File("boot.img", self.boot_data)
1073 self._out_tmp_sink("boot.img", boot_image.data, "IMAGES")
1075 common.MakeRecoveryPatch(self._tempdir, self._out_tmp_sink,
1076 recovery_image, boot_image, self._info)
1077 validate_target_files.ValidateInstallRecoveryScript(self._tempdir,
1078 self._info)
1080 self._out_tmp_sink("etc/recovery-resource.dat", "bonus", "SYSTEM")
1081 common.MakeRecoveryPatch(self._tempdir, self._out_tmp_sink,
1082 recovery_image, boot_image, self._info)
1083 validate_target_files.ValidateInstallRecoveryScript(self._tempdir,
1084 self._info)
1090 def __init__(self, enable_comments=False): argument
1091 self.lines = []
1092 self.enable_comments = enable_comments
1093 def Comment(self, comment): argument
1094 if self.enable_comments:
1095 self.lines.append("# {}".format(comment))
1096 def AppendExtra(self, extra): argument
1097 self.lines.append(extra)
1098 def __str__(self): argument
1099 return "\n".join(self.lines)
1103 def __init__(self, partition, tgt, src=None): argument
1104 self.partition = partition
1105 self.tgt = tgt
1106 self.src = src
1107 def WriteScript(self, script, _, progress=None, argument
1111 script.AppendExtra("patch({});".format(self.partition))
1113 self.WritePostInstallVerifyScript(script)
1114 def WritePostInstallVerifyScript(self, script): argument
1115 script.AppendExtra("verify({});".format(self.partition))
1119 def __init__(self, size): argument
1120 self.blocksize = 4096
1121 self.total_blocks = size // 4096
1133 def setUp(self): argument
1134 self.script = MockScriptWriter()
1135 self.output_path = common.MakeTempFile(suffix='.zip')
1137 def test_full(self): argument
1148 with zipfile.ZipFile(self.output_path, 'w') as output_zip:
1149 dp_diff.WriteScript(self.script, output_zip, write_verify_script=True)
1151 self.assertEqual(str(self.script).strip(), """
1161 lines = self.get_op_list(self.output_path)
1170 self.assertLess(remove_all_groups, add_group,
1172 self.assertLess(add_group, min(add_vendor, add_system),
1174 self.assertLess(add_system, resize_system,
1176 self.assertLess(add_vendor, resize_vendor,
1179 def test_inc_groups(self): argument
1196 with zipfile.ZipFile(self.output_path, 'w') as output_zip:
1197 dp_diff.WriteScript(self.script, output_zip, write_verify_script=True)
1199 lines = self.get_op_list(self.output_path)
1206 self.assertLess(max(removed, shrunk) < min(grown, added),
1210 def test_incremental(self): argument
1239 with zipfile.ZipFile(self.output_path, 'w') as output_zip:
1240 dp_diff.WriteScript(self.script, output_zip, write_verify_script=True)
1242 metadata_idx = self.script.lines.index(
1245 self.assertLess(self.script.lines.index('patch(vendor);'), metadata_idx)
1246 self.assertLess(metadata_idx, self.script.lines.index('verify(vendor);'))
1248 patch_idx = self.script.lines.index("patch({});".format(p))
1249 verify_idx = self.script.lines.index("verify({});".format(p))
1250 self.assertLess(metadata_idx, patch_idx,
1252 self.assertLess(patch_idx, verify_idx,
1255 self.assertNotIn("patch(product_services);", self.script.lines)
1257 lines = self.get_op_list(self.output_path)
1272 self.assertLess(max_idx_move_partition_out_foo, shrink_group,
1276 self.assertLess(add_group_bar, move_product_in,
1279 self.assertLess(max_idx_move_partition_out_foo,
1284 def test_remove_partition(self): argument
1310 with zipfile.ZipFile(self.output_path, 'w') as output_zip:
1311 dp_diff.WriteScript(self.script, output_zip, write_verify_script=True)
1313 self.assertNotIn("block_image_update", str(self.script),
1316 lines = self.get_op_list(self.output_path)
1317 self.assertEqual(lines, ["remove foo"])