From 8ed2392f46fbd1a76a9fc481f6c8f2b64eef8219 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Fri, 25 May 2012 15:01:18 +0200 Subject: [PATCH] Fix test cases --- tests/__init__.py | 13 +++++-- tests/data/t.7z.foo | Bin 158 -> 157 bytes tests/data/{t.a => t.txt.a} | 0 tests/data/{t.a.foo => t.txt.a.foo} | 0 tests/data/t.txt.lz.foo | Bin 39 -> 38 bytes tests/test_archives.py | 6 ++-- tests/test_foo_archives.py | 54 ++++++++++++++-------------- tests/test_mime.py | 4 +-- 8 files changed, 43 insertions(+), 34 deletions(-) rename tests/data/{t.a => t.txt.a} (100%) rename tests/data/{t.a.foo => t.txt.a.foo} (100%) diff --git a/tests/__init__.py b/tests/__init__.py index 670e1a0..414a65f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -98,8 +98,10 @@ class ArchiveTest (unittest.TestCase): txtfile = os.path.join(output, 't.txt') self.check_textfile(txtfile, 't.txt') elif contents == ContentSet.Singlefile: - txtfile = output - self.check_textfile(txtfile, 't.txt') + # a non-existing directory to ensure files do not exist in it + ned = get_nonexisting_directory() + expected_output = os.path.basename(patoolib.util.get_single_outfile(ned, archive)) + self.check_textfile(output, expected_output) def check_directory (self, dirname, expectedname): self.assertTrue(os.path.isdir(dirname), dirname) @@ -245,3 +247,10 @@ def has_codec (program, codec): if patoolib.program_supports_compression(program, codec): return True return patoolib.util.find_program(codec) + + +def get_nonexisting_directory(): + d = os.path.join(os.getcwd(), "foo") + while os.path.exists(d): + d += 'a' + return d diff --git a/tests/data/t.7z.foo b/tests/data/t.7z.foo index 32772431a1b52a454a484b4eae79492e3b9adf15..7149c7fb954a92df91fd08c1db396f560800dea5 100644 GIT binary patch delta 144 zcmbQoIG3^BylT&Sbr}ZcbKAaOh-H8P1t`5XV+l8d6i*G9+i1+bj{lr$U7*vcVz2f? z3a8GU`JgJufBdZlgEK4Jx82`g=k$K~oV#Mm>PxEx?U~;<9{-o%*RzaAwU=>vM|#77 mvX^kGyaSRZk0Ht@`vwF%P#Z&9K1|-mE%)XBQoc-bF9a@I+ zHdn>n%}VaPc=LYqukuB+IoqR7Z_~PbocA?fzRUeLMy&tXq$ajUv524O{roj6DmUzp osON^_;G*-_3f9~V?YYc7-B8~jXr?$58^^>3akj`w2mBZq09CLxwEzGB diff --git a/tests/data/t.a b/tests/data/t.txt.a similarity index 100% rename from tests/data/t.a rename to tests/data/t.txt.a diff --git a/tests/data/t.a.foo b/tests/data/t.txt.a.foo similarity index 100% rename from tests/data/t.a.foo rename to tests/data/t.txt.a.foo diff --git a/tests/data/t.txt.lz.foo b/tests/data/t.txt.lz.foo index 92fe36a98b075de293791109ec38ecdc1ef1dfa8..f5f78c7688382fe87b299d89314c01b8aa75c2cb 100644 GIT binary patch literal 38 jcmeZ?@(f_)VUXgP^B)L4FfcH5Y)~;`0@5I$2B8=L. -from tests import ArchiveTest, needs_os, needs_program, needs_codec +from tests import ArchiveTest, needs_os, needs_program, needs_codec, ContentSet class TestArchives (ArchiveTest): @@ -182,21 +182,21 @@ class TestArchives (ArchiveTest): @needs_program('bzip2') def test_bzip2 (self): self.program = 'bzip2' - self.archive_extract('t.txt.bz2.foo') + self.archive_extract('t.txt.bz2.foo', contents=ContentSet.Singlefile) self.archive_test('t.txt.bz2.foo') self.archive_create('t.txt.bz2.foo', format="bzip2", singlefile=True) @needs_program('file') def test_py_bz2 (self): self.program = 'py_bz2' - self.archive_extract('t.txt.bz2.foo') + self.archive_extract('t.txt.bz2.foo', contents=ContentSet.Singlefile) self.archive_create('t.txt.bz2.foo', format="bzip2", singlefile=True) @needs_program('file') @needs_program('pbzip2') def test_pbzip2 (self): self.program = 'pbzip2' - self.archive_extract('t.txt.bz2.foo') + self.archive_extract('t.txt.bz2.foo', contents=ContentSet.Singlefile) self.archive_test('t.txt.bz2.foo') self.archive_create('t.txt.bz2.foo', format="bzip2", singlefile=True) @@ -204,7 +204,7 @@ class TestArchives (ArchiveTest): @needs_program('lbzip2') def test_lbzip2 (self): self.program = 'lbzip2' - self.archive_extract('t.txt.bz2.foo') + self.archive_extract('t.txt.bz2.foo', contents=ContentSet.Singlefile) self.archive_test('t.txt.bz2.foo') self.archive_create('t.txt.bz2.foo', format="bzip2", singlefile=True) @@ -227,7 +227,7 @@ class TestArchives (ArchiveTest): @needs_program('unzip') def test_unzip (self): self.program = 'unzip' - self.archive_extract('t.zip.foo') + self.archive_extract('t.zip.foo', contents=None) self.archive_list('t.zip.foo') self.archive_test('t.zip.foo') self.archive_extract('t.jar.foo', contents=None) @@ -250,13 +250,13 @@ class TestArchives (ArchiveTest): def test_gzip (self): self.program = 'gzip' self.archive_commands('t.txt.gz.foo', format="gzip", singlefile=True) - self.archive_extract('t.txt.Z.foo') + self.archive_extract('t.txt.Z.foo', contents=ContentSet.Singlefile) @needs_program('file') @needs_program('gzip') def test_py_gzip (self): self.program = 'py_gzip' - self.archive_extract('t.txt.gz.foo') + self.archive_extract('t.txt.gz.foo', contents=ContentSet.Singlefile) # gzip is used to test the created archive self.archive_create('t.txt.gz.foo', format="gzip", singlefile=True) @@ -264,7 +264,7 @@ class TestArchives (ArchiveTest): @needs_program('uncompress.real') def test_uncompress (self): self.program = 'uncompress.real' - self.archive_extract('t.txt.Z.foo') + self.archive_extract('t.txt.Z.foo', contents=ContentSet.Singlefile) @needs_program('file') @needs_program('compress') @@ -287,10 +287,10 @@ class TestArchives (ArchiveTest): self.archive_list('t.cpio.foo') self.archive_list('t.rpm.foo') self.archive_list('t.deb.foo') - self.archive_extract('t.txt.gz.foo') - self.archive_extract('t.txt.bz2.foo') + self.archive_extract('t.txt.gz.foo', contents=None) + self.archive_extract('t.txt.bz2.foo', contents=ContentSet.Singlefile) self.archive_extract('t.jar.foo', contents=None) - self.archive_extract('t.txt.Z.foo') + self.archive_extract('t.txt.Z.foo', contents=ContentSet.Singlefile) self.archive_extract('t.cab.foo') self.archive_extract('t.arj.foo') self.archive_extract('t.cpio.foo') @@ -321,10 +321,10 @@ class TestArchives (ArchiveTest): #self.archive_list('t.cpio.foo') self.archive_list('t.rpm.foo') #self.archive_list('t.deb.foo') - self.archive_extract('t.txt.gz.foo') - self.archive_extract('t.txt.bz2.foo') + self.archive_extract('t.txt.gz.foo', contents=None) + self.archive_extract('t.txt.bz2.foo', contents=ContentSet.Singlefile) self.archive_extract('t.jar.foo', contents=None) - self.archive_extract('t.txt.Z.foo') + self.archive_extract('t.txt.Z.foo', contents=ContentSet.Singlefile) self.archive_extract('t.cab.foo') #self.archive_extract('t.arj.foo') #self.archive_extract('t.cpio.foo') @@ -367,7 +367,7 @@ class TestArchives (ArchiveTest): def test_cabextract (self): self.program = 'cabextract' self.archive_list('t.cab.foo') - self.archive_extract('t.cab.foo') + self.archive_extract('t.cab.foo', contents=None) @needs_program('file') @needs_program('orange') @@ -392,7 +392,7 @@ class TestArchives (ArchiveTest): @needs_program('ar') def test_ar (self): self.program = 'ar' - self.archive_commands('t.a.foo', format='ar', singlefile=True) + self.archive_commands('t.txt.a.foo', format='ar', singlefile=True, contents=None) @needs_program('file') @needs_program('cpio') @@ -459,7 +459,7 @@ class TestArchives (ArchiveTest): def test_lzip (self): self.program = 'lzip' self.archive_test('t.txt.lz.foo') - self.archive_extract('t.txt.lz.foo') + self.archive_extract('t.txt.lz.foo', contents=ContentSet.Singlefile) self.archive_create('t.txt.lz.foo', format="lzip", singlefile=True) @needs_program('file') @@ -467,7 +467,7 @@ class TestArchives (ArchiveTest): def test_clzip (self): self.program = 'clzip' self.archive_test('t.txt.lz.foo') - self.archive_extract('t.txt.lz.foo') + self.archive_extract('t.txt.lz.foo', contents=ContentSet.Singlefile) self.archive_create('t.txt.lz.foo', format="lzip", singlefile=True) @needs_program('file') @@ -475,7 +475,7 @@ class TestArchives (ArchiveTest): def test_plzip (self): self.program = 'plzip' self.archive_test('t.txt.lz.foo') - self.archive_extract('t.txt.lz.foo') + self.archive_extract('t.txt.lz.foo', contents=ContentSet.Singlefile) self.archive_create('t.txt.lz.foo', format="lzip", singlefile=True) @needs_program('file') @@ -483,16 +483,16 @@ class TestArchives (ArchiveTest): def test_pdlzip (self): self.program = 'pdlzip' self.archive_test('t.txt.lz.foo') - self.archive_extract('t.txt.lz.foo') + self.archive_extract('t.txt.lz.foo', contents=ContentSet.Singlefile) self.archive_create('t.txt.lz.foo', format="lzip", singlefile=True) @needs_program('file') @needs_program('xz') def test_xz (self): self.program = 'xz' - self.archive_test('t.xz.foo') - self.archive_extract('t.xz.foo') - self.archive_create('t.xz.foo', format="xz", singlefile=True) + self.archive_test('t.txt.xz.foo') + self.archive_extract('t.txt.xz.foo', contents=ContentSet.Singlefile) + self.archive_create('t.txt.xz.foo', format="xz", singlefile=True) @needs_program('file') @needs_program('lha') @@ -554,7 +554,7 @@ class TestArchives (ArchiveTest): @needs_program('mac') def test_mac (self): self.program = 'mac' - self.archive_extract('t.ape.foo') + self.archive_extract('t.ape.foo', contents=None) self.archive_create('t.ape.foo', srcfile='t.wav') # file(1) does not recognize .shn files @@ -562,13 +562,13 @@ class TestArchives (ArchiveTest): #@needs_program('shorten') #def test_shorten (self): # self.program = 'shorten' - # self.archive_extract('t.shn.foo') + # self.archive_extract('t.shn.foo', contents=None) # self.archive_create('t.shn.foo', srcfile='t.wav') @needs_program('file') @needs_program('flac') def test_flac (self): self.program = 'flac' - self.archive_extract('t.flac.foo') + self.archive_extract('t.flac.foo', contents=None) self.archive_test('t.flac.foo') self.archive_create('t.flac.foo', srcfile='t.wav', format='flac') diff --git a/tests/test_mime.py b/tests/test_mime.py index 146536a..0b8083e 100644 --- a/tests/test_mime.py +++ b/tests/test_mime.py @@ -97,8 +97,8 @@ class TestMime (unittest.TestCase): self.mime_test_file("t.zip.foo", "application/zip", None) self.mime_test_file("t.ace", "application/x-ace", None) self.mime_test_file("t.ace.foo", "application/x-ace", None) - self.mime_test_file("t.a", "application/x-archive", None) - self.mime_test_file("t.a.foo", "application/x-archive", None) + self.mime_test_file("t.txt.a", "application/x-archive", None) + self.mime_test_file("t.txt.a.foo", "application/x-archive", None) self.mime_test_file("t.lha", "application/x-lha", None) self.mime_test_file("t.lzh", "application/x-lha", None) self.mime_test_file("t.lha.foo", "application/x-lha", None)