File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff 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 \
You can’t perform that action at this time.
0 commit comments