diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-05 18:55:13 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-05 18:55:13 (GMT) |
commit | cfc2c7bb8672e859240df093871e0ab3fb106f8c (patch) | |
tree | 0d9abdecc26d2b21a27d224dc8235e09e2816c4c | |
parent | dd9d64eb53991a165f5f34b8270bcda28981dc2d (diff) | |
download | cpython-cfc2c7bb8672e859240df093871e0ab3fb106f8c.zip cpython-cfc2c7bb8672e859240df093871e0ab3fb106f8c.tar.gz cpython-cfc2c7bb8672e859240df093871e0ab3fb106f8c.tar.bz2 |
Issue #19920: Added tests for TarFile.list(). Based on patch by Vajrasky Kok.
-rw-r--r-- | Lib/test/test_tarfile.py | 77 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
2 files changed, 79 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index e817f61..ff3265f 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -158,6 +158,80 @@ class UstarReadTest(ReadTest): self._test_fileobj_link("symtype2", "ustar/regtype") +class ListTest(ReadTest, unittest.TestCase): + + # Override setUp to use default encoding (UTF-8) + def setUp(self): + self.tar = tarfile.open(self.tarname, mode=self.mode) + + def test_list(self): + with test_support.captured_stdout() as t: + self.tar.list(verbose=False) + out = t.getvalue() + self.assertIn('ustar/conttype', out) + self.assertIn('ustar/regtype', out) + self.assertIn('ustar/lnktype', out) + self.assertIn('ustar' + ('/12345' * 40) + '67/longname', out) + self.assertIn('./ustar/linktest2/symtype', out) + self.assertIn('./ustar/linktest2/lnktype', out) + # Make sure it puts trailing slash for directory + self.assertIn('ustar/dirtype/', out) + self.assertIn('ustar/dirtype-with-size/', out) + # Make sure it is able to print non-ASCII characters + self.assertIn('ustar/umlauts-' + '\xc4\xd6\xdc\xe4\xf6\xfc\xdf', out) + self.assertIn('misc/regtype-hpux-signed-chksum-' + '\xc4\xd6\xdc\xe4\xf6\xfc\xdf', out) + self.assertIn('misc/regtype-old-v7-signed-chksum-' + '\xc4\xd6\xdc\xe4\xf6\xfc\xdf', out) + # Make sure it prints files separated by one newline without any + # 'ls -l'-like accessories if verbose flag is not being used + # ... + # ustar/conttype + # ustar/regtype + # ... + self.assertRegexpMatches(out, r'ustar/conttype ?\r?\n' + r'ustar/regtype ?\r?\n') + # Make sure it does not print the source of link without verbose flag + self.assertNotIn('link to', out) + self.assertNotIn('->', out) + + def test_list_verbose(self): + with test_support.captured_stdout() as t: + self.tar.list(verbose=True) + out = t.getvalue() + # Make sure it prints files separated by one newline with 'ls -l'-like + # accessories if verbose flag is being used + # ... + # ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/conttype + # ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/regtype + # ... + self.assertRegexpMatches(out, (r'-rw-r--r-- tarfile/tarfile\s+7011 ' + r'\d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d ' + r'ustar/\w+type ?\r?\n') * 2) + # Make sure it prints the source of link with verbose flag + self.assertIn('ustar/symtype -> regtype', out) + self.assertIn('./ustar/linktest2/symtype -> ../linktest1/regtype', out) + self.assertIn('./ustar/linktest2/lnktype link to ' + './ustar/linktest1/regtype', out) + self.assertIn('gnu' + ('/123' * 125) + '/longlink link to gnu' + + ('/123' * 125) + '/longname', out) + self.assertIn('pax' + ('/123' * 125) + '/longlink link to pax' + + ('/123' * 125) + '/longname', out) + + +class GzipListTest(ListTest): + tarname = gzipname + mode = "r:gz" + taropen = tarfile.TarFile.gzopen + + +class Bz2ListTest(ListTest): + tarname = bz2name + mode = "r:bz2" + taropen = tarfile.TarFile.bz2open + + class CommonReadTest(ReadTest): def test_empty_tarfile(self): @@ -1646,6 +1720,7 @@ def test_main(): MemberReadTest, GNUReadTest, PaxReadTest, + ListTest, WriteTest, StreamWriteTest, GNUWriteTest, @@ -1677,6 +1752,7 @@ def test_main(): GzipMiscReadTest, GzipUstarReadTest, GzipStreamReadTest, + GzipListTest, GzipWriteTest, GzipStreamWriteTest, ] @@ -1691,6 +1767,7 @@ def test_main(): Bz2MiscReadTest, Bz2UstarReadTest, Bz2StreamReadTest, + Bz2ListTest, Bz2WriteTest, Bz2StreamWriteTest, Bz2PartialReadTest, @@ -224,6 +224,8 @@ IDLE Tests ----- +- Issue #19920: Added tests for TarFile.list(). Based on patch by Vajrasky Kok. + - Issue #19990: Added tests for the imghdr module. Based on patch by Claudiu Popa. |