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:
data = s[:length]
f.write(data)
f.close()
+ return self.md5sum(path)
def md5sum(self, filename):
md5 = hashlib.md5()
"""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",
"""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",
"""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",
# 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",
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",
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")
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")
# 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",
# 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",
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)