[svn] Add tests for the case where we do recursive extraction of an archive trunk

Sun, 17 Dec 2006 09:20:02 -0500

author
brett
date
Sun, 17 Dec 2006 09:20:02 -0500
branch
trunk
changeset 10
f0acfe12a0e2
parent 9
920417b8acc9
child 11
a2ca41a85243

[svn] Add tests for the case where we do recursive extraction of an archive
that's not in the current working directory, and fix the associated bug.

TODO file | annotate | diff | comparison | revisions
scripts/x file | annotate | diff | comparison | revisions
tests/compare.py file | annotate | diff | comparison | revisions
--- a/TODO	Sun Dec 17 08:30:32 2006 -0500
+++ b/TODO	Sun Dec 17 09:20:02 2006 -0500
@@ -1,7 +1,5 @@
 Things which I have a use case/anti-use case for:
 * Decompress non-archive files.
-* Write tests for extracting in a different directory from where the archives
-  live.
 * Figure out what to do about warnings in the Handlers.
 
 Things that are generally good:
--- a/scripts/x	Sun Dec 17 08:30:32 2006 -0500
+++ b/scripts/x	Sun Dec 17 09:20:02 2006 -0500
@@ -354,10 +354,9 @@
     def recurse(self):
         if not self.options.recursive:
             return
-        archive_path = os.path.split(self.current_filename)[0]
         for filename in self.current_extractor.included_archives:
             tail_path, basename = os.path.split(filename)
-            directory = os.path.join(self.current_directory, archive_path,
+            directory = os.path.join(self.current_directory,
                                      self.current_handler.directory, tail_path)
             self.archives.setdefault(directory, []).append(basename)
 
--- a/tests/compare.py	Sun Dec 17 08:30:32 2006 -0500
+++ b/tests/compare.py	Sun Dec 17 09:20:02 2006 -0500
@@ -28,20 +28,20 @@
 set -e
 """
 
-tests = {'test-1.23.tar': ([], ['tar -xf test-1.23.tar'], []),
-         'test-1.23.tar.gz': ([], ['tar -xzf test-1.23.tar.gz'], []),
+tests = {'test-1.23.tar': ([], ['tar -xf $1'], []),
+         'test-1.23.tar.gz': ([], ['tar -xzf $1'], []),
          'test-1.23.tar.bz2': ([], ['mkdir test-1.23',
                                     'cd test-1.23',
-                                    'tar -jxf ../test-1.23.tar.bz2'], []),
+                                    'tar -jxf ../$1'], []),
          'test-1.23.zip': ([], ['mkdir test-1.23',
                                 'cd test-1.23',
-                                'unzip -q ../test-1.23.zip'], []),
+                                'unzip -q ../$1'], []),
          'test-1.23.cpio': ([], ['cpio -i --make-directories \
-                                  <test-1.23.cpio 2>/dev/null'], []),
+                                  <$1 2>/dev/null'], []),
          'test-1.23_all.deb': ([], ['TD=$PWD',
                                     'mkdir test-1.23',
                                     'cd /tmp',
-                                    'ar x $TD/test-1.23_all.deb data.tar.gz',
+                                    'ar x $TD/$1 data.tar.gz',
                                     'cd $TD/test-1.23',
                                     'tar -zxf /tmp/data.tar.gz',
                                     'rm /tmp/data.tar.gz'], []),
@@ -49,7 +49,7 @@
     ['-r'],
     ['mkdir test-recursive-badperms',
      'cd test-recursive-badperms',
-     'tar -jxf ../test-recursive-badperms.tar.bz2',
+     'tar -jxf ../$1',
      'mkdir test-badperms',
      'cd test-badperms',
      'tar -xf ../test-badperms.tar',
@@ -72,8 +72,9 @@
 
 
 class ExtractorTest(object):
-    def __init__(self, archive_filename, info):
-        self.archive_filename = archive_filename
+    def __init__(self, directory, archive_filename, info):
+        self.directory = directory
+        self.archive_filename = os.path.join(directory, archive_filename)
         self.arguments, self.shell_commands, self.shell_test = info
         
     def get_results(self, commands):
@@ -94,10 +95,11 @@
 
     def get_shell_results(self):
         self.write_script(self.shell_commands)
-        return self.get_results(['sh', TESTSCRIPT_NAME])
+        return self.get_results(['sh', TESTSCRIPT_NAME, self.archive_filename])
 
     def get_extractor_results(self):
-        return self.get_results(['../scripts/x'] + self.arguments +
+        script = os.path.join(self.directory, '../scripts/x')
+        return self.get_results([script] + self.arguments +
                                 [self.archive_filename])
         
     def get_posttest_result(self):
@@ -143,15 +145,25 @@
             return True
 
 
-successes = 0
-failures = 0
+def run_tests(directory, testnames):
+    successes = 0
+    failures = 0
+    for testname in testnames:
+        test = ExtractorTest(directory, testname, tests[testname])
+        if test.run():
+            successes += 1
+        else:
+            failures += 1
+    return successes, failures
+    
+results = []
 testnames = tests.keys()
 testnames.sort()
-for testname in testnames:
-    test = ExtractorTest(testname, tests[testname])
-    if test.run():
-        successes += 1
-    else:
-        failures += 1
-print "Totals: %s successes, %s failures" % (successes, failures)
-
+results.append(run_tests('.', testnames))
+os.mkdir('inside-dir')
+os.chdir('inside-dir')
+results.append(run_tests('..', testnames))
+os.chdir('..')
+subprocess.call(['rm', '-rf', 'inside-dir'])
+print "Totals: %s successes, %s failures" % \
+      tuple([sum(total) for total in zip(*results)])

mercurial