Check archive creation result.
This commit is contained in:
parent
c5f1dc543b
commit
f82e1d3d22
|
@ -84,13 +84,13 @@ class ArchiveTest (unittest.TestCase):
|
||||||
os.chdir(tmpdir)
|
os.chdir(tmpdir)
|
||||||
try:
|
try:
|
||||||
output = patoolib._handle_archive(archive, 'extract', program=self.program, verbose=verbose)
|
output = patoolib._handle_archive(archive, 'extract', program=self.program, verbose=verbose)
|
||||||
self.check_extracted_contents(archive, output, contents)
|
self.check_extracted_archive(archive, output, contents)
|
||||||
finally:
|
finally:
|
||||||
if olddir:
|
if olddir:
|
||||||
os.chdir(olddir)
|
os.chdir(olddir)
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
def check_extracted_contents (self, archive, output, contents):
|
def check_extracted_archive (self, archive, output, contents):
|
||||||
if contents == ContentSet.Recursive:
|
if contents == ContentSet.Recursive:
|
||||||
# outdir is the 't' directory of the archive
|
# outdir is the 't' directory of the archive
|
||||||
self.assertEqual(output, 't')
|
self.assertEqual(output, 't')
|
||||||
|
@ -130,12 +130,10 @@ class ArchiveTest (unittest.TestCase):
|
||||||
# determine filename which is added to the archive
|
# determine filename which is added to the archive
|
||||||
if srcfile is None:
|
if srcfile is None:
|
||||||
if singlefile:
|
if singlefile:
|
||||||
srcfile = 'foo .txt'
|
srcfile = 't.txt'
|
||||||
contents = ContentSet.Singlefile
|
|
||||||
else:
|
else:
|
||||||
srcfile = 'foo dir'
|
srcfile = 't'
|
||||||
contents = ContentSet.Recursive
|
os.chdir(datadir)
|
||||||
srcfile = os.path.join(datadir, srcfile)
|
|
||||||
# The format and compression arguments are needed for creating
|
# The format and compression arguments are needed for creating
|
||||||
# archives with unusual file extensions.
|
# archives with unusual file extensions.
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
|
@ -147,18 +145,24 @@ class ArchiveTest (unittest.TestCase):
|
||||||
# create again in verbose mode
|
# create again in verbose mode
|
||||||
kwargs['verbose'] = True
|
kwargs['verbose'] = True
|
||||||
self._archive_create(archive, srcfile, kwargs)
|
self._archive_create(archive, srcfile, kwargs)
|
||||||
# XXX check content
|
|
||||||
|
|
||||||
def _archive_create (self, filename, topack, kwargs):
|
def _archive_create (self, archive, srcfile, kwargs):
|
||||||
"""Create archive from filename."""
|
"""Create archive from filename."""
|
||||||
|
self.assertFalse(os.path.isabs(srcfile))
|
||||||
|
self.assertTrue(os.path.exists(srcfile))
|
||||||
# create a temporary directory for creation
|
# create a temporary directory for creation
|
||||||
tmpdir = patoolib.util.tmpdir(dir=basedir)
|
tmpdir = patoolib.util.tmpdir(dir=basedir)
|
||||||
archive = os.path.join(tmpdir, filename)
|
archive = os.path.join(tmpdir, archive)
|
||||||
os.chdir(tmpdir)
|
self.assertTrue(os.path.isabs(archive), "archive path is not absolute: %r" % archive)
|
||||||
try:
|
try:
|
||||||
patoolib._handle_archive(archive, 'create', topack, **kwargs)
|
patoolib._handle_archive(archive, 'create', srcfile, **kwargs)
|
||||||
self.assertTrue(os.path.isfile(archive))
|
self.assertTrue(os.path.isfile(archive))
|
||||||
# test the created archive
|
self.check_created_archive_with_test(archive)
|
||||||
|
self.check_created_archive_with_diff(archive, srcfile)
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
def check_created_archive_with_test(self, archive):
|
||||||
command = 'test'
|
command = 'test'
|
||||||
program = self.program
|
program = self.program
|
||||||
# special case for programs that cannot test what they create
|
# special case for programs that cannot test what they create
|
||||||
|
@ -174,8 +178,33 @@ class ArchiveTest (unittest.TestCase):
|
||||||
elif self.program == 'lcab':
|
elif self.program == 'lcab':
|
||||||
program = 'cabextract'
|
program = 'cabextract'
|
||||||
patoolib._handle_archive(archive, command, program=program)
|
patoolib._handle_archive(archive, command, program=program)
|
||||||
|
|
||||||
|
def check_created_archive_with_diff(self, archive, srcfile):
|
||||||
|
"""Extract created archive again and compare the contents."""
|
||||||
|
# diff srcfile and output
|
||||||
|
diff = patoolib.util.find_program("diff")
|
||||||
|
if not diff:
|
||||||
|
return
|
||||||
|
program = self.program
|
||||||
|
# special case for programs that cannot extract what they create
|
||||||
|
if self.program == 'lcab':
|
||||||
|
program = 'cabextract'
|
||||||
|
# XXX
|
||||||
|
tmpdir = patoolib.util.tmpdir(dir=basedir)
|
||||||
|
try:
|
||||||
|
olddir = os.getcwd()
|
||||||
|
except OSError:
|
||||||
|
olddir = None
|
||||||
|
os.chdir(tmpdir)
|
||||||
|
try:
|
||||||
|
output = patoolib._handle_archive(archive, 'extract', program=program)
|
||||||
|
print "XXX1", archive, tmpdir
|
||||||
|
print "XXX diff", srcfile, "with", output
|
||||||
|
res = patoolib.util.run([diff, "-urN", srcfile, output])
|
||||||
|
self.assertEqual(res, 0)
|
||||||
finally:
|
finally:
|
||||||
os.chdir(basedir)
|
if olddir:
|
||||||
|
os.chdir(olddir)
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
42
|
|
|
@ -1 +0,0 @@
|
||||||
42
|
|
|
@ -0,0 +1 @@
|
||||||
|
42
|
|
@ -0,0 +1 @@
|
||||||
|
42
|
Loading…
Reference in New Issue