Example #1
0
 def test_zip_file(self, workdir):
     # make sure we can zip single files
     workdir.join("sample_dir").mkdir()
     sample_file = workdir.join("sample_dir").join("sample.txt")
     sample_file.write("A sample")
     result_path = zip(str(sample_file))
     assert zipfile.is_zipfile(result_path)
Example #2
0
 def test_zip_file(self):
     # make sure we can zip single files
     new_dir = os.path.join(self.workdir, 'sampledir')
     os.mkdir(new_dir)
     sample_file = os.path.join(new_dir, 'sample.txt')
     open(sample_file, 'wb').write('A sample')
     self.resultpath = zip(sample_file)
     assert zipfile.is_zipfile(self.resultpath)
Example #3
0
 def process(self, path, metadata):
     if os.path.isfile(path):
         basename = os.path.basename(path)
     path = os.path.dirname(path)
     zip_file = zip(path)
     shutil.rmtree(path)
     result_path = os.path.join(
         os.path.dirname(zip_file), basename + '.zip')
     os.rename(zip_file, result_path)
     return result_path, metadata
Example #4
0
 def process(self, path, metadata):
     if os.path.isfile(path):
         basename = os.path.basename(path)
     path = os.path.dirname(path)
     zip_file = zip(path)
     shutil.rmtree(path)
     result_path = os.path.join(os.path.dirname(zip_file),
                                basename + '.zip')
     os.rename(zip_file, result_path)
     return result_path, metadata
Example #5
0
 def test_zip_dir(self, workdir):
     # make sure we can zip complete dir trees
     dir_to_zip = workdir / "src"
     dir_to_zip.join("subdir1").mkdir()
     dir_to_zip.join("subdir2").mkdir().join("subdir21").mkdir()
     dir_to_zip.join("subdir2").join("sample.txt").write("A sample")
     result_path = zip(str(dir_to_zip))
     zip_file = zipfile.ZipFile(result_path, 'r')
     result = sorted(zip_file.namelist())
     assert sorted(result) == [
         'sample.txt', 'subdir1/',
         'subdir2/', 'subdir2/sample.txt', 'subdir2/subdir21/']
     assert zip_file.testzip() is None
Example #6
0
 def test_zip_dir(self):
     # make sure we can zip complete dir trees
     new_dir = os.path.join(self.workdir, 'sampledir')
     os.mkdir(new_dir)
     os.mkdir(os.path.join(new_dir, 'subdir1'))
     os.mkdir(os.path.join(new_dir, 'subdir2'))
     os.mkdir(os.path.join(new_dir, 'subdir2', 'subdir21'))
     sample_file = os.path.join(new_dir, 'subdir2', 'sample.txt')
     open(sample_file, 'wb').write('A sample')
     self.resultpath = zip(new_dir)
     zip_file = zipfile.ZipFile(self.resultpath, 'r')
     result = sorted(zip_file.namelist())
     assert sorted(result) == [
         'subdir1/', 'subdir2/', 'subdir2/sample.txt', 'subdir2/subdir21/']
     assert zip_file.testzip() is None
Example #7
0
 def test_zip_invalid_path(self):
     # we get a ValueError if zip path is not valid
     with pytest.raises(ValueError) as why:
         zip("not-a-valid-path")
     assert why.type == ValueError