Debian Codegraph @

rpython/rlib/test/test_rzipfile.py

raw symbols SCIP
1 import py
2
3 from rpython.rlib.rzipfile import RZipFile
4 from rpython.tool.udir import udir
5 from zipfile import ZIP_STORED, ZIP_DEFLATED, ZipInfo, ZipFile
6 from rpython.rtyper.test.tool import BaseRtypingTest
7 from rpython.rlib import clibffi # for side effect of testing lib_c_name on win32
8 import os
9 import time
10
11 try:
12 from rpython.rlib import rzlib
13 except CompilationError as e:
14 py.test.skip("zlib not installed: %s " % (e, ))
15
16 class BaseTestRZipFile(BaseRtypingTest):
17
18 def setup_class(cls):
19 tmpdir = udir.ensure('zipimport_%s' % cls.__name__, dir=1)
20 zipname = str(tmpdir.join("somezip.zip"))
21 cls.zipname = zipname
22 zipfile = ZipFile(zipname, "w", compression=cls.compression)
23 cls.year = time.localtime(time.time())[0]
24 zipfile.writestr("one", "stuff\n")
25 zipfile.writestr("dir" + os.path.sep + "two", "otherstuff")
26 # Value selected to produce a CRC32 which is negative if
27 # interpreted as a signed 32 bit integer. This exercises the
28 # masking behavior necessary on 64 bit platforms.
29 zipfile.writestr("three", "hello, world")
30 zipfile.close()
31
32 def test_rzipfile(self):
33 zipname = self.zipname
34 year = self.year
35 compression = self.compression
36 def one():
37 rzip = RZipFile(zipname, "r", compression)
38 info = rzip.getinfo('one')
39 return (info.date_time[0] == year and
40 rzip.read('one') == 'stuff\n' and
41 rzip.read('three') == 'hello, world')
42
43 assert one()
44 assert self.interpret(one, [])
45
46 class TestRZipFile(BaseTestRZipFile):
47 compression = ZIP_STORED
48
49 class TestRZipFileCompressed(BaseTestRZipFile):
50 compression = ZIP_DEFLATED