Пример #1
0
 def test_extract_archive_fails_on_nonexisting_file(self):
     with self.assertRaises(ExtractError) as ctx:
         Extract.extract_archive(archive_path=os.path.join(
             TestExtract.temp_dir, "no_file"),
                                 out_dir_path=TestExtract.temp_dir)
     self.assertTrue(
         str(ctx.exception).startswith("Path is not a valid archive"))
Пример #2
0
 def test_extract_archive_overwrites_existing(self):
     path = os.path.join(TestExtract.temp_dir, "file")
     with open(path, "w") as f:
         f.write("Dummy file")
     Extract.extract_archive(archive_path=TestExtract.ar_zip,
                             out_dir_path=TestExtract.temp_dir)
     self._assert_extracted_files(TestExtract.temp_dir)
Пример #3
0
 def test_extract_archive_fails_on_bad_file(self):
     path = os.path.join(TestExtract.temp_dir, "bad_file")
     with open(path, 'wb') as f:
         f.write(bytearray(os.urandom(100)))
     self.assertTrue(os.path.isfile(path))
     with self.assertRaises(ExtractError) as ctx:
         Extract.extract_archive(archive_path=path,
                                 out_dir_path=TestExtract.temp_dir)
     self.assertTrue(
         str(ctx.exception).startswith("Path is not a valid archive"))
Пример #4
0
    def test_is_archive_fast(self):
        self.assertTrue(Extract.is_archive_fast("a.zip"))
        self.assertTrue(Extract.is_archive_fast("b.rar"))
        self.assertTrue(Extract.is_archive_fast("c.bz2"))
        self.assertTrue(Extract.is_archive_fast("d.tar.gz"))
        self.assertTrue(Extract.is_archive_fast("e.7z"))

        self.assertFalse(Extract.is_archive_fast("a"))
        self.assertFalse(Extract.is_archive_fast("a.b"))
        self.assertFalse(Extract.is_archive_fast(".b"))
        self.assertFalse(Extract.is_archive_fast(".zip"))
        self.assertFalse(Extract.is_archive_fast(""))
        self.assertFalse(Extract.is_archive_fast("7"))
        self.assertFalse(Extract.is_archive_fast("z"))
Пример #5
0
 def test_extract_archive_tar_gz(self):
     Extract.extract_archive(archive_path=TestExtract.ar_tar_gz,
                             out_dir_path=TestExtract.temp_dir)
     self._assert_extracted_files(TestExtract.temp_dir)
Пример #6
0
 def test_extract_archive_rar_split(self):
     Extract.extract_archive(archive_path=TestExtract.ar_rar_split_p1,
                             out_dir_path=TestExtract.temp_dir)
     self._assert_extracted_files(TestExtract.temp_dir)
Пример #7
0
 def test_extract_archive_creates_sub_directories(self):
     out_path = os.path.join(TestExtract.temp_dir, "bunch", "of", "sub",
                             "dir")
     Extract.extract_archive(archive_path=TestExtract.ar_rar,
                             out_dir_path=out_path)
     self._assert_extracted_files(out_path)
Пример #8
0
 def test_extract_archive_fails_on_dir(self):
     with self.assertRaises(ExtractError) as ctx:
         Extract.extract_archive(archive_path=TestExtract.temp_dir,
                                 out_dir_path=TestExtract.temp_dir)
     self.assertTrue(
         str(ctx.exception).startswith("Path is not a valid archive"))
Пример #9
0
 def test_is_archive_tar_gz(self):
     self.assertTrue(Extract.is_archive(TestExtract.ar_tar_gz))
Пример #10
0
 def test_is_archive_rar(self):
     self.assertTrue(Extract.is_archive(TestExtract.ar_rar))
Пример #11
0
 def test_is_archive_rar_split(self):
     self.assertTrue(Extract.is_archive(TestExtract.ar_rar_split_p1))
     self.assertTrue(Extract.is_archive(TestExtract.ar_rar_split_p2))
Пример #12
0
 def test_is_archive_zip(self):
     self.assertTrue(Extract.is_archive(TestExtract.ar_zip))
Пример #13
0
 def test_is_archive_false_on_bad_archive(self):
     path = os.path.join(TestExtract.temp_dir, "bad_file")
     with open(path, 'wb') as f:
         f.write(bytearray(os.urandom(100)))
     self.assertTrue(os.path.isfile(path))
     self.assertFalse(Extract.is_archive(path))
Пример #14
0
 def test_is_archive_false_on_dir(self):
     path = os.path.join(TestExtract.temp_dir, "dir")
     os.mkdir(path)
     self.assertTrue(os.path.isdir(path))
     self.assertFalse(Extract.is_archive(path))
Пример #15
0
 def test_is_archive_false_on_nonexisting_file(self):
     self.assertFalse(
         Extract.is_archive(os.path.join(TestExtract.temp_dir, "no_file")))
Пример #16
0
 def test_is_archive_fast_works_with_full_paths(self):
     self.assertTrue(Extract.is_archive_fast("/full/path/a.zip"))
     self.assertFalse(Extract.is_archive_fast("/full/path/a"))
     self.assertFalse(Extract.is_archive_fast("/full/path/.zip"))