MCPcopy Index your code
hub / github.com/python/cpython / zip_test

Method zip_test

Lib/test/test_zipfile/test_core.py:85–138  ·  view source on GitHub ↗
(self, f, compression, compresslevel=None)

Source from the content-addressed store, hash-verified

83 f.write(line)
84
85 def zip_test(self, f, compression, compresslevel=None):
86 self.make_test_archive(f, compression, compresslevel)
87
88 # Read the ZIP archive
89 with zipfile.ZipFile(f, "r", compression) as zipfp:
90 self.assertEqual(zipfp.read(TESTFN), self.data)
91 self.assertEqual(zipfp.read("another.name"), self.data)
92 self.assertEqual(zipfp.read("strfile"), self.data)
93
94 # Print the ZIP directory
95 fp = io.StringIO()
96 zipfp.printdir(file=fp)
97 directory = fp.getvalue()
98 lines = directory.splitlines()
99 self.assertEqual(len(lines), 5) # Number of files + header
100
101 self.assertIn('File Name', lines[0])
102 self.assertIn('Modified', lines[0])
103 self.assertIn('Size', lines[0])
104
105 fn, date, time_, size = lines[1].split()
106 self.assertEqual(fn, 'another.name')
107 self.assertTrue(time.strptime(date, '%Y-%m-%d'))
108 self.assertTrue(time.strptime(time_, '%H:%M:%S'))
109 self.assertEqual(size, str(len(self.data)))
110
111 # Check the namelist
112 names = zipfp.namelist()
113 self.assertEqual(len(names), 4)
114 self.assertIn(TESTFN, names)
115 self.assertIn("another.name", names)
116 self.assertIn("strfile", names)
117 self.assertIn("written-open-w", names)
118
119 # Check infolist
120 infos = zipfp.infolist()
121 names = [i.filename for i in infos]
122 self.assertEqual(len(names), 4)
123 self.assertIn(TESTFN, names)
124 self.assertIn("another.name", names)
125 self.assertIn("strfile", names)
126 self.assertIn("written-open-w", names)
127 for i in infos:
128 self.assertEqual(i.file_size, len(self.data))
129
130 # check getinfo
131 for nm in (TESTFN, "another.name", "strfile", "written-open-w"):
132 info = zipfp.getinfo(nm)
133 self.assertEqual(info.filename, nm)
134 self.assertEqual(info.file_size, len(self.data))
135
136 # Check that testzip thinks the archive is ok
137 # (it returns None if all contents could be read properly)
138 self.assertIsNone(zipfp.testzip())
139
140 def test_basic(self):
141 for f in get_files(self):

Callers 2

test_basicMethod · 0.95

Calls 15

make_test_archiveMethod · 0.95
getvalueMethod · 0.95
strFunction · 0.85
printdirMethod · 0.80
assertInMethod · 0.80
assertTrueMethod · 0.80
infolistMethod · 0.80
assertIsNoneMethod · 0.80
testzipMethod · 0.80
assertEqualMethod · 0.45
readMethod · 0.45
splitlinesMethod · 0.45

Tested by

no test coverage detected