blob: 6b3b12eccc299d4ecf872ef389337441d725f401 [file] [log] [blame]
Guido van Rossum7d9ea502003-02-03 20:45:52 +00001import unittest
2from test import test_support
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +00003import zlib
Andrew M. Kuchling9a0f98e2001-02-21 02:17:01 +00004import random
Andrew M. Kuchling9a0f98e2001-02-21 02:17:01 +00005
Guido van Rossum7d9ea502003-02-03 20:45:52 +00006# print test_support.TESTFN
Andrew M. Kuchling9a0f98e2001-02-21 02:17:01 +00007
Guido van Rossum7d9ea502003-02-03 20:45:52 +00008def getbuf():
9 # This was in the original. Avoid non-repeatable sources.
10 # Left here (unused) in case something wants to be done with it.
11 import imp
12 try:
13 t = imp.find_module('test_zlib')
14 file = t[0]
15 except ImportError:
16 file = open(__file__)
17 buf = file.read() * 8
18 file.close()
19 return buf
Andrew M. Kuchling9a0f98e2001-02-21 02:17:01 +000020
Tim Peters0009c4e2001-02-21 07:29:48 +000021
Andrew M. Kuchling9a0f98e2001-02-21 02:17:01 +000022
Guido van Rossum7d9ea502003-02-03 20:45:52 +000023class ChecksumTestCase(unittest.TestCase):
24 # checksum test cases
25 def test_crc32start(self):
26 self.assertEqual(zlib.crc32(""), zlib.crc32("", 0))
Andrew M. Kuchlingbb7e8002005-11-22 15:32:28 +000027 self.assert_(zlib.crc32("abc", 0xffffffff))
Andrew M. Kuchlingfcfc8d52001-08-10 15:50:11 +000028
Guido van Rossum7d9ea502003-02-03 20:45:52 +000029 def test_crc32empty(self):
30 self.assertEqual(zlib.crc32("", 0), 0)
31 self.assertEqual(zlib.crc32("", 1), 1)
32 self.assertEqual(zlib.crc32("", 432), 432)
Andrew M. Kuchling9a0f98e2001-02-21 02:17:01 +000033
Guido van Rossum7d9ea502003-02-03 20:45:52 +000034 def test_adler32start(self):
35 self.assertEqual(zlib.adler32(""), zlib.adler32("", 1))
Andrew M. Kuchlingbb7e8002005-11-22 15:32:28 +000036 self.assert_(zlib.adler32("abc", 0xffffffff))
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +000037
Guido van Rossum7d9ea502003-02-03 20:45:52 +000038 def test_adler32empty(self):
39 self.assertEqual(zlib.adler32("", 0), 0)
40 self.assertEqual(zlib.adler32("", 1), 1)
41 self.assertEqual(zlib.adler32("", 432), 432)
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +000042
Guido van Rossum7d9ea502003-02-03 20:45:52 +000043 def assertEqual32(self, seen, expected):
44 # 32-bit values masked -- checksums on 32- vs 64- bit machines
45 # This is important if bit 31 (0x08000000L) is set.
46 self.assertEqual(seen & 0x0FFFFFFFFL, expected & 0x0FFFFFFFFL)
47
48 def test_penguins(self):
49 self.assertEqual32(zlib.crc32("penguin", 0), 0x0e5c1a120L)
50 self.assertEqual32(zlib.crc32("penguin", 1), 0x43b6aa94)
51 self.assertEqual32(zlib.adler32("penguin", 0), 0x0bcf02f6)
52 self.assertEqual32(zlib.adler32("penguin", 1), 0x0bd602f7)
53
54 self.assertEqual(zlib.crc32("penguin"), zlib.crc32("penguin", 0))
55 self.assertEqual(zlib.adler32("penguin"),zlib.adler32("penguin",1))
56
57
58
59class ExceptionTestCase(unittest.TestCase):
60 # make sure we generate some expected errors
61 def test_bigbits(self):
62 # specifying total bits too large causes an error
63 self.assertRaises(zlib.error,
64 zlib.compress, 'ERROR', zlib.MAX_WBITS + 1)
65
66 def test_badcompressobj(self):
67 # verify failure on building compress object with bad params
Neil Schemenauer94afd3e2004-06-05 19:02:52 +000068 self.assertRaises(ValueError, zlib.compressobj, 1, zlib.DEFLATED, 0)
Guido van Rossum7d9ea502003-02-03 20:45:52 +000069
70 def test_baddecompressobj(self):
71 # verify failure on building decompress object with bad params
72 self.assertRaises(ValueError, zlib.decompressobj, 0)
73
Gregory P. Smithf6234672008-04-09 00:26:44 +000074 def test_decompressobj_badflush(self):
75 # verify failure on calling decompressobj.flush with bad params
76 self.assertRaises(ValueError, zlib.decompressobj().flush, 0)
77 self.assertRaises(ValueError, zlib.decompressobj().flush, -1)
78
Guido van Rossum7d9ea502003-02-03 20:45:52 +000079
80
81class CompressTestCase(unittest.TestCase):
82 # Test compression in one go (whole message compression)
83 def test_speech(self):
Neil Schemenauer6412b122004-06-05 19:34:28 +000084 x = zlib.compress(HAMLET_SCENE)
85 self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
Guido van Rossum7d9ea502003-02-03 20:45:52 +000086
87 def test_speech128(self):
Neil Schemenauer6412b122004-06-05 19:34:28 +000088 # compress more data
89 data = HAMLET_SCENE * 128
Guido van Rossum7d9ea502003-02-03 20:45:52 +000090 x = zlib.compress(data)
91 self.assertEqual(zlib.decompress(x), data)
92
Guido van Rossum7d9ea502003-02-03 20:45:52 +000093
94
95
96class CompressObjectTestCase(unittest.TestCase):
97 # Test compression object
Guido van Rossum7d9ea502003-02-03 20:45:52 +000098 def test_pair(self):
Neil Schemenauer6412b122004-06-05 19:34:28 +000099 # straightforward compress/decompress objects
100 data = HAMLET_SCENE * 128
101 co = zlib.compressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000102 x1 = co.compress(data)
103 x2 = co.flush()
104 self.assertRaises(zlib.error, co.flush) # second flush should not work
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000105 dco = zlib.decompressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000106 y1 = dco.decompress(x1 + x2)
107 y2 = dco.flush()
108 self.assertEqual(data, y1 + y2)
109
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000110 def test_compressoptions(self):
111 # specify lots of options to compressobj()
112 level = 2
113 method = zlib.DEFLATED
114 wbits = -12
115 memlevel = 9
116 strategy = zlib.Z_FILTERED
117 co = zlib.compressobj(level, method, wbits, memlevel, strategy)
Neil Schemenauer6412b122004-06-05 19:34:28 +0000118 x1 = co.compress(HAMLET_SCENE)
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000119 x2 = co.flush()
120 dco = zlib.decompressobj(wbits)
121 y1 = dco.decompress(x1 + x2)
122 y2 = dco.flush()
Neil Schemenauer6412b122004-06-05 19:34:28 +0000123 self.assertEqual(HAMLET_SCENE, y1 + y2)
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000124
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000125 def test_compressincremental(self):
126 # compress object in steps, decompress object as one-shot
Neil Schemenauer6412b122004-06-05 19:34:28 +0000127 data = HAMLET_SCENE * 128
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000128 co = zlib.compressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000129 bufs = []
130 for i in range(0, len(data), 256):
131 bufs.append(co.compress(data[i:i+256]))
132 bufs.append(co.flush())
133 combuf = ''.join(bufs)
134
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000135 dco = zlib.decompressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000136 y1 = dco.decompress(''.join(bufs))
137 y2 = dco.flush()
138 self.assertEqual(data, y1 + y2)
139
Neil Schemenauer6412b122004-06-05 19:34:28 +0000140 def test_decompinc(self, flush=False, source=None, cx=256, dcx=64):
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000141 # compress object in steps, decompress object in steps
Neil Schemenauer6412b122004-06-05 19:34:28 +0000142 source = source or HAMLET_SCENE
143 data = source * 128
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000144 co = zlib.compressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000145 bufs = []
Neil Schemenauer6412b122004-06-05 19:34:28 +0000146 for i in range(0, len(data), cx):
147 bufs.append(co.compress(data[i:i+cx]))
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000148 bufs.append(co.flush())
149 combuf = ''.join(bufs)
150
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000151 self.assertEqual(data, zlib.decompress(combuf))
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000152
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000153 dco = zlib.decompressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000154 bufs = []
Neil Schemenauer6412b122004-06-05 19:34:28 +0000155 for i in range(0, len(combuf), dcx):
156 bufs.append(dco.decompress(combuf[i:i+dcx]))
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000157 self.assertEqual('', dco.unconsumed_tail, ########
158 "(A) uct should be '': not %d long" %
Neil Schemenauer6412b122004-06-05 19:34:28 +0000159 len(dco.unconsumed_tail))
160 if flush:
161 bufs.append(dco.flush())
162 else:
163 while True:
164 chunk = dco.decompress('')
165 if chunk:
166 bufs.append(chunk)
167 else:
168 break
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000169 self.assertEqual('', dco.unconsumed_tail, ########
Neil Schemenauer6412b122004-06-05 19:34:28 +0000170 "(B) uct should be '': not %d long" %
171 len(dco.unconsumed_tail))
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000172 self.assertEqual(data, ''.join(bufs))
173 # Failure means: "decompressobj with init options failed"
174
Neil Schemenauer6412b122004-06-05 19:34:28 +0000175 def test_decompincflush(self):
176 self.test_decompinc(flush=True)
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000177
Neil Schemenauer6412b122004-06-05 19:34:28 +0000178 def test_decompimax(self, source=None, cx=256, dcx=64):
179 # compress in steps, decompress in length-restricted steps
180 source = source or HAMLET_SCENE
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000181 # Check a decompression object with max_length specified
Neil Schemenauer6412b122004-06-05 19:34:28 +0000182 data = source * 128
183 co = zlib.compressobj()
184 bufs = []
185 for i in range(0, len(data), cx):
186 bufs.append(co.compress(data[i:i+cx]))
187 bufs.append(co.flush())
188 combuf = ''.join(bufs)
189 self.assertEqual(data, zlib.decompress(combuf),
190 'compressed data failure')
191
192 dco = zlib.decompressobj()
193 bufs = []
194 cb = combuf
195 while cb:
196 #max_length = 1 + len(cb)//10
197 chunk = dco.decompress(cb, dcx)
198 self.failIf(len(chunk) > dcx,
199 'chunk too big (%d>%d)' % (len(chunk), dcx))
200 bufs.append(chunk)
201 cb = dco.unconsumed_tail
202 bufs.append(dco.flush())
203 self.assertEqual(data, ''.join(bufs), 'Wrong data retrieved')
204
205 def test_decompressmaxlen(self, flush=False):
206 # Check a decompression object with max_length specified
207 data = HAMLET_SCENE * 128
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000208 co = zlib.compressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000209 bufs = []
210 for i in range(0, len(data), 256):
211 bufs.append(co.compress(data[i:i+256]))
212 bufs.append(co.flush())
213 combuf = ''.join(bufs)
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000214 self.assertEqual(data, zlib.decompress(combuf),
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000215 'compressed data failure')
216
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000217 dco = zlib.decompressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000218 bufs = []
219 cb = combuf
220 while cb:
Guido van Rossumf3594102003-02-27 18:39:18 +0000221 max_length = 1 + len(cb)//10
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000222 chunk = dco.decompress(cb, max_length)
223 self.failIf(len(chunk) > max_length,
224 'chunk too big (%d>%d)' % (len(chunk),max_length))
225 bufs.append(chunk)
226 cb = dco.unconsumed_tail
Neil Schemenauer6412b122004-06-05 19:34:28 +0000227 if flush:
228 bufs.append(dco.flush())
229 else:
230 while chunk:
231 chunk = dco.decompress('', max_length)
232 self.failIf(len(chunk) > max_length,
233 'chunk too big (%d>%d)' % (len(chunk),max_length))
234 bufs.append(chunk)
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000235 self.assertEqual(data, ''.join(bufs), 'Wrong data retrieved')
236
Neil Schemenauer6412b122004-06-05 19:34:28 +0000237 def test_decompressmaxlenflush(self):
238 self.test_decompressmaxlen(flush=True)
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000239
240 def test_maxlenmisc(self):
241 # Misc tests of max_length
Neil Schemenauer94afd3e2004-06-05 19:02:52 +0000242 dco = zlib.decompressobj()
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000243 self.assertRaises(ValueError, dco.decompress, "", -1)
244 self.assertEqual('', dco.unconsumed_tail)
245
246 def test_flushes(self):
247 # Test flush() with the various options, using all the
248 # different levels in order to provide more variations.
249 sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH']
250 sync_opt = [getattr(zlib, opt) for opt in sync_opt
251 if hasattr(zlib, opt)]
Neil Schemenauer6412b122004-06-05 19:34:28 +0000252 data = HAMLET_SCENE * 8
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000253
254 for sync in sync_opt:
255 for level in range(10):
256 obj = zlib.compressobj( level )
257 a = obj.compress( data[:3000] )
258 b = obj.flush( sync )
259 c = obj.compress( data[3000:] )
260 d = obj.flush()
261 self.assertEqual(zlib.decompress(''.join([a,b,c,d])),
262 data, ("Decompress failed: flush "
263 "mode=%i, level=%i") % (sync, level))
264 del obj
265
266 def test_odd_flush(self):
267 # Test for odd flushing bugs noted in 2.0, and hopefully fixed in 2.1
268 import random
269
270 if hasattr(zlib, 'Z_SYNC_FLUSH'):
271 # Testing on 17K of "random" data
272
273 # Create compressor and decompressor objects
Neil Schemenauer6412b122004-06-05 19:34:28 +0000274 co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000275 dco = zlib.decompressobj()
276
277 # Try 17K of data
278 # generate random data stream
279 try:
280 # In 2.3 and later, WichmannHill is the RNG of the bug report
281 gen = random.WichmannHill()
282 except AttributeError:
283 try:
284 # 2.2 called it Random
285 gen = random.Random()
286 except AttributeError:
287 # others might simply have a single RNG
288 gen = random
289 gen.seed(1)
290 data = genblock(1, 17 * 1024, generator=gen)
291
292 # compress, sync-flush, and decompress
293 first = co.compress(data)
294 second = co.flush(zlib.Z_SYNC_FLUSH)
295 expanded = dco.decompress(first + second)
296
297 # if decompressed data is different from the input data, choke.
298 self.assertEqual(expanded, data, "17K random source doesn't match")
299
Andrew M. Kuchling3b585b32004-12-28 20:10:48 +0000300 def test_empty_flush(self):
301 # Test that calling .flush() on unused objects works.
302 # (Bug #1083110 -- calling .flush() on decompress objects
303 # caused a core dump.)
304
305 co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
306 self.failUnless(co.flush()) # Returns a zlib header
307 dco = zlib.decompressobj()
308 self.assertEqual(dco.flush(), "") # Returns nothing
Tim Peters5a9fb3c2005-01-07 16:01:32 +0000309
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000310 if hasattr(zlib.compressobj(), "copy"):
311 def test_compresscopy(self):
312 # Test copying a compression object
313 data0 = HAMLET_SCENE
314 data1 = HAMLET_SCENE.swapcase()
315 c0 = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
316 bufs0 = []
317 bufs0.append(c0.compress(data0))
Georg Brandl8d3342b2006-05-16 07:38:27 +0000318
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000319 c1 = c0.copy()
320 bufs1 = bufs0[:]
Georg Brandl8d3342b2006-05-16 07:38:27 +0000321
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000322 bufs0.append(c0.compress(data0))
323 bufs0.append(c0.flush())
324 s0 = ''.join(bufs0)
Georg Brandl8d3342b2006-05-16 07:38:27 +0000325
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000326 bufs1.append(c1.compress(data1))
327 bufs1.append(c1.flush())
328 s1 = ''.join(bufs1)
Georg Brandl8d3342b2006-05-16 07:38:27 +0000329
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000330 self.assertEqual(zlib.decompress(s0),data0+data0)
331 self.assertEqual(zlib.decompress(s1),data0+data1)
Georg Brandl8d3342b2006-05-16 07:38:27 +0000332
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000333 def test_badcompresscopy(self):
334 # Test copying a compression object in an inconsistent state
335 c = zlib.compressobj()
336 c.compress(HAMLET_SCENE)
337 c.flush()
338 self.assertRaises(ValueError, c.copy)
Georg Brandl8d3342b2006-05-16 07:38:27 +0000339
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000340 if hasattr(zlib.decompressobj(), "copy"):
341 def test_decompresscopy(self):
342 # Test copying a decompression object
343 data = HAMLET_SCENE
344 comp = zlib.compress(data)
Georg Brandl8d3342b2006-05-16 07:38:27 +0000345
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000346 d0 = zlib.decompressobj()
347 bufs0 = []
348 bufs0.append(d0.decompress(comp[:32]))
Georg Brandl8d3342b2006-05-16 07:38:27 +0000349
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000350 d1 = d0.copy()
351 bufs1 = bufs0[:]
Georg Brandl8d3342b2006-05-16 07:38:27 +0000352
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000353 bufs0.append(d0.decompress(comp[32:]))
354 s0 = ''.join(bufs0)
Georg Brandl8d3342b2006-05-16 07:38:27 +0000355
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000356 bufs1.append(d1.decompress(comp[32:]))
357 s1 = ''.join(bufs1)
Georg Brandl8d3342b2006-05-16 07:38:27 +0000358
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000359 self.assertEqual(s0,s1)
360 self.assertEqual(s0,data)
Georg Brandl8d3342b2006-05-16 07:38:27 +0000361
Neal Norwitz6e73aaa2006-06-12 03:33:09 +0000362 def test_baddecompresscopy(self):
363 # Test copying a compression object in an inconsistent state
364 data = zlib.compress(HAMLET_SCENE)
365 d = zlib.decompressobj()
366 d.decompress(data)
367 d.flush()
368 self.assertRaises(ValueError, d.copy)
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000369
370def genblock(seed, length, step=1024, generator=random):
371 """length-byte stream of random data from a seed (in step-byte blocks)."""
372 if seed is not None:
373 generator.seed(seed)
374 randint = generator.randint
375 if length < step or step < 2:
376 step = length
377 blocks = []
378 for i in range(0, length, step):
379 blocks.append(''.join([chr(randint(0,255))
380 for x in range(step)]))
381 return ''.join(blocks)[:length]
382
383
384
385def choose_lines(source, number, seed=None, generator=random):
386 """Return a list of number lines randomly chosen from the source"""
387 if seed is not None:
388 generator.seed(seed)
389 sources = source.split('\n')
390 return [generator.choice(sources) for n in range(number)]
391
392
393
Neil Schemenauer6412b122004-06-05 19:34:28 +0000394HAMLET_SCENE = """
Fred Drake004d5e62000-10-23 17:22:08 +0000395LAERTES
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +0000396
397 O, fear me not.
398 I stay too long: but here my father comes.
399
400 Enter POLONIUS
401
402 A double blessing is a double grace,
403 Occasion smiles upon a second leave.
404
Fred Drake004d5e62000-10-23 17:22:08 +0000405LORD POLONIUS
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +0000406
407 Yet here, Laertes! aboard, aboard, for shame!
408 The wind sits in the shoulder of your sail,
409 And you are stay'd for. There; my blessing with thee!
410 And these few precepts in thy memory
411 See thou character. Give thy thoughts no tongue,
412 Nor any unproportioned thought his act.
413 Be thou familiar, but by no means vulgar.
414 Those friends thou hast, and their adoption tried,
415 Grapple them to thy soul with hoops of steel;
416 But do not dull thy palm with entertainment
417 Of each new-hatch'd, unfledged comrade. Beware
418 Of entrance to a quarrel, but being in,
419 Bear't that the opposed may beware of thee.
420 Give every man thy ear, but few thy voice;
421 Take each man's censure, but reserve thy judgment.
422 Costly thy habit as thy purse can buy,
423 But not express'd in fancy; rich, not gaudy;
424 For the apparel oft proclaims the man,
425 And they in France of the best rank and station
426 Are of a most select and generous chief in that.
427 Neither a borrower nor a lender be;
428 For loan oft loses both itself and friend,
429 And borrowing dulls the edge of husbandry.
430 This above all: to thine ownself be true,
431 And it must follow, as the night the day,
432 Thou canst not then be false to any man.
433 Farewell: my blessing season this in thee!
434
Fred Drake004d5e62000-10-23 17:22:08 +0000435LAERTES
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +0000436
437 Most humbly do I take my leave, my lord.
438
Fred Drake004d5e62000-10-23 17:22:08 +0000439LORD POLONIUS
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +0000440
441 The time invites you; go; your servants tend.
442
Fred Drake004d5e62000-10-23 17:22:08 +0000443LAERTES
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +0000444
445 Farewell, Ophelia; and remember well
446 What I have said to you.
447
Fred Drake004d5e62000-10-23 17:22:08 +0000448OPHELIA
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +0000449
450 'Tis in my memory lock'd,
451 And you yourself shall keep the key of it.
452
Fred Drake004d5e62000-10-23 17:22:08 +0000453LAERTES
Jeremy Hylton6eb4b6a1997-08-15 15:59:43 +0000454
455 Farewell.
456"""
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000457
458
459def test_main():
Walter Dörwald21d3a322003-05-01 17:45:56 +0000460 test_support.run_unittest(
461 ChecksumTestCase,
462 ExceptionTestCase,
463 CompressTestCase,
464 CompressObjectTestCase
465 )
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000466
467if __name__ == "__main__":
468 test_main()
469
470def test(tests=''):
471 if not tests: tests = 'o'
Walter Dörwald21d3a322003-05-01 17:45:56 +0000472 testcases = []
473 if 'k' in tests: testcases.append(ChecksumTestCase)
474 if 'x' in tests: testcases.append(ExceptionTestCase)
475 if 'c' in tests: testcases.append(CompressTestCase)
476 if 'o' in tests: testcases.append(CompressObjectTestCase)
477 test_support.run_unittest(*testcases)
Guido van Rossum7d9ea502003-02-03 20:45:52 +0000478
479if False:
480 import sys
481 sys.path.insert(1, '/Py23Src/python/dist/src/Lib/test')
482 import test_zlib as tz
483 ts, ut = tz.test_support, tz.unittest
484 su = ut.TestSuite()
485 su.addTest(ut.makeSuite(tz.CompressTestCase))
486 ts.run_suite(su)