From: Eduardo Robles Elvira Date: Thu, 20 Jun 2013 08:04:57 +0000 (+0200) Subject: beautifying test code a bit X-Git-Tag: v2.2~185 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=920e8c3afc2d591a55097ebe56700218002be6a1;p=python-delta-tar beautifying test code a bit --- diff --git a/testing/test_multivol.py b/testing/test_multivol.py index 6ace811..3dae89e 100644 --- a/testing/test_multivol.py +++ b/testing/test_multivol.py @@ -13,12 +13,7 @@ class MultivolTest(unittest.TestCase): def tearDown(self): os.system("rm -rf big small small2 sample.tar*") - def create_file(self, path, data): - f = open(path, 'w') - f.write(data) - f.close() - - def create_random_file(self, path, length): + def create_file(self, path, length): f = open(path, 'w') s = string.lowercase + string.digits + "\n" if len(s) < length: @@ -26,6 +21,7 @@ class MultivolTest(unittest.TestCase): data = s[:length] f.write(data) f.close() + return self.md5sum(path) def md5sum(self, filename): md5 = hashlib.md5() @@ -38,10 +34,7 @@ class MultivolTest(unittest.TestCase): """Test normal tarfile creation, no volumes """ # create the content of the file to compress and hash it - s = "hello" * 10000 - assert len(s) == 50000 - self.create_file("big", s) - hash = self.md5sum("big") + hash = self.create_file("big", 50000) # create the tar file with volumes tarobj = TarFile.open("sample.tar", @@ -65,10 +58,7 @@ class MultivolTest(unittest.TestCase): """Test volumes creation""" # create the content of the file to compress and hash it - s = "hello" * 10000 - assert len(s) == 50000 - self.create_file("big", s) - hash = self.md5sum("big") + hash = self.create_file("big", 50000) # create the tar file with volumes tarobj = TarFile.open("sample.tar", @@ -95,10 +85,7 @@ class MultivolTest(unittest.TestCase): """Test volumes creation with two volumes""" # create the content of the file to compress and hash it - s = "hello" * 10000 - assert len(s) == 50000 - self.create_file("big", s) - hash = self.md5sum("big") + hash = self.create_file("big", 50000) # create the tar file with volumes tarobj = TarFile.open("sample.tar", @@ -127,12 +114,9 @@ class MultivolTest(unittest.TestCase): # create sample data hash = dict() - self.create_random_file("big", 50000) - hash["big"] = self.md5sum("big") - self.create_random_file("small", 100) - hash["small"] = self.md5sum("small") - self.create_random_file("small2", 354) - hash["small2"] = self.md5sum("small2") + hash["big"] = self.create_file("big", 50000) + hash["small"] = self.create_file("small", 100) + hash["small2"] = self.create_file("small2", 354) # create the tar file with volumes tarobj = TarFile.open("sample.tar", @@ -165,8 +149,7 @@ class MultivolTest(unittest.TestCase): Create a volume and extract it ''' # create the content of the file to compress and hash it - self.create_random_file("big", 5*1024*1024) - hash = self.md5sum("big") + hash = self.create_file("big", 5*1024*1024) # create the tar file with volumes tarobj = TarFile.open("sample.tar", @@ -198,8 +181,7 @@ class MultivolTest(unittest.TestCase): Create a volume with gnu tar command and extract it with our tarfiel lib ''' # create the content of the file to compress and hash it - self.create_random_file("big", 5*1024*1024) - hash = self.md5sum("big") + hash = self.create_file("big", 5*1024*1024) # create the tar file with volumes os.system("tar cM -L 3M big --file=sample.tar --file=sample.tar.1") @@ -227,8 +209,7 @@ class MultivolTest(unittest.TestCase): Create a volume with gnu tar command and extract it with our tarfiel lib ''' # create the content of the file to compress and hash it - self.create_random_file("big", 5*1024*1024) - hash = self.md5sum("big") + hash = self.create_file("big", 5*1024*1024) # create the tar file with volumes os.system("tar cM -L 3M big --file=sample.tar --file=sample.tar.1") @@ -256,12 +237,9 @@ class MultivolTest(unittest.TestCase): # create sample data hash = dict() - self.create_random_file("big", 50000) - hash["big"] = self.md5sum("big") - self.create_random_file("small", 100) - hash["small"] = self.md5sum("small") - self.create_random_file("small2", 354) - hash["small2"] = self.md5sum("small2") + hash["big"] = self.create_file("big", 50000) + hash["small"] = self.create_file("small", 100) + hash["small2"] = self.create_file("small2", 354) # create the tar file with volumes tarobj = TarFile.open("sample.tar", @@ -299,12 +277,9 @@ class MultivolTest(unittest.TestCase): # create sample data hash = dict() - self.create_random_file("big", 50000) - hash["big"] = self.md5sum("big") - self.create_random_file("small", 100) - hash["small"] = self.md5sum("small") - self.create_random_file("small2", 354) - hash["small2"] = self.md5sum("small2") + hash["big"] = self.create_file("big", 50000) + hash["small"] = self.create_file("small", 100) + hash["small2"] = self.create_file("small2", 354) # create the tar file with volumes tarobj = TarFile.open("sample.tar", @@ -331,4 +306,4 @@ class MultivolTest(unittest.TestCase): for key, value in hash.iteritems(): assert os.path.exists(key) - assert value == self.md5sum(key) \ No newline at end of file + assert value == self.md5sum(key)