@@ -80,7 +80,6 @@ def test_fileobj_readlines(self):
8080 "I will gladly admit that Python is not the fastest running scripting language.\n " ,
8181 "fileobj.readlines() failed" )
8282
83- #FIX: This now breaks with the new tarfile
8483 def test_fileobj_iter (self ):
8584 self .tar .extract ("ustar/regtype" , TEMPDIR )
8685 tarinfo = self .tar .getmember ("ustar/regtype" )
@@ -238,18 +237,17 @@ def test_list_verbose(self):
238237 self .assertIn ('pax' + ('/123' * 125 ) + '/longlink link to pax' +
239238 ('/123' * 125 ) + '/longname' , out )
240239
241- #INFO: Python2 list doesn't have the "members" functionality, so can't test
242- # def test_list_members(self):
243- # tio = io.TextIOWrapper(io.BytesIO(), 'ascii', newline='\n')
244- # def members(tar):
245- # for tarinfo in tar.getmembers():
246- # if 'reg' in tarinfo.name:
247- # yield tarinfo
248- # with support.swap_attr(sys, 'stdout', tio):
249- # self.tar.list(verbose=False, members=members(self.tar))
250- # out = tio.detach().getvalue()
251- # self.assertIn(b'ustar/regtype', out)
252- # self.assertNotIn(b'ustar/conttype', out)
240+ def test_list_members (self ):
241+ tio = io .BufferedRandom (io .BytesIO ())
242+ def members (tar ):
243+ for tarinfo in tar .getmembers ():
244+ if 'reg' in tarinfo .name :
245+ yield tarinfo
246+ with support .swap_attr (sys , 'stdout' , tio ):
247+ self .tar .list (verbose = False , members = members (self .tar ))
248+ out = tio .detach ().getvalue ()
249+ self .assertIn (b'ustar/regtype' , out )
250+ self .assertNotIn (b'ustar/conttype' , out )
253251
254252class GzipListTest (ListTest ):
255253 tarname = gzipname
@@ -577,9 +575,6 @@ def test_parallel_iteration(self):
577575 self .assertEqual (m1 .offset , m2 .offset )
578576 self .assertEqual (m1 .name , m2 .name )
579577
580- # FIX: Brought in from Python3.6
581- # class MiscReadTest(MiscReadTestBase, unittest.TestCase):
582- # test_fail_comp = None
583578
584579class StreamReadTest (CommonReadTest ):
585580
@@ -622,13 +617,6 @@ def test_compare_members(self):
622617 finally :
623618 tar1 .close ()
624619
625- # FIX: Brought in from Python3.6
626- # class GzipStreamReadTest(GzipTest, StreamReadTest):
627- # pass
628- #
629- #INFO: Python2 doesn't have LZMA
630- # class LzmaStreamReadTest(LzmaTest, StreamReadTest):
631- # pass
632620
633621class TarTest :
634622 tarname = tarname
@@ -640,6 +628,7 @@ class TarTest:
640628 def mode (self ):
641629 return self .prefix + self .suffix
642630
631+
643632class DetectReadTest (TarTest , unittest .TestCase ):
644633 def _testfunc_file (self , name , mode ):
645634 try :
@@ -710,10 +699,6 @@ def test_detect_stream_bz2(self):
710699 self ._testfunc_file (tmpname , "r|*" )
711700
712701
713- #INFO: Python2 doesn't have LZMA
714- # class LzmaDetectReadTest(LzmaTest, DetectReadTest):
715- # pass
716-
717702class MemberReadTest (ReadTest ):
718703
719704 def _test_member (self , tarinfo , chksum = None , ** kwargs ):
@@ -916,6 +901,7 @@ def test_eof_marker(self):
916901 t .size = tarfile .RECORDSIZE - tarfile .BLOCKSIZE
917902 tar .addfile (t , io .BytesIO (b"a" * t .size ))
918903
904+
919905class WriteTest (WriteTestBase ):
920906
921907 mode = "w:"
@@ -984,6 +970,7 @@ def test_directory_size(self):
984970 finally :
985971 os .rmdir (path )
986972
973+
987974 #INFO: We don't have pathlib on Python2, not sure if we can really test this
988975 # def test_gettarinfo_pathlike_name(self):
989976 # with tarfile.open(tmpname, self.mode) as tar:
@@ -996,8 +983,7 @@ def test_directory_size(self):
996983 # self.assertEqual(tarinfo.name, tarinfo2.name)
997984 # self.assertEqual(tarinfo.size, 3)
998985
999- @unittest .skipUnless (hasattr (os , "link" ),
1000- "Missing hardlink implementation" )
986+ @unittest .skipUnless (hasattr (os , "link" ),"Missing hardlink implementation" )
1001987 def test_link_size (self ):
1002988 if hasattr (os , "link" ):
1003989 link = os .path .join (TEMPDIR , "link" )
@@ -1546,21 +1532,6 @@ def test_create_taropen_pathlike_name(self):
15461532 self .assertIn ('spameggs42' , names [0 ])
15471533
15481534
1549- #FIX: Brought in by Python3.6
1550- # class GzipCreateTest(GzipTest, CreateTest):
1551- # pass
1552-
1553-
1554- #FIX: Brought in by Python3.6
1555- # class Bz2CreateTest(Bz2Test, CreateTest):
1556- # pass
1557-
1558-
1559- #INFO: Python2 doesn't have LZMA
1560- # class LzmaCreateTest(LzmaTest, CreateTest):
1561- # pass
1562-
1563-
15641535class CreateWithXModeTest (CreateTest ):
15651536
15661537 prefix = "x"
@@ -1813,12 +1784,29 @@ def test_error_handler_utf8(self):
18131784 self .assertEqual (tar .getnames ()[0 ], "\xe4 \xf6 \xfc /" + u"\u20ac " .encode ("utf8" ))
18141785
18151786 # FIX: Came in on Python3.6
1816- # # Test the same as above for the 100 bytes link field.
1817- # def test_unicode_link1(self):
1818- # self._test_ustar_link("0123456789" * 10)
1819- # self._test_ustar_link("0123456789" * 10 + "0", ValueError)
1820- # self._test_ustar_link("0123456789" * 9 + "01234567\xff")
1821- # self._test_ustar_link("0123456789" * 9 + "012345678\xff", ValueError)
1787+ # Test the same as above for the 100 bytes link field.
1788+ def test_unicode_link1 (self ):
1789+ self ._test_ustar_link ("0123456789" * 10 )
1790+ self ._test_ustar_link ("0123456789" * 10 + "0" , ValueError )
1791+ # Use a two byte UTF-8 character
1792+ self ._test_ustar_link ("0123456789" * 9 + "01234567\303 \251 " )
1793+ self ._test_ustar_link ("0123456789" * 9 + "012345678\303 \251 " , ValueError )
1794+
1795+ def _test_ustar_link (self , name , exc = None ):
1796+ with tarfile .open (tmpname , "w" , format = 0 , encoding = "utf-8" ) as tar :
1797+ t = tarfile .TarInfo ("foo" )
1798+ t .linkname = name
1799+ if exc is None :
1800+ tar .addfile (t )
1801+ else :
1802+ self .assertRaises (exc , tar .addfile , t )
1803+
1804+ if exc is None :
1805+ with tarfile .open (tmpname , "r" , encoding = "utf-8" ) as tar :
1806+ for t in tar :
1807+ self .assertEqual (name , t .linkname )
1808+ break
1809+
18221810
18231811class AppendTest (unittest .TestCase ):
18241812 # Test append mode (cp. patch #1652681).
@@ -1979,7 +1967,7 @@ def test_char_fields(self):
19791967 "foo" )
19801968 self .assertEqual (tarfile .nts (b"foo\0 bar\0 " ),
19811969 "foo" )
1982-
1970+
19831971 def test_read_number_fields (self ):
19841972 # Issue 13158: Test if GNU tar specific base-256 number fields
19851973 # are decoded correctly.
@@ -1989,12 +1977,6 @@ def test_read_number_fields(self):
19891977 0o10000000 )
19901978 self .assertEqual (tarfile .nti (b"\x80 \x00 \x00 \x00 \xff \xff \xff \xff " ),
19911979 0xffffffff )
1992- # self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\xff"),
1993- # -1)
1994- # self.assertEqual(tarfile.nti(b"\xff\xff\xff\xff\xff\xff\xff\x9c"),
1995- # -100)
1996- # self.assertEqual(tarfile.nti(b"\xff\x00\x00\x00\x00\x00\x00\x00"),
1997- # -0x100000000000000)
19981980
19991981 # Issue 24514: Test if empty number fields are converted to zero.
20001982 self .assertEqual (tarfile .nti ("\0 " ), 0 )
0 commit comments