Beispiel #1
0
 def testReferenceCounting(self):
     """
     Make 3 resources with different names but same md5, ensure they are reference counted properly
     """
     res1 = Path('my.resource1.bin')
     res2 = Path('my.resource2.bin')
     res3 = Path('my.resource3.bin')
     for res in (res1, res2, res3):
         res.write_bytes('SOME NICE DATA')
     res1md5 = res1.md5
     res4 = Path('tmp/my.resource1.bin')
     if not res4.dirname().exists():
         res4.dirname().makedirs()
     res4.write_bytes('SOME *DIFFERENT* DATA')
     res4md5 = res4.md5
     res1, res2, res3, res4 = map(lambda f: Resource(self.package, f),
                                  (res1, res2, res3, res4))
     assert res1.storageName == 'my.resource1.bin', res1.storageName
     assert res2.storageName == 'my.resource1.bin', res2.storageName
     assert res3.storageName == 'my.resource1.bin', res3.storageName
     assert res4.storageName == 'my.resource1.1.bin', res4.storageName
     assert res4.userName == 'my.resource1.bin', res4.userName
     assert len(self.package.resources) == 2
     assert len(self.package.resources[res1.path.md5]) == 3
     assert len(self.package.resources[res4.path.md5]) == 1
     assert self.package.resources[res4md5][0] is res4
     # Now start deleting things
     res4path = Path(res4.path)
     assert res4path.exists()
     res4.delete()
     assert not res4path.exists()
     assert res4md5 not in self.package.resources
     assert not res4path.exists()
     res1path = Path(res1.path)
     assert res1path.exists()
     res2.delete()
     assert res1path.exists()
     assert res2 not in self.package.resources[res1md5]
     res1.delete()
     assert res1path.exists()
     assert res1 not in self.package.resources[res1md5]
     res3.delete()
     assert res1md5 not in self.package.resources
     assert not res1path.exists()
 def testReferenceCounting(self):
     """
     Make 3 resources with different names but same md5, ensure they are reference counted properly
     """
     res1 = Path('my.resource1.bin')
     res2 = Path('my.resource2.bin')
     res3 = Path('my.resource3.bin')
     for res in (res1, res2, res3):
         res.write_bytes('SOME NICE DATA')
     res1md5 = res1.md5
     res4 = Path('tmp/my.resource1.bin')
     if not res4.dirname().exists():
         res4.dirname().makedirs()
     res4.write_bytes('SOME *DIFFERENT* DATA')
     res4md5 = res4.md5
     res1, res2, res3, res4 = map(lambda f: Resource(self.package, f), (res1, res2, res3, res4))
     assert res1.storageName == 'my.resource1.bin', res1.storageName
     assert res2.storageName == 'my.resource1.bin', res2.storageName
     assert res3.storageName == 'my.resource1.bin', res3.storageName
     assert res4.storageName == 'my.resource1.1.bin', res4.storageName
     assert res4.userName == 'my.resource1.bin', res4.userName
     assert len(self.package.resources) == 2
     assert len(self.package.resources[res1.path.md5]) == 3
     assert len(self.package.resources[res4.path.md5]) == 1
     assert self.package.resources[res4md5][0] is res4
     # Now start deleting things
     res4path = Path(res4.path)
     assert res4path.exists()
     res4.delete()
     assert not res4path.exists()
     assert res4md5 not in self.package.resources
     assert not res4path.exists()
     res1path = Path(res1.path)
     assert res1path.exists()
     res2.delete()
     assert res1path.exists()
     assert res2 not in self.package.resources[res1md5]
     res1.delete()
     assert res1path.exists()
     assert res1 not in self.package.resources[res1md5]
     res3.delete()
     assert res1md5 not in self.package.resources
     assert not res1path.exists()