]> granicus.if.org Git - zziplib/blob - test/zziptests.py
expand tests to mix/zap
[zziplib] / test / zziptests.py
1 import unittest
2 import subprocess
3 import logging
4 import os
5 import collections
6 from fnmatch import fnmatchcase as matches
7
8 logg = logging.getLogger("test")
9
10 topsrcdir = "../.."
11 testdatadir = "testdata.d"
12 readme = "README"
13 mkzip = "zip"
14 unzip = "unzip"
15 exeext = ""
16
17 def shell_string(command):
18    return " ".join(["'%s'" % arg.replace("'","\\'") for arg in command])
19
20 def shell(command, shell=True, calls=False, cwd=None, env=None, lang=None, returncodes=None):
21     returncodes = returncodes or [ None, 0 ]
22     Shell = collections.namedtuple("Shell",["returncode", "output", "errors", "shell"])
23     if isinstance(command, basestring):
24        sh_command = command
25        command = [ command ]
26     else:
27        sh_command = shell_string(command)
28     if lang:
29         if not env: env = os.environ.copy()
30         for name, value in env.items():
31             if name.startswith("LC_"):
32                 env[name] = lang
33         env["LANG"] = lang # defines message format
34         env["LC_ALL"] = lang # other locale formats
35     try:
36         output, errors = "", ""
37         if calls:
38             logg.debug("result from %s: %s", cwd and cwd+"/" or "shell", sh_command)
39             run = subprocess.Popen(command, shell=shell, cwd=cwd, env=env)
40             if run.returncode:
41                 logg.warning("EXIT %s: %s", run.returncode, command)
42             run.wait()
43         else:
44             logg.debug("output from %s: %s", cwd and cwd+"/" or "shell", sh_command)
45             run = subprocess.Popen(command, shell=shell, cwd=cwd,
46                 stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=None, env=env)
47             if run.returncode:
48                 logg.warning("EXIT %s: %s", run.returncode, command)
49             output, errors = run.communicate() # run.wait()
50     except:
51         logg.error("*E*: %s", sh_command)
52         for line in output.split("\n"):
53             if line:
54                 logg.error("OUT: %s", line)
55         for line in errors.split("\n"):
56             if line:
57                 logg.error("ERR: %s", line)
58         raise
59     if run.returncode not in returncodes:
60         logg.warning("*%02i: %s", run.returncode, sh_command)
61         for line in output.split("\n"):
62             if line:
63                 logg.warning("OUT: %s", line)
64         for line in errors.split("\n"):
65             if line:
66                 logg.warning("ERR: %s", line)
67     else:
68         for line in output.split("\n"):
69             if line:
70                 logg.debug("OUT: %s", line)
71         for line in errors.split("\n"):
72             if line:
73                 logg.debug("ERR: %s", line)
74     return Shell(run.returncode, output, errors, sh_command)
75
76
77 class ZZipTest(unittest.TestCase):
78   @property
79   def t(self):
80     if not os.path.isdir(testdatadir):
81        os.makedirs(testdatadir)
82     return testdatdir
83   @property
84   def s(self):
85     return topsrcdir
86   def src(self, name):
87     return os.path.join(self.s, name)
88   def readme(self):
89      f = open(self.src(readme))
90      text = f.read()
91      f.close()
92      return text
93   def mkfile(self, name, content):
94     b = os.path.dirname(name)
95     if not os.path.isdir(b):
96        os.makedirs(b)
97     f = open(name, "w")
98     f.write(content)
99     f.close()
100   def bins(self, name):
101     exe = os.path.join("..", "bins", name)
102     if exeext: exe += exeext
103     return exe
104   def test_100_make_test0_zip(self):
105     """ create a test.zip for later tests using standard 'zip'
106     It will fall back to a variant in the source code if 'zip'
107     is not installed on the build host. The content is just
108     the README file that we can check for equality later on. """
109     zipfile="test0.zip"
110     tmpdir="test0.tmp"
111     exe=mkzip
112     filename = os.path.join(tmpdir,"README")
113     filetext = self.readme()
114     self.mkfile(filename, filetext)
115     shell("{exe} ../{zipfile} README".format(**locals()), cwd=tmpdir)
116     self.assertGreater(os.path.getsize(zipfile), 10)
117   def test_101_make_test1_zip(self):
118     """ create a test1.zip for later tests using standard 'zip'
119     It will fall back to a variant in the source code if 'zip'
120     is not installed on the build host. The archive has 10
121     generic files that we can check for their content later. """
122     zipfile="test1.zip"
123     tmpdir="test1.tmp"
124     exe=mkzip
125     for i in [1,2,3,4,5,6,7,8,9]:
126        filename = os.path.join(tmpdir,"file.%i" % i)
127        filetext = "file-%i\n" % i
128        self.mkfile(filename, filetext)
129     filename = os.path.join(tmpdir,"README")
130     filetext = self.readme()
131     self.mkfile(filename, filetext)
132     shell("{exe} ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
133     self.assertGreater(os.path.getsize(zipfile), 10)
134   def test_102_make_test2_zip(self):
135     """ create a test2.zip for later tests using standard 'zip'
136     It will NOT fall back to a variant in the source code.
137     The archive has 100 generic files with known content. """
138     zipfile="test2.zip"
139     tmpdir="test2.tmp"
140     exe=mkzip
141     for i in xrange(100):
142        filename = os.path.join(tmpdir,"file.%02i" % i)
143        filetext = "file-%02i\n" % i
144        self.mkfile(filename, filetext)
145     filename = os.path.join(tmpdir,"README")
146     filetext = self.readme()
147     self.mkfile(filename, filetext)
148     shell("{exe} ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
149     self.assertGreater(os.path.getsize(zipfile), 10)
150   def test_103_make_test3_zip(self):
151     """ create a test3.zip for later tests using standard 'zip'
152     It will NOT fall back to a variant in the source code.
153     The archive has 1000 generic files with known content. """
154     zipfile="test3.zip"
155     tmpdir="test3.tmp"
156     exe=mkzip
157     for i in xrange(1000):
158        filename = os.path.join(tmpdir,"file.%03i" % i)
159        filetext = "file-%03i\n" % i
160        self.mkfile(filename, filetext)
161     filename = os.path.join(tmpdir,"README")
162     filetext = self.readme()
163     self.mkfile(filename, filetext)
164     shell("{exe} ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
165     self.assertGreater(os.path.getsize(zipfile), 10)
166   def test_104_make_test4_zip(self):
167     """ create a test4.zip for later tests using standard 'zip'
168     It will NOT fall back to a variant in the source code.
169     The archive has 1000 generic files with known content
170     and they are NOT stored compressed in the archive. """
171     zipfile="test4.zip"
172     tmpdir="test4.tmp"
173     exe=mkzip
174     for i in xrange(1000):
175        filename = os.path.join(tmpdir,"file.%03i" % i)
176        filetext = "file-%03i\n" % i
177        self.mkfile(filename, filetext)
178     filename = os.path.join(tmpdir,"README")
179     filetext = self.readme()
180     self.mkfile(filename, filetext)
181     shell("{exe} -n README ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
182     self.assertGreater(os.path.getsize(zipfile), 10)
183   def test_110_make_test0_dat(self):
184     """ create test.dat from test.zip with xorcopy """
185     zipfile = "test0.zip"
186     datfile = "test0x.dat"
187     exe = self.bins("zzxorcopy")
188     shell("{exe} {zipfile} {datfile}".format(**locals()))
189     self.assertGreater(os.path.getsize(datfile), 10)
190     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
191   def test_111_make_test1_dat(self):
192     """ create test.dat from test.zip with xorcopy """
193     zipfile = "test1.zip"
194     datfile = "test1x.dat"
195     exe = self.bins("zzxorcopy")
196     shell("{exe} {zipfile} {datfile}".format(**locals()))
197     self.assertGreater(os.path.getsize(datfile), 10)
198     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
199   def test_112_make_test2_dat(self):
200     """ create test.dat from test.zip with xorcopy """
201     zipfile = "test2.zip"
202     datfile = "test2x.dat"
203     exe = self.bins("zzxorcopy")
204     shell("{exe} {zipfile} {datfile}".format(**locals()))
205     self.assertGreater(os.path.getsize(datfile), 10)
206     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
207   def test_113_make_test3_dat(self):
208     """ create test.dat from test.zip with xorcopy """
209     zipfile = "test3.zip"
210     datfile = "test3x.dat"
211     exe = self.bins("zzxorcopy")
212     shell("{exe} {zipfile} {datfile}".format(**locals()))
213     self.assertGreater(os.path.getsize(datfile), 10)
214     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
215   def test_114_make_test4_dat(self):
216     """ create test.dat from test.zip with xorcopy """
217     zipfile = "test4.zip"
218     datfile = "test4x.dat"
219     exe = self.bins("zzxorcopy")
220     shell("{exe} {zipfile} {datfile}".format(**locals()))
221     self.assertGreater(os.path.getsize(datfile), 10)
222     self.assertEqual(os.path.getsize(datfile), os.path.getsize(zipfile))
223   def test_200_zziptest_test0_zip(self):
224     """ run zziptest on test.zip """
225     zipfile = "test0.zip"
226     logfile = "test0.log"
227     exe = self.bins("zziptest")
228     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
229     self.assertGreater(os.path.getsize(logfile), 10)
230   def test_201_zziptest_test1_zip(self):
231     """ run zziptest on test.zip """
232     zipfile = "test1.zip"
233     logfile = "test1.log"
234     exe = self.bins("zziptest")
235     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
236     self.assertGreater(os.path.getsize(logfile), 10)
237   def test_202_zziptest_test2_zip(self):
238     """ run zziptest on test.zip """
239     zipfile = "test2.zip"
240     logfile = "test2.log"
241     exe = self.bins("zziptest")
242     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
243     self.assertGreater(os.path.getsize(logfile), 10)
244   def test_203_zziptest_test3_zip(self):
245     """ run zziptest on test.zip """
246     zipfile = "test3.zip"
247     logfile = "test3.log"
248     exe = self.bins("zziptest")
249     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
250     self.assertGreater(os.path.getsize(logfile), 10)
251   def test_204_zziptest_test4_zip(self):
252     """ run zziptest on test.zip """
253     zipfile = "test4.zip"
254     logfile = "test4.log"
255     exe = self.bins("zziptest")
256     shell("{exe} --quick {zipfile} | tee {logfile}".format(**locals()))
257     self.assertGreater(os.path.getsize(logfile), 10)
258   def test_210_zzcat_test0_zip(self):
259     """ run zzcat on test.zip using just test/README """
260     zipfile = "test0.zip"
261     getfile = "test0/README"
262     logfile = "test0.readme.txt"
263     exe = self.bins("zzcat")
264     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
265     self.assertGreater(os.path.getsize(logfile), 10)
266     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
267   def test_211_zzcat_test1_zip(self):
268     """ run zzcat on test.zip using just test/README """
269     zipfile = "test1.zip"
270     getfile = "test1/README"
271     logfile = "test1.readme.txt"
272     exe = self.bins("zzcat")
273     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
274     self.assertGreater(os.path.getsize(logfile), 10)
275     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
276     getfile = "test1/file.1"
277     run = shell("{exe} {getfile}".format(**locals()))
278     self.assertEqual("file-1\n", run.output)
279   def test_212_zzcat_test2_zip(self):
280     """ run zzcat on test.zip using just test/README """
281     zipfile = "test2.zip"
282     getfile = "test2/README"
283     logfile = "test2.readme.txt"
284     exe = self.bins("zzcat")
285     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
286     self.assertGreater(os.path.getsize(logfile), 10)
287     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
288     getfile = "test2/file.22"
289     run = shell("{exe} {getfile}".format(**locals()))
290     self.assertEqual("file-22\n", run.output)
291   def test_213_zzcat_test3_zip(self):
292     """ run zzcat on test.zip using just test/README """
293     zipfile = "test3.zip"
294     getfile = "test3/README"
295     logfile = "test3.readme.txt"
296     exe = self.bins("zzcat")
297     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
298     self.assertGreater(os.path.getsize(logfile), 10)
299     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
300     getfile = "test3/file.999"
301     run = shell("{exe} {getfile}".format(**locals()))
302     self.assertEqual("file-999\n", run.output)
303   def test_214_zzcat_test4_zip(self):
304     """ run zzcat on test.zip using just test/README """
305     zipfile = "test4.zip"
306     getfile = "test4/README"
307     logfile = "test4.readme.txt"
308     exe = self.bins("zzcat")
309     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
310     self.assertGreater(os.path.getsize(logfile), 10)
311     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
312     getfile = "test4/file.999"
313     run = shell("{exe} {getfile}".format(**locals()))
314     self.assertEqual("file-999\n", run.output)
315   def test_220_zzdir_test0_zip(self):
316     """ run zzdir on test0.zip using just 'test0' """
317     zipfile = "test0.zip"
318     getfile = "test0"
319     exe = self.bins("zzdir")
320     run = shell("{exe} {getfile} ".format(**locals()))
321     self.assertIn(' README ', run.output)
322     self.assertIn(' deflated ', run.output)
323     self.assertLess(len(run.output), 30)
324   def test_221_zzdir_test1_zip(self):
325     """ run zzdir on test1.zip using just 'test1' """
326     zipfile = "test1.zip"
327     getfile = "test1"
328     exe = self.bins("zzdir")
329     run = shell("{exe} {getfile} ".format(**locals()))
330     self.assertIn(' file.1 ', run.output)
331     self.assertIn(' file.2 ', run.output)
332     self.assertIn(' file.9 ', run.output)
333     self.assertIn(' README ', run.output)
334     self.assertIn(' deflated ', run.output)
335     self.assertIn(' stored ', run.output)
336   def test_222_zzdir_test2_zip(self):
337     """ run zzdir on test2.zip using just 'test2' """
338     zipfile = "test2.zip"
339     getfile = "test2"
340     exe = self.bins("zzdir")
341     run = shell("{exe} {getfile} ".format(**locals()))
342     self.assertIn(' file.01 ', run.output)
343     self.assertIn(' file.22 ', run.output)
344     self.assertIn(' file.99 ', run.output)
345     self.assertIn(' deflated ', run.output)
346     self.assertIn(' stored ', run.output)
347   def test_223_zzdir_test3_zip(self):
348     """ run zzdir on test3.zip using just 'test3' """
349     zipfile = "test3.zip"
350     getfile = "test3"
351     exe = self.bins("zzdir")
352     run = shell("{exe} {getfile} ".format(**locals()))
353     self.assertIn(' file.001 ', run.output)
354     self.assertIn(' file.222 ', run.output)
355     self.assertIn(' file.999 ', run.output)
356     self.assertIn(' deflated ', run.output)
357     self.assertIn(' stored ', run.output)
358   def test_224_zzdir_test4_zip(self):
359     """ run zzdir on test4.zip using just 'test4' """
360     zipfile = "test4.zip"
361     getfile = "test4"
362     exe = self.bins("zzdir")
363     run = shell("{exe} {getfile} ".format(**locals()))
364     self.assertIn(' file.001 ', run.output)
365     self.assertIn(' file.222 ', run.output)
366     self.assertIn(' file.999 ', run.output)
367     self.assertNotIn(' deflated ', run.output)
368     self.assertIn(' stored ', run.output)
369   def test_320_zzxordir_test0_dat(self):
370     """ run zzxordir on test0x.dat """
371     zipfile = "test0x.dat"
372     getfile = "test0x.dat"
373     exe = self.bins("zzdir")
374     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
375     self.assertEqual(run.returncode, 1)
376     self.assertEqual("", run.output)
377     self.assertIn("did not open test", run.errors)
378     exe = self.bins("zzxordir")
379     run = shell("{exe} {getfile} ".format(**locals()))
380     self.assertIn(' README ', run.output)
381     self.assertIn(' deflated ', run.output)
382     self.assertLess(len(run.output), 30)
383   def test_321_zzxordir_test1_dat(self):
384     """ run zzxordir on test1x.dat using just 'test1x' """
385     zipfile = "test1x.dat"
386     getfile = "test1x.dat"
387     exe = self.bins("zzdir")
388     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
389     self.assertEqual(run.returncode, 1)
390     self.assertEqual("", run.output)
391     self.assertIn("did not open test", run.errors)
392     exe = self.bins("zzxordir")
393     run = shell("{exe} {getfile} ".format(**locals()))
394     self.assertIn(' file.1 ', run.output)
395     self.assertIn(' file.2 ', run.output)
396     self.assertIn(' file.9 ', run.output)
397     self.assertIn(' README ', run.output)
398     self.assertIn(' deflated ', run.output)
399     self.assertIn(' stored ', run.output)
400   def test_322_zzxordir_test2_dat(self):
401     """ run zzxordir on test2x.dat using just 'test2x' """
402     zipfile = "test2x.dat"
403     getfile = "test2x"
404     exe = self.bins("zzdir")
405     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
406     self.assertEqual(run.returncode, 1)
407     self.assertEqual("", run.output)
408     self.assertIn("did not open test", run.errors)
409     exe = self.bins("zzxordir")
410     run = shell("{exe} {getfile} ".format(**locals()))
411     self.assertIn(' file.01 ', run.output)
412     self.assertIn(' file.22 ', run.output)
413     self.assertIn(' file.99 ', run.output)
414     self.assertIn(' deflated ', run.output)
415     self.assertIn(' stored ', run.output)
416   def test_323_zzxordir_test3_dat(self):
417     """ run zzxordir on test3x.dat using just 'test3x' """
418     zipfile = "test3x.dat"
419     getfile = "test3x"
420     exe = self.bins("zzdir")
421     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
422     self.assertEqual(run.returncode, 1)
423     self.assertEqual("", run.output)
424     self.assertIn("did not open test", run.errors)
425     exe = self.bins("zzxordir")
426     run = shell("{exe} {getfile} ".format(**locals()))
427     self.assertIn(' file.001 ', run.output)
428     self.assertIn(' file.222 ', run.output)
429     self.assertIn(' file.999 ', run.output)
430     self.assertIn(' deflated ', run.output)
431     self.assertIn(' stored ', run.output)
432   def test_324_zzxordir_test4_zip(self):
433     """ run zzxordir on test4x.dat using just 'test4x' """
434     zipfile = "test4x.dat"
435     getfile = "test4x"
436     exe = self.bins("zzdir")
437     run = shell("{exe} {getfile} ".format(**locals()), returncodes = [0,1])
438     self.assertEqual(run.returncode, 1)
439     self.assertEqual("", run.output)
440     self.assertIn("did not open test", run.errors)
441     exe = self.bins("zzxordir")
442     run = shell("{exe} {getfile} ".format(**locals()))
443     self.assertIn(' file.001 ', run.output)
444     self.assertIn(' file.222 ', run.output)
445     self.assertIn(' file.999 ', run.output)
446     self.assertNotIn(' deflated ', run.output)
447     self.assertIn(' stored ', run.output)
448   def test_340_zzxorcat_test0_zip(self):
449     """ run zzxorcat on testx.zip using just testx/README """
450     getfile = "test0x/README"
451     logfile = "test0x.readme.txt"
452     exe = self.bins("zzcat")
453     run = shell("{exe} {getfile} ".format(**locals()), lang="C")
454     self.assertEqual("", run.output)
455     self.assertIn("No such file or directory", run.errors)
456     exe = self.bins("zzxorcat")
457     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
458     self.assertGreater(os.path.getsize(logfile), 10)
459     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
460   def test_341_zzxorcat_test1_zip(self):
461     """ run zzxorcat on testx.zip using just testx/README """
462     getfile = "test1x/README"
463     logfile = "test1x.readme.txt"
464     exe = self.bins("zzcat")
465     run = shell("{exe} {getfile} ".format(**locals()), lang="C")
466     self.assertEqual("", run.output)
467     self.assertIn("No such file or directory", run.errors)
468     exe = self.bins("zzxorcat")
469     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
470     self.assertGreater(os.path.getsize(logfile), 10)
471     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
472     getfile = "test1x/file.1"
473     run = shell("{exe} {getfile}".format(**locals()))
474     self.assertEqual("file-1\n", run.output)
475   def test_342_zzxorcat_test2_zip(self):
476     """ run zzxorcat on testx.zip using just testx/README """
477     getfile = "test2x/README"
478     logfile = "test2x.readme.txt"
479     exe = self.bins("zzcat")
480     run = shell("{exe} {getfile} ".format(**locals()), lang="C")
481     self.assertEqual("", run.output)
482     self.assertIn("No such file or directory", run.errors)
483     exe = self.bins("zzxorcat")
484     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
485     self.assertGreater(os.path.getsize(logfile), 10)
486     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
487     getfile = "test2x/file.22"
488     run = shell("{exe} {getfile}".format(**locals()))
489     self.assertEqual("file-22\n", run.output)
490   def test_343_zzxorcat_test3_zip(self):
491     """ run zzxorcat on testx.zip using just testx/README """
492     getfile = "test3x/README"
493     logfile = "test3x.readme.txt"
494     exe = self.bins("zzcat")
495     run = shell("{exe} {getfile} ".format(**locals()), lang="C")
496     self.assertEqual("", run.output)
497     self.assertIn("No such file or directory", run.errors)
498     exe = self.bins("zzxorcat")
499     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
500     self.assertGreater(os.path.getsize(logfile), 10)
501     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
502     getfile = "test3x/file.999"
503     run = shell("{exe} {getfile}".format(**locals()))
504     self.assertEqual("file-999\n", run.output)
505   def test_344_zzxorcat_test4_zip(self):
506     """ run zzxorcat on testx.zip using just testx/README """
507     getfile = "test4x/README"
508     logfile = "test4x.readme.txt"
509     exe = self.bins("zzxorcat")
510     run = shell("{exe} {getfile} | tee {logfile}".format(**locals()))
511     self.assertGreater(os.path.getsize(logfile), 10)
512     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
513     getfile = "test4x/file.999"
514     run = shell("{exe} {getfile}".format(**locals()))
515     self.assertEqual("file-999\n", run.output)
516
517   def test_400_zzcat_big_test0_zip(self):
518     """ run zzcat-big on test.zip using just archive README """
519     zipfile = "test0.zip"
520     getfile = "README"
521     logfile = "test0.readme.big.txt"
522     exe = self.bins("unzzip-big")
523     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
524     self.assertGreater(os.path.getsize(logfile), 10)
525     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
526   def test_401_zzcat_big_test1_zip(self):
527     """ run zzcat-big on test.zip using just archive README """
528     zipfile = "test1.zip"
529     getfile = "README"
530     logfile = "test1.readme.big.txt"
531     exe = self.bins("unzzip-big")
532     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
533     self.assertGreater(os.path.getsize(logfile), 10)
534     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
535     getfile = "file.1"
536     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
537     self.assertEqual("file-1\n", run.output)
538   def test_402_zzcat_big_test2_zip(self):
539     """ run zzcat-seeke on test.zip using just archive README """
540     zipfile = "test2.zip"
541     getfile = "README"
542     logfile = "test2.readme.big.txt"
543     exe = self.bins("unzzip-big")
544     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
545     self.assertGreater(os.path.getsize(logfile), 10)
546     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
547     getfile = "file.22"
548     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
549     self.assertEqual("file-22\n", run.output)
550   def test_410_zzcat_mem_test0_zip(self):
551     """ run zzcat-mem on test.zip using just archive README """
552     zipfile = "test0.zip"
553     getfile = "README"
554     logfile = "test0.readme.mem.txt"
555     exe = self.bins("unzzip-mem")
556     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
557     self.assertGreater(os.path.getsize(logfile), 10)
558     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
559   def test_411_zzcat_mem_test1_zip(self):
560     """ run zzcat-mem on test.zip using archive README """
561     zipfile = "test1.zip"
562     getfile = "README"
563     logfile = "test1.readme.mem.txt"
564     exe = self.bins("unzzip-mem")
565     run = shell("{exe} -p {zipfile}  {getfile} | tee {logfile}".format(**locals()))
566     self.assertGreater(os.path.getsize(logfile), 10)
567     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
568     getfile = "file.1"
569     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
570     self.assertEqual("file-1\n", run.output)
571   def test_412_zzcat_mem_test2_zip(self):
572     """ run zzcat-mem on test.zip using archive README """
573     zipfile = "test2.zip"
574     getfile = "README"
575     logfile = "test2.readme.mem.txt"
576     exe = self.bins("unzzip-mem")
577     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
578     self.assertGreater(os.path.getsize(logfile), 10)
579     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
580     getfile = "file.22"
581     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
582     self.assertEqual("file-22\n", run.output)
583   def test_413_zzcat_mem_test3_zip(self):
584     """ run zzcat-mem on test.zip using archive README """
585     zipfile = "test3.zip"
586     getfile = "README"
587     logfile = "test3.readme.mem.txt"
588     exe = self.bins("unzzip-mem")
589     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
590     self.assertGreater(os.path.getsize(logfile), 10)
591     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
592     getfile = "file.999"
593     run = shell("{exe} -p {zipfile}  {getfile}".format(**locals()))
594     self.assertEqual("file-999\n", run.output)
595   def test_414_zzcat_mem_test4_zip(self):
596     """ run zzcat-mem on test.zip using archive README """
597     zipfile = "test4.zip"
598     getfile = "README"
599     logfile = "test4.readme.mem.txt"
600     exe = self.bins("unzzip-mem")
601     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
602     self.assertGreater(os.path.getsize(logfile), 10)
603     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
604     getfile = "file.999"
605     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
606     self.assertEqual("file-999\n", run.output)
607   def test_420_zzcat_mix_test0_zip(self):
608     """ run zzcat-mix on test.zip using just archive README """
609     self.skipTest("todo")
610     zipfile = "test0.zip"
611     getfile = "README"
612     logfile = "test0.readme.mix.txt"
613     exe = self.bins("unzzip-mix")
614     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
615     self.assertGreater(os.path.getsize(logfile), 10)
616     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
617   def test_421_zzcat_mix_test1_zip(self):
618     """ run zzcat-mix on test.zip using archive README """
619     self.skipTest("todo")
620     zipfile = "test1.zip"
621     getfile = "README"
622     logfile = "test1.readme.mix.txt"
623     exe = self.bins("unzzip-mix")
624     run = shell("{exe} -p {zipfile}  {getfile} | tee {logfile}".format(**locals()))
625     self.assertGreater(os.path.getsize(logfile), 10)
626     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
627     getfile = "file.1"
628     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
629     self.assertEqual("file-1\n", run.output)
630   def test_422_zzcat_mix_test2_zip(self):
631     """ run zzcat-mix on test.zip using archive README """
632     self.skipTest("todo")
633     zipfile = "test2.zip"
634     getfile = "README"
635     logfile = "test2.readme.mix.txt"
636     exe = self.bins("unzzip-mix")
637     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
638     self.assertGreater(os.path.getsize(logfile), 10)
639     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
640     getfile = "file.22"
641     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
642     self.assertEqual("file-22\n", run.output)
643   def test_423_zzcat_mix_test3_zip(self):
644     """ run zzcat-mix on test.zip using archive README """
645     self.skipTest("todo")
646     zipfile = "test3.zip"
647     getfile = "README"
648     logfile = "test3.readme.mix.txt"
649     exe = self.bins("unzzip-mix")
650     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
651     self.assertGreater(os.path.getsize(logfile), 10)
652     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
653     getfile = "file.999"
654     run = shell("{exe} -p {zipfile}  {getfile}".format(**locals()))
655     self.assertEqual("file-999\n", run.output)
656   def test_424_zzcat_mix_test4_zip(self):
657     """ run zzcat-mix on test.zip using archive README """
658     self.skipTest("todo")
659     zipfile = "test4.zip"
660     getfile = "README"
661     logfile = "test4.readme.mix.txt"
662     exe = self.bins("unzzip-mix")
663     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
664     self.assertGreater(os.path.getsize(logfile), 10)
665     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
666     getfile = "file.999"
667     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
668     self.assertEqual("file-999\n", run.output)
669   def test_440_zzcat_zap_test0_zip(self):
670     """ run zzcat-zap on test.zip using just archive README """
671     zipfile = "test0.zip"
672     getfile = "README"
673     logfile = "test0.readme.txt"
674     exe = self.bins("unzzip")
675     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
676     self.assertGreater(os.path.getsize(logfile), 10)
677     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
678   def test_441_zzcat_zap_test1_zip(self):
679     """ run zzcat-zap on test.zip using archive README """
680     zipfile = "test1.zip"
681     getfile = "README"
682     logfile = "test1.readme.zap.txt"
683     exe = self.bins("unzzip")
684     run = shell("{exe} -p {zipfile}  {getfile} | tee {logfile}".format(**locals()))
685     self.assertGreater(os.path.getsize(logfile), 10)
686     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
687     getfile = "file.1"
688     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
689     self.assertEqual("file-1\n", run.output)
690   def test_442_zzcat_zap_test2_zip(self):
691     """ run zzcat-zap on test.zip using archive README """
692     zipfile = "test2.zip"
693     getfile = "README"
694     logfile = "test2.readme.zap.txt"
695     exe = self.bins("unzzip")
696     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
697     self.assertGreater(os.path.getsize(logfile), 10)
698     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
699     getfile = "file.22"
700     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
701     self.assertEqual("file-22\n", run.output)
702   def test_443_zzcat_zap_test3_zip(self):
703     """ run zzcat-zap on test.zip using archive README """
704     zipfile = "test3.zip"
705     getfile = "README"
706     logfile = "test3.readme.zap.txt"
707     exe = self.bins("unzzip")
708     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
709     self.assertGreater(os.path.getsize(logfile), 10)
710     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
711     getfile = "file.999"
712     run = shell("{exe} -p {zipfile}  {getfile}".format(**locals()))
713     self.assertEqual("file-999\n", run.output)
714   def test_444_zzcat_zap_test4_zip(self):
715     """ run zzcat-zap on test.zip using archive README """
716     zipfile = "test4.zip"
717     getfile = "README"
718     logfile = "test4.readme.zap.txt"
719     exe = self.bins("unzzip")
720     run = shell("{exe} -p {zipfile} {getfile} | tee {logfile}".format(**locals()))
721     self.assertGreater(os.path.getsize(logfile), 10)
722     self.assertEqual(run.output.split("\n"), self.readme().split("\n"))
723     getfile = "file.999"
724     run = shell("{exe} -p {zipfile} {getfile}".format(**locals()))
725     self.assertEqual("file-999\n", run.output)
726
727   def test_500_zzdir_big_test0_zip(self):
728     """ run zzdir-big on test0.zip  """
729     zipfile = "test0.zip"
730     getfile = "test0.zip"
731     exe = self.bins("unzzip-big")
732     run = shell("{exe} -l {getfile} ".format(**locals()))
733     self.assertIn(' README ', run.output)
734     self.assertLess(len(run.output), 30)
735   def test_501_zzdir_big_test1_zip(self):
736     """ run zzdir-big on test1.zip  """
737     zipfile = "test1.zip"
738     getfile = "test1.zip"
739     exe = self.bins("unzzip-big")
740     run = shell("{exe} -l {getfile} ".format(**locals()))
741     self.assertIn(' file.1 ', run.output)
742     self.assertIn(' file.2 ', run.output)
743     self.assertIn(' file.9 ', run.output)
744     self.assertIn(' README ', run.output)
745   def test_502_zzdir_big_test2_zip(self):
746     """ run zzdir-big on test2.zip """
747     zipfile = "test2.zip"
748     getfile = "test2.zip"
749     exe = self.bins("unzzip-big")
750     run = shell("{exe} -l {getfile} ".format(**locals()))
751     self.assertIn(' file.01 ', run.output)
752     self.assertIn(' file.22 ', run.output)
753     self.assertIn(' file.99 ', run.output)
754   def test_503_zzdir_big_test3_zip(self):
755     """ run zzdir-big on test3.zip  """
756     zipfile = "test3.zip"
757     getfile = "test3.zip"
758     exe = self.bins("unzzip-big")
759     run = shell("{exe} -l {getfile} ".format(**locals()))
760     self.assertIn(' file.001 ', run.output)
761     self.assertIn(' file.222 ', run.output)
762     self.assertIn(' file.999 ', run.output)
763   def test_504_zzdir_big_test4_zip(self):
764     """ run zzdir-big on test4.zip """
765     zipfile = "test4.zip"
766     getfile = "test4.zip"
767     exe = self.bins("unzzip-big")
768     run = shell("{exe} -l {getfile} ".format(**locals()))
769     self.assertIn(' file.001 ', run.output)
770     self.assertIn(' file.222 ', run.output)
771     self.assertIn(' file.999 ', run.output)
772   def test_510_zzdir_mem_test0_zip(self):
773     """ run zzdir-mem on test0.zip  """
774     zipfile = "test0.zip"
775     getfile = "test0.zip"
776     exe = self.bins("unzzip-mem")
777     run = shell("{exe} -l {getfile} ".format(**locals()))
778     self.assertIn(' README ', run.output)
779     self.assertIn(' deflated ', run.output)
780     self.assertLess(len(run.output), 30)
781   def test_511_zzdir_mem_test1_zip(self):
782     """ run zzdir-mem on test1.zip  """
783     zipfile = "test1.zip"
784     getfile = "test1.zip"
785     exe = self.bins("unzzip-mem")
786     run = shell("{exe} -l {getfile} ".format(**locals()))
787     self.assertIn(' file.1 ', run.output)
788     self.assertIn(' file.2 ', run.output)
789     self.assertIn(' file.9 ', run.output)
790     self.assertIn(' README ', run.output)
791     self.assertIn(' deflated ', run.output)
792     self.assertIn(' stored ', run.output)
793   def test_512_zzdir_mem_test2_zip(self):
794     """ run zzdir-mem on test2.zip """
795     zipfile = "test2.zip"
796     getfile = "test2.zip"
797     exe = self.bins("unzzip-mem")
798     run = shell("{exe} -l {getfile} ".format(**locals()))
799     self.assertIn(' file.01 ', run.output)
800     self.assertIn(' file.22 ', run.output)
801     self.assertIn(' file.99 ', run.output)
802     self.assertIn(' deflated ', run.output)
803     self.assertIn(' stored ', run.output)
804   def test_513_zzdir_mem_test3_zip(self):
805     """ run zzdir-mem on test3.zip  """
806     zipfile = "test3.zip"
807     getfile = "test3.zip"
808     exe = self.bins("unzzip-mem")
809     run = shell("{exe} -l {getfile} ".format(**locals()))
810     self.assertIn(' file.001 ', run.output)
811     self.assertIn(' file.222 ', run.output)
812     self.assertIn(' file.999 ', run.output)
813     self.assertIn(' deflated ', run.output)
814     self.assertIn(' stored ', run.output)
815   def test_514_zzdir_mem_test4_zip(self):
816     """ run zzdir-mem on test4.zip """
817     zipfile = "test4.zip"
818     getfile = "test4.zip"
819     exe = self.bins("unzzip-mem")
820     run = shell("{exe} -l {getfile} ".format(**locals()))
821     self.assertIn(' file.001 ', run.output)
822     self.assertIn(' file.222 ', run.output)
823     self.assertIn(' file.999 ', run.output)
824     self.assertNotIn(' deflated ', run.output)
825     self.assertIn(' stored ', run.output)
826   def test_520_zzdir_mix_test0_zip(self):
827     """ run zzdir-mix on test0.zip  """
828     self.skipTest("todo")
829     zipfile = "test0.zip"
830     getfile = "test0.zip"
831     exe = self.bins("unzzip-mix")
832     run = shell("{exe} -l {getfile} ".format(**locals()))
833     self.assertIn(' README ', run.output)
834     self.assertIn(' deflated ', run.output)
835     self.assertLess(len(run.output), 30)
836   def test_540_zzdir_zap_test0_zip(self):
837     """ run zzdir-zap on test0.zip  """
838     zipfile = "test0.zip"
839     getfile = "test0.zip"
840     exe = self.bins("unzzip")
841     run = shell("{exe} -l {getfile} ".format(**locals()))
842     self.assertIn(' README ', run.output)
843     self.assertIn(' deflated ', run.output)
844     self.assertLess(len(run.output), 30)
845   def test_541_zzdir_zap_test1_zip(self):
846     """ run zzdir-zap on test1.zip  """
847     zipfile = "test1.zip"
848     getfile = "test1.zip"
849     exe = self.bins("unzzip")
850     run = shell("{exe} -l {getfile} ".format(**locals()))
851     self.assertIn(' file.1 ', run.output)
852     self.assertIn(' file.2 ', run.output)
853     self.assertIn(' file.9 ', run.output)
854     self.assertIn(' README ', run.output)
855     self.assertIn(' deflated ', run.output)
856     self.assertIn(' stored ', run.output)
857   def test_542_zzdir_zap_test2_zip(self):
858     """ run zzdir-zap on test2.zip """
859     zipfile = "test2.zip"
860     getfile = "test2.zip"
861     exe = self.bins("unzzip")
862     run = shell("{exe} -l {getfile} ".format(**locals()))
863     self.assertIn(' file.01 ', run.output)
864     self.assertIn(' file.22 ', run.output)
865     self.assertIn(' file.99 ', run.output)
866     self.assertIn(' deflated ', run.output)
867     self.assertIn(' stored ', run.output)
868   def test_543_zzdir_zap_test3_zip(self):
869     """ run zzdir-zap on test3.zip  """
870     zipfile = "test3.zip"
871     getfile = "test3.zip"
872     exe = self.bins("unzzip")
873     run = shell("{exe} -l {getfile} ".format(**locals()))
874     self.assertIn(' file.001 ', run.output)
875     self.assertIn(' file.222 ', run.output)
876     self.assertIn(' file.999 ', run.output)
877     self.assertIn(' deflated ', run.output)
878     self.assertIn(' stored ', run.output)
879   def test_544_zzdir_zap_test4_zip(self):
880     """ run zzdir-zap on test4.zip """
881     zipfile = "test4.zip"
882     getfile = "test4.zip"
883     exe = self.bins("unzzip")
884     run = shell("{exe} -l {getfile} ".format(**locals()))
885     self.assertIn(' file.001 ', run.output)
886     self.assertIn(' file.222 ', run.output)
887     self.assertIn(' file.999 ', run.output)
888     self.assertNotIn(' deflated ', run.output)
889     self.assertIn(' stored ', run.output)
890
891   def test_900_make_test1w_zip(self):
892     """ create a test1w.zip using zzip/write functions. """
893     exe=self.bins("zzip")
894     run = shell("{exe} --version".format(**locals()))
895     if "- NO -" in run.output:
896         self.skipTest("- NO -D_ZZIP_ENABLE_WRITE")
897         return
898     zipfile="test1w.zip"
899     tmpdir="test1w.tmp"
900     exe=self.bins("zzip")
901     for i in [1,2,3,4,5,6,7,8,9]:
902        filename = os.path.join(tmpdir,"file.%i" % i)
903        filetext = "file-%i\n" % i
904        self.mkfile(filename, filetext)
905     filename = os.path.join(tmpdir,"README")
906     filetext = self.readme()
907     self.mkfile(filename, filetext)
908     try: os.remove(zipfile)
909     except: pass
910     shell("../{exe} ../{zipfile} ??*.* README".format(**locals()), cwd=tmpdir)
911     self.assertGreater(os.path.getsize(zipfile), 10)
912
913
914
915
916 if __name__ == "__main__":
917   import optparse
918   _o = optparse.OptionParser("%prog [options] test_xxx")
919   _o.add_option("-b", "--topsrcdir", metavar="DIR", default=topsrcdir,
920     help="path to the top srcdir / unpack directory [%default]")
921   _o.add_option("-t", "--testdatadir", metavar="DIR", default=testdatadir,
922     help="path where temporary testdata is created [%default]")
923   _o.add_option("-Z", "--mkzip", metavar="EXE", default=mkzip,
924     help="name or path to zip.exe for *.zip creation [%default]")
925   _o.add_option("-U", "--unzip", metavar="EXE", default=unzip,
926     help="name or path to unzip.exe to unpack *.zip [%default]")
927   _o.add_option("-E", "--exeext", metavar="EXT", default=exeext,
928     help="the executable extension (automake $(EXEEXT)) [%default]")
929   _o.add_option("--xmlresults", action="store_true", default=False,
930     help="print output in junit xml testresult format [%default]")
931   _o.add_option("-v", "--verbose", action="count", default=0,
932     help="increase logging output [%default]")
933   opt, args = _o.parse_args()
934   logging.basicConfig(level = logging.WARNING - 10 * opt.verbose)
935   topsrcdir = opt.topsrcdir
936   testdatdir = opt.testdatadir
937   mkzip = opt.mkzip
938   unzip = opt.unzip
939   exeext = opt.exeext
940   if not args: args += [ "test_" ]
941   suite = unittest.TestSuite()
942   for arg in args:
943     for classname in sorted(list(globals())):
944       if not classname.endswith("Test"):
945         continue
946       testclass = globals()[classname]
947       for method in sorted(dir(testclass)):
948         if "*" not in arg: arg += "*"
949         if arg.startswith("_"): arg = arg[1:]
950         if matches(method, arg):
951           suite.addTest(testclass(method))
952   # TextTestRunner(verbosity=opt.verbose).run(suite)
953   if opt.xmlresults:
954     import xmlrunner
955     Runner = xmlrunner.XMLTestRunner
956     Runner(xmlresults).run(suite)
957   else:
958     Runner = unittest.TextTestRunner
959     Runner(verbosity=opt.verbose).run(suite)
960