Skip to content

Commit 1390722

Browse files
dpgeorgeprojectgus
authored andcommitted
tarfile: Add basic unittest for tarfile.TarFile.
Tests TarFile iteration and extracting file information. Signed-off-by: Damien George <damien@micropython.org>
1 parent ab6dfdb commit 1390722

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

python-stdlib/tarfile/test.tar

20 KB
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import tarfile
2+
import unittest
3+
4+
5+
test_tar_contents = (
6+
("a", "file", 2),
7+
("b", "file", 2),
8+
("dir/", "dir", 0),
9+
("dir/c", "file", 2),
10+
("dir/d", "file", 2),
11+
("tar.tar", "file", 10240),
12+
)
13+
14+
test_sub_tar_contents = (
15+
("e", "file", 2),
16+
("f", "file", 2),
17+
)
18+
19+
20+
class TestTarFile(unittest.TestCase):
21+
def check_contents(self, expected, tf):
22+
for i, file in enumerate(tf):
23+
name, type, size = expected[i]
24+
self.assertEqual(file.name, name)
25+
self.assertEqual(file.type, type)
26+
self.assertEqual(file.size, size)
27+
28+
def test_iter(self):
29+
tf = tarfile.TarFile("test.tar")
30+
for _ in range(6):
31+
self.assertIsInstance(next(tf), tarfile.TarInfo)
32+
with self.assertRaises(StopIteration):
33+
next(tf)
34+
35+
def test_contents(self):
36+
tf = tarfile.TarFile("test.tar")
37+
self.check_contents(test_tar_contents, tf)

tools/ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function ci_package_tests_run {
9090
python-stdlib/pathlib \
9191
python-stdlib/quopri \
9292
python-stdlib/shutil \
93+
python-stdlib/tarfile \
9394
python-stdlib/tempfile \
9495
python-stdlib/time \
9596
python-stdlib/unittest/tests \

0 commit comments

Comments
 (0)