Beispiel #1
0
 def test_one_directory_with_files(self):
   from detail.archive import ZipArchive
   from detail.archive import Archive
   arch = ZipArchive(
       os.path.join(test_dir_path, 'one directory with files.zip')
   )
   top_file, top_dir = Archive.check_has_only_one_top(arch.raw_namelist())
   self.assertEqual(top_file, '')
   self.assertEqual(top_dir, 'dir', arch.raw_namelist())
   self.assertEqual(arch.separate_directory, '')
   self.assertEqual(
       arch.namelist(),
       [
           'dir/',
           'dir/a.txt',
           'dir/b.txt',
           'dir/c.txt',
           'dir/d.txt',
           'dir/e.txt'
       ]
   )
   arch.extractall(self.temp_path)
   result_struct = [x for x in os.walk(self.temp_path)]
   result_struct[1][2].sort()
       # may be not sorted for some reason (found on drone.io server)
   self.assertEqual(
       result_struct,
       [
           ('./__tmp_testing__', ['dir'], []),
           (
               './__tmp_testing__/dir',
               [],
               ['a.txt', 'b.txt', 'c.txt', 'd.txt', 'e.txt']
           )
       ]
   )
Beispiel #2
0
 def test_one_top(self):
   from detail.archive import Archive
   self.assertEqual(Archive.check_has_only_one_top(['a.txt']), ('a.txt', ''))
   self.assertEqual(
       Archive.check_has_only_one_top(['a/', 'a/b.txt']),
       ('', 'a')
   )
   self.assertEqual(
       Archive.check_has_only_one_top(['./a/', 'a/']),
       ('', 'a')
   )
   self.assertEqual(
       Archive.check_has_only_one_top(['a/', 'a/b.txt', 'a/x.txt']),
       ('', 'a')
   )
   self.assertEqual(
       Archive.check_has_only_one_top(['a/x.txt', 'a/b.txt', 'a/']),
       ('', 'a')
   )
   self.assertEqual(
       Archive.check_has_only_one_top([
           'dir/',
           'dir/a.txt',
           'dir/b.txt',
           'dir/c.txt',
           'dir/d.txt',
           'dir/e.txt'
       ]),
       ('', 'dir')
   )
   self.assertEqual(
       Archive.check_has_only_one_top(['a/', 'b/']),
       ('', '')
   )
   self.assertEqual(
       Archive.check_has_only_one_top(['a.txt', 'b.txt']),
       ('', '')
   )
   self.assertEqual(
       Archive.check_has_only_one_top(['a/', 'b.txt']),
       ('b.txt', 'a')
   )
   self.assertEqual(
       Archive.check_has_only_one_top(['a/', 'abc/b.txt']),
       ('', '')
   )
   self.assertEqual(
       Archive.check_has_only_one_top(['a/', 'b/b.txt', 'a/x.txt']),
       ('', '')
   )