Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_extract_rar_basic(self):
test_file = self.get_test_loc('archive/rar/basic.rar')
test_dir = self.get_temp_dir()
archive.extract_rar(test_file, test_dir)
result = os.path.join(test_dir, 'd', 'b', 'a.txt')
assert os.path.exists(result)
def test_get_extractors(self):
test_data = [
('archive/zip/basic.zip', [archive.extract_zip]),
('archive/rar/basic.rar', [archive.extract_rar]),
('archive/deb/adduser_3.112ubuntu1_all.deb', [archive.extract_ar]),
('archive/cpio/elfinfo-1.0-1.fc9.src.cpio', [archive.extract_cpio]),
('archive/rpm/elfinfo-1.0-1.fc9.src.rpm', [archive.extract_rpm, archive.extract_cpio]),
('archive/gzip/file_4.26-1.diff.gz', [archive.uncompress_gzip]),
('archive/ar/liby.a', [archive.extract_ar]),
('archive/bz2/single_file_not_tarred.bz2', [archive.uncompress_bzip2]),
('archive/tar/tarred.tar', [archive.extract_tar]),
('archive/tbz/tarred_bzipped.bz', [archive.uncompress_bzip2]),
('archive/tbz/tarred_bzipped.tar.bz2', [archive.extract_tar]),
('archive/tbz/tarred_bzipped.tbz', [archive.extract_tar]),
('archive/tgz/tarred_gzipped.gz', [archive.uncompress_gzip]),
('archive/tgz/tarred_gzipped.tar.gz', [archive.extract_tar]),
('archive/tgz/tarred_gzipped.tgz', [archive.extract_tar]),
('archive/7z/z.7z', [archive.extract_7z]),
('archive/Z/tr2tex.Z', [archive.extract_Z, ]),
('archive/Z/tkWWW-0.11.tar.Z', [archive.extract_Z, archive.extract_tar]),
def test_extract_rar_broken(self):
test_file = self.get_test_loc('archive/rar/broken.rar')
test_dir = self.get_temp_dir()
expected = Exception('Unknown extraction error')
self.assertRaisesInstance(expected, archive.extract_rar, test_file, test_dir)
def test_get_extractor_cbr(self):
test_file = self.get_test_loc('archive/cbr/t.cbr')
result = archive.get_extractor(test_file)
expected = archive.extract_rar
assert expected == result
def test_extract_rar_with_absolute_path(self):
# FIXME: this file may not have a real absolute path
assert not os.path.exists('/home/li/Desktop/zip_folder')
test_file = self.get_test_loc('archive/rar/rar_absolute.rar', copy=True)
test_dir = self.get_temp_dir()
archive.extract_rar(test_file, test_dir)
assert not os.path.exists('/home/li/Desktop/absolute_folder')
result = os.path.join(test_dir, 'home/li/Desktop',
'absolute_folder/absolute_file')
assert os.path.exists(result)
def test_extract_rar_with_trailing_data(self):
test_file = self.get_test_loc('archive/rar/rar_trailing.rar')
test_dir = self.get_temp_dir()
Exception('Unknown extraction error')
archive.extract_rar(test_file, test_dir)
result = os.path.join(test_dir, 'd', 'b', 'a.txt')
assert os.path.exists(result)
def test_extract_rar_with_invalid_path(self):
test_file = self.get_test_loc('archive/rar/rar_invalidpath.rar')
test_dir = self.get_temp_dir()
archive.extract_rar(test_file, test_dir)
result = os.path.join(test_dir, 'this/that')
assert os.path.exists(result)
def test_extract_rar_with_relative_path(self):
# FIXME: this file may not have a real relative path
test_file = self.get_test_loc('archive/rar/rar_relative.rar', copy=True)
test_dir = self.get_temp_dir()
archive.extract_rar(test_file, test_dir)
result = os.path.abspath(test_file + '/../a_parent_folder.txt')
assert not os.path.exists(result)
result = os.path.join(test_dir, '2folder/relative_file')
assert os.path.exists(result)
result = os.path.join(test_dir, '2folder/3folder/relative_file')
assert os.path.exists(result)