Cleanup test_tarfile, and use check_warnings.

This commit is contained in:
Florent Xicluna 2010-03-20 22:26:42 +00:00
parent db4a321fea
commit fc5f6a7f40
1 changed files with 12 additions and 9 deletions

View File

@ -69,7 +69,7 @@ class UstarReadTest(ReadTest):
"fileobj.readlines() failed") "fileobj.readlines() failed")
self.assertTrue(len(lines2) == 114, self.assertTrue(len(lines2) == 114,
"fileobj.readlines() failed") "fileobj.readlines() failed")
self.assertTrue(lines2[83] == \ self.assertTrue(lines2[83] ==
"I will gladly admit that Python is not the fastest running scripting language.\n", "I will gladly admit that Python is not the fastest running scripting language.\n",
"fileobj.readlines() failed") "fileobj.readlines() failed")
@ -707,11 +707,12 @@ class WriteTest(WriteTestBase):
name = os.path.join(tempdir, name) name = os.path.join(tempdir, name)
open(name, "wb").close() open(name, "wb").close()
def exclude(name): exclude = os.path.isfile
return os.path.isfile(name)
tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1") tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
tar.add(tempdir, arcname="empty_dir", exclude=exclude) with test_support.check_warnings(("use the filter argument",
DeprecationWarning)):
tar.add(tempdir, arcname="empty_dir", exclude=exclude)
tar.close() tar.close()
tar = tarfile.open(tmpname, "r") tar = tarfile.open(tmpname, "r")
@ -889,10 +890,12 @@ class GNUWriteTest(unittest.TestCase):
tar = tarfile.open(tmpname) tar = tarfile.open(tmpname)
member = tar.next() member = tar.next()
self.assertFalse(member is None, "unable to read longname member") self.assertIsNotNone(member,
self.assertTrue(tarinfo.name == member.name and \ "unable to read longname member")
tarinfo.linkname == member.linkname, \ self.assertEqual(tarinfo.name, member.name,
"unable to read longname member") "unable to read longname member")
self.assertEqual(tarinfo.linkname, member.linkname,
"unable to read longname member")
def test_longname_1023(self): def test_longname_1023(self):
self._test(("longnam/" * 127) + "longnam") self._test(("longnam/" * 127) + "longnam")
@ -994,7 +997,7 @@ class PaxWriteTest(GNUWriteTest):
u"test": u"äöü", u"test": u"äöü",
u"äöü": u"test"} u"äöü": u"test"}
tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, \ tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
pax_headers=pax_headers) pax_headers=pax_headers)
tar.addfile(tarfile.TarInfo("test")) tar.addfile(tarfile.TarInfo("test"))
tar.close() tar.close()