def testStoreAndGetManifest(self): manifestsRootDir = os.path.join(ASSETS_DIR, "manifests") mm = ManifestRepository(manifestsRootDir) manifest1 = Manifest([r'somepath\myinclude.h'], { "fdde59862785f9f0ad6e661b9b5746b7": "a649723940dc975ebd17167d29a532f8" }) manifest2 = Manifest([r'somepath\myinclude.h', 'moreincludes.h'], { "474e7fc26a592d84dfa7416c10f036c6": "8771d7ebcf6c8bd57a3d6485f63e3a89" }) ms1 = mm.section("8a33738d88be7edbacef48e262bbb5bc") ms2 = mm.section("0623305942d216c165970948424ae7d1") ms1.setManifest("8a33738d88be7edbacef48e262bbb5bc", manifest1) ms2.setManifest("0623305942d216c165970948424ae7d1", manifest2) retrieved1 = ms1.getManifest("8a33738d88be7edbacef48e262bbb5bc") self.assertIsNotNone(retrieved1) self.assertEqual(retrieved1.includesContentToObjectMap["fdde59862785f9f0ad6e661b9b5746b7"], "a649723940dc975ebd17167d29a532f8") retrieved2 = ms2.getManifest("0623305942d216c165970948424ae7d1") self.assertIsNotNone(retrieved2) self.assertEqual(retrieved2.includesContentToObjectMap["474e7fc26a592d84dfa7416c10f036c6"], "8771d7ebcf6c8bd57a3d6485f63e3a89")
def testPaths(self): manifestsRootDir = os.path.join(ASSETS_DIR, "manifests") mm = ManifestRepository(manifestsRootDir) ms = mm.section("fdde59862785f9f0ad6e661b9b5746b7") self.assertEqual(ms.manifestSectionDir, os.path.join(manifestsRootDir, "fd")) self.assertEqual(ms.manifestPath("fdde59862785f9f0ad6e661b9b5746b7"), os.path.join(manifestsRootDir, "fd", "fdde59862785f9f0ad6e661b9b5746b7.json"))
def testClean(self): manifestsRootDir = os.path.join(ASSETS_DIR, "manifests") mm = ManifestRepository(manifestsRootDir) mm.section("8a33738d88be7edbacef48e262bbb5bc").setManifest("8a33738d88be7edbacef48e262bbb5bc", TestManifestRepository.manifest1) mm.section("0623305942d216c165970948424ae7d1").setManifest("0623305942d216c165970948424ae7d1", TestManifestRepository.manifest2) cleaningResultSize = mm.clean(240) # Only one of those manifests can be left self.assertLessEqual(cleaningResultSize, 240) self.assertLessEqual(self._getDirectorySize(manifestsRootDir), 240) cleaningResultSize = mm.clean(240) # The one remaining is remains alive self.assertLessEqual(cleaningResultSize, 240) self.assertGreaterEqual(cleaningResultSize, 120) self.assertLessEqual(self._getDirectorySize(manifestsRootDir), 240) self.assertGreaterEqual(self._getDirectorySize(manifestsRootDir), 120) cleaningResultSize = mm.clean(0) # All manifest are gone self.assertEqual(cleaningResultSize, 0) self.assertEqual(self._getDirectorySize(manifestsRootDir), 0)
def testStoreAndGetManifest(self): manifestsRootDir = os.path.join(ASSETS_DIR, "manifests") mm = ManifestRepository(manifestsRootDir) ms1 = mm.section("8a33738d88be7edbacef48e262bbb5bc") ms2 = mm.section("0623305942d216c165970948424ae7d1") ms1.setManifest("8a33738d88be7edbacef48e262bbb5bc", TestManifestRepository.manifest1) ms2.setManifest("0623305942d216c165970948424ae7d1", TestManifestRepository.manifest2) retrieved1 = ms1.getManifest("8a33738d88be7edbacef48e262bbb5bc") self.assertIsNotNone(retrieved1) retrieved1Entry = retrieved1.entries()[0] self.assertEqual(retrieved1Entry, TestManifestRepository.entry1) retrieved2 = ms2.getManifest("0623305942d216c165970948424ae7d1") self.assertIsNotNone(retrieved2) retrieved2Entry = retrieved2.entries()[0] self.assertEqual(retrieved2Entry, TestManifestRepository.entry2)
def testStoreAndGetManifest(self): with tempfile.TemporaryDirectory() as manifestsRootDir: mm = ManifestRepository(manifestsRootDir) ms1 = mm.section("8a33738d88be7edbacef48e262bbb5bc") ms2 = mm.section("0623305942d216c165970948424ae7d1") ms1.setManifest("8a33738d88be7edbacef48e262bbb5bc", TestManifestRepository.manifest1) ms2.setManifest("0623305942d216c165970948424ae7d1", TestManifestRepository.manifest2) retrieved1 = ms1.getManifest("8a33738d88be7edbacef48e262bbb5bc") self.assertIsNotNone(retrieved1) retrieved1Entry = retrieved1.entries()[0] self.assertEqual(retrieved1Entry, TestManifestRepository.entry1) retrieved2 = ms2.getManifest("0623305942d216c165970948424ae7d1") self.assertIsNotNone(retrieved2) retrieved2Entry = retrieved2.entries()[0] self.assertEqual(retrieved2Entry, TestManifestRepository.entry2)
def testClean(self): manifestsRootDir = os.path.join(ASSETS_DIR, "manifests") mm = ManifestRepository(manifestsRootDir) # Size in (120, 240] bytes manifest1 = Manifest([r'somepath\myinclude.h'], { "fdde59862785f9f0ad6e661b9b5746b7": "a649723940dc975ebd17167d29a532f8" }) # Size in (120, 240] bytes manifest2 = Manifest([r'somepath\myinclude.h', 'moreincludes.h'], { "474e7fc26a592d84dfa7416c10f036c6": "8771d7ebcf6c8bd57a3d6485f63e3a89" }) mm.section("8a33738d88be7edbacef48e262bbb5bc").setManifest("8a33738d88be7edbacef48e262bbb5bc", manifest1) mm.section("0623305942d216c165970948424ae7d1").setManifest("0623305942d216c165970948424ae7d1", manifest2) cleaningResultSize = mm.clean(240) # Only one of those manifests can be left self.assertLessEqual(cleaningResultSize, 240) self.assertLessEqual(self._getDirectorySize(manifestsRootDir), 240) cleaningResultSize = mm.clean(240) # The one remaining is remains alive self.assertLessEqual(cleaningResultSize, 240) self.assertGreaterEqual(cleaningResultSize, 120) self.assertLessEqual(self._getDirectorySize(manifestsRootDir), 240) self.assertGreaterEqual(self._getDirectorySize(manifestsRootDir), 120) cleaningResultSize = mm.clean(0) # All manifest are gone self.assertEqual(cleaningResultSize, 0) self.assertEqual(self._getDirectorySize(manifestsRootDir), 0)
def testNonExistingManifest(self): manifestsRootDir = os.path.join(ASSETS_DIR, "manifests") mm = ManifestRepository(manifestsRootDir) retrieved = mm.section("ffffffffffffffffffffffffffffffff").getManifest("ffffffffffffffffffffffffffffffff") self.assertIsNone(retrieved)
def testIncludesContentHash(self): self.assertEqual( ManifestRepository.getIncludesContentHashForHashes([]), ManifestRepository.getIncludesContentHashForHashes([]) ) self.assertEqual( ManifestRepository.getIncludesContentHashForHashes(["d88be7edbf"]), ManifestRepository.getIncludesContentHashForHashes(["d88be7edbf"]) ) self.assertEqual( ManifestRepository.getIncludesContentHashForHashes(["d88be7edbf", "f6c8bd5733"]), ManifestRepository.getIncludesContentHashForHashes(["d88be7edbf", "f6c8bd5733"]) ) # Wrong number of elements self.assertNotEqual( ManifestRepository.getIncludesContentHashForHashes([]), ManifestRepository.getIncludesContentHashForHashes(["d88be7edbf"]) ) # Wrong order self.assertNotEqual( ManifestRepository.getIncludesContentHashForHashes(["d88be7edbf", "f6c8bd5733"]), ManifestRepository.getIncludesContentHashForHashes(["f6c8bd5733", "d88be7edbf"]) ) # Content in different elements self.assertNotEqual( ManifestRepository.getIncludesContentHashForHashes(["", "d88be7edbf"]), ManifestRepository.getIncludesContentHashForHashes(["d88be7edbf", ""]) ) self.assertNotEqual( ManifestRepository.getIncludesContentHashForHashes(["d88be", "7edbf"]), ManifestRepository.getIncludesContentHashForHashes(["d88b", "e7edbf"]) )
def testBrokenManifest(self): manifestsRootDir = os.path.join(ASSETS_DIR, "manifests") mm = ManifestRepository(manifestsRootDir) retrieved = mm.section("brokenmanifest").getManifest("brokenmanifest") self.assertIsNone(retrieved)