def test_corrupted_create(self): tmpdir = tempfile.mkdtemp() LibArchive.extract(self.testcontainer, container(self.corruptedarchivepath).archive, tmpdir) fs = FileSystem() path1 = tmpdir checked = DirectoryTree(tmpdir, fs) checked.add(path1, True) corrupted2archivepath = os.path.join(tmpdir, 'corrupted2.tar') LibArchive.create(fs, corrupted2archivepath, checked) self.assertTrue(os.path.exists(corrupted2archivepath)) corrupted2archive = LibArchive(corrupted2archivepath) self.assertEqual(len(corrupted2archive.tree.root.children), 0) # clean up for root, dirs, files in os.walk(tmpdir, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) os.rmdir(tmpdir)
def test_create_utf8(self): tmpdir = tempfile.mkdtemp() testarchivepath = os.path.join(self.testdirectory, 'testdata', 'tešt.tar') LibArchive.extract(self.testcontainer, container(testarchivepath).archive, tmpdir) path1 = os.path.join(tmpdir, 'tarmanš.log') fs = FileSystem() checked = DirectoryTree(tmpdir, fs) checked.add(path1, False) testdata2archivepath = os.path.join(tmpdir, 'tešt2.tar') LibArchive.create(fs, testdata2archivepath, checked) self.assertTrue(os.path.exists(testdata2archivepath)) testdata2archive = LibArchive(testdata2archivepath) apath1 = os.path.join(testdata2archivepath, 'tarmanš.log') self.assertIn(apath1, testdata2archive.tree) # clean up for root, dirs, files in os.walk(tmpdir, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) os.rmdir(tmpdir)
def test_create(self): testdatadirectory = os.path.join(self.testdirectory, 'testdata', 'testdata') path1 = os.path.join(testdatadirectory, 'a', 'aa', 'aaa') path2 = os.path.join(testdatadirectory, 'c') path3 = os.path.join(testdatadirectory, 'a', 'ab') fs = FileSystem() checked = DirectoryTree(testdatadirectory, fs) checked.add(path1, False) checked.add(path2, False) checked.add(path3, True) tmpdir = tempfile.mkdtemp() testdata2archivepath = os.path.join(tmpdir, 'testdata2.tar.gz') LibArchive.create(fs, testdata2archivepath, checked) self.assertTrue(os.path.exists(testdata2archivepath)) testdata2archive = LibArchive(testdata2archivepath) apath1 = os.path.join(testdata2archivepath, 'a', 'aa', 'aaa') apath2 = os.path.join(testdata2archivepath, 'c') apath3 = os.path.join(testdata2archivepath, 'a', 'ab') self.assertIn(apath1, testdata2archive.tree) self.assertIn(apath2, testdata2archive.tree) self.assertIn(apath3, testdata2archive.tree) os.remove(testdata2archivepath) os.rmdir(tmpdir)
def test_create_utf8(self): tmpdir = tempfile.mkdtemp() testarchivepath = os.path.join( self.testdirectory, 'testdata', 'tešt.tar' ) LibArchive.extract( self.testcontainer, container(testarchivepath).archive, tmpdir ) path1 = os.path.join(tmpdir, 'tarmanš.log') fs = FileSystem() checked = DirectoryTree( tmpdir, fs ) checked.add(path1, False) testdata2archivepath = os.path.join( tmpdir, 'tešt2.tar' ) LibArchive.create( fs, testdata2archivepath, checked ) self.assertTrue(os.path.exists(testdata2archivepath)) testdata2archive = LibArchive(testdata2archivepath) apath1 = os.path.join(testdata2archivepath, 'tarmanš.log') self.assertIn(apath1, testdata2archive.tree) # clean up for root, dirs, files in os.walk(tmpdir, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) os.rmdir(tmpdir)
def test_corrupted_create(self): tmpdir = tempfile.mkdtemp() LibArchive.extract( self.testcontainer, container(self.corruptedarchivepath).archive, tmpdir ) fs = FileSystem() path1 = tmpdir checked = DirectoryTree( tmpdir, fs ) checked.add(path1, True) corrupted2archivepath = os.path.join( tmpdir, 'corrupted2.tar' ) LibArchive.create( fs, corrupted2archivepath, checked ) self.assertTrue(os.path.exists(corrupted2archivepath)) corrupted2archive = LibArchive(corrupted2archivepath) self.assertEqual(len(corrupted2archive.tree.root.children), 0) # clean up for root, dirs, files in os.walk(tmpdir, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) os.rmdir(tmpdir)
def test_create(self): testdatadirectory = os.path.join( self.testdirectory, 'testdata', 'testdata' ) path1 = os.path.join(testdatadirectory, 'a', 'aa', 'aaa') path2 = os.path.join(testdatadirectory, 'c') path3 = os.path.join(testdatadirectory, 'a', 'ab') fs = FileSystem() checked = DirectoryTree( testdatadirectory, fs ) checked.add(path1, False) checked.add(path2, False) checked.add(path3, True) tmpdir = tempfile.mkdtemp() testdata2archivepath = os.path.join( tmpdir, 'testdata2.tar.gz' ) LibArchive.create( fs, testdata2archivepath, checked ) self.assertTrue(os.path.exists(testdata2archivepath)) testdata2archive = LibArchive(testdata2archivepath) apath1 = os.path.join(testdata2archivepath, 'a', 'aa', 'aaa') apath2 = os.path.join(testdata2archivepath, 'c') apath3 = os.path.join(testdata2archivepath, 'a', 'ab') self.assertIn(apath1, testdata2archive.tree) self.assertIn(apath2, testdata2archive.tree) self.assertIn(apath3, testdata2archive.tree) os.remove(testdata2archivepath) os.rmdir(tmpdir)