summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-06-30 23:06:06 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-06-30 23:06:06 (GMT)
commitc9c0f201fed21efcf669dbbf5f923eaf0eeb1db9 (patch)
tree6350dab0b481e6de307dc4e043c6230f463a9ca7 /Lib/test/test_tarfile.py
parent98d23f2e065713ccfbc07d9a0b65f737a212bfb5 (diff)
downloadcpython-c9c0f201fed21efcf669dbbf5f923eaf0eeb1db9.zip
cpython-c9c0f201fed21efcf669dbbf5f923eaf0eeb1db9.tar.gz
cpython-c9c0f201fed21efcf669dbbf5f923eaf0eeb1db9.tar.bz2
convert old fail* assertions to assert*
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r--Lib/test/test_tarfile.py86
1 files changed, 43 insertions, 43 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index f4c0035..76390c7 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -57,7 +57,7 @@ class UstarReadTest(ReadTest):
tarinfo = self.tar.getmember("ustar/regtype")
fobj = self.tar.extractfile(tarinfo)
data = fobj.read()
- self.assert_((len(data), md5sum(data)) == (tarinfo.size, md5_regtype),
+ self.assertTrue((len(data), md5sum(data)) == (tarinfo.size, md5_regtype),
"regular file extraction failed")
def test_fileobj_readlines(self):
@@ -68,11 +68,11 @@ class UstarReadTest(ReadTest):
lines1 = fobj1.readlines()
lines2 = fobj2.readlines()
- self.assert_(lines1 == lines2,
+ self.assertTrue(lines1 == lines2,
"fileobj.readlines() failed")
- self.assert_(len(lines2) == 114,
+ self.assertTrue(len(lines2) == 114,
"fileobj.readlines() failed")
- self.assert_(lines2[83] == \
+ self.assertTrue(lines2[83] == \
"I will gladly admit that Python is not the fastest running scripting language.\n",
"fileobj.readlines() failed")
@@ -83,7 +83,7 @@ class UstarReadTest(ReadTest):
fobj2 = self.tar.extractfile(tarinfo)
lines1 = fobj1.readlines()
lines2 = list(io.TextIOWrapper(fobj2))
- self.assert_(lines1 == lines2,
+ self.assertTrue(lines1 == lines2,
"fileobj.__iter__() failed")
def test_fileobj_seek(self):
@@ -109,12 +109,12 @@ class UstarReadTest(ReadTest):
self.assertEqual(2048, fobj.tell(),
"seek() to positive relative position failed")
s = fobj.read(10)
- self.assert_(s == data[2048:2058],
+ self.assertTrue(s == data[2048:2058],
"read() after seek failed")
fobj.seek(0, 2)
self.assertEqual(tarinfo.size, fobj.tell(),
"seek() to file's end failed")
- self.assert_(fobj.read() == b"",
+ self.assertTrue(fobj.read() == b"",
"read() at file's end did not return empty string")
fobj.seek(-tarinfo.size, 2)
self.assertEqual(0, fobj.tell(),
@@ -123,13 +123,13 @@ class UstarReadTest(ReadTest):
s1 = fobj.readlines()
fobj.seek(512)
s2 = fobj.readlines()
- self.assert_(s1 == s2,
+ self.assertTrue(s1 == s2,
"readlines() after seek failed")
fobj.seek(0)
self.assertEqual(len(fobj.readline()), fobj.tell(),
"tell() after readline() failed")
fobj.seek(512)
- self.assert_(len(fobj.readline()) + 512 == fobj.tell(),
+ self.assertTrue(len(fobj.readline()) + 512 == fobj.tell(),
"tell() after seek() and readline() failed")
fobj.seek(0)
line = fobj.readline()
@@ -204,7 +204,7 @@ class MiscReadTest(ReadTest):
# Old V7 tars create directory members using an AREGTYPE
# header with a "/" appended to the filename field.
tarinfo = self.tar.getmember("misc/dirtype-old-v7")
- self.assert_(tarinfo.type == tarfile.DIRTYPE,
+ self.assertTrue(tarinfo.type == tarfile.DIRTYPE,
"v7 dirtype failed")
def test_xstar_type(self):
@@ -218,15 +218,15 @@ class MiscReadTest(ReadTest):
def test_check_members(self):
for tarinfo in self.tar:
- self.assert_(int(tarinfo.mtime) == 0o7606136617,
+ self.assertTrue(int(tarinfo.mtime) == 0o7606136617,
"wrong mtime for %s" % tarinfo.name)
if not tarinfo.name.startswith("ustar/"):
continue
- self.assert_(tarinfo.uname == "tarfile",
+ self.assertTrue(tarinfo.uname == "tarfile",
"wrong uname for %s" % tarinfo.name)
def test_find_members(self):
- self.assert_(self.tar.getmembers()[-1].name == "misc/eof",
+ self.assertTrue(self.tar.getmembers()[-1].name == "misc/eof",
"could not find all members")
def test_extract_hardlink(self):
@@ -275,7 +275,7 @@ class StreamReadTest(ReadTest):
tarinfo = self.tar.next() # get "regtype" (can't use getmember)
fobj = self.tar.extractfile(tarinfo)
data = fobj.read()
- self.assert_((len(data), md5sum(data)) == (tarinfo.size, md5_regtype),
+ self.assertTrue((len(data), md5sum(data)) == (tarinfo.size, md5_regtype),
"regular file extraction failed")
def test_provoke_stream_error(self):
@@ -292,7 +292,7 @@ class StreamReadTest(ReadTest):
t2 = tar2.next()
if t1 is None:
break
- self.assert_(t2 is not None, "stream.next() failed.")
+ self.assertTrue(t2 is not None, "stream.next() failed.")
if t2.islnk() or t2.issym():
self.assertRaises(tarfile.StreamError, tar2.extractfile, t2)
@@ -302,7 +302,7 @@ class StreamReadTest(ReadTest):
v2 = tar2.extractfile(t2)
if v1 is None:
continue
- self.assert_(v2 is not None, "stream.extractfile() failed")
+ self.assertTrue(v2 is not None, "stream.extractfile() failed")
self.assertEqual(v1.read(), v2.read(), "stream extraction failed")
tar1.close()
@@ -364,7 +364,7 @@ class MemberReadTest(ReadTest):
def _test_member(self, tarinfo, chksum=None, **kwargs):
if chksum is not None:
- self.assert_(md5sum(self.tar.extractfile(tarinfo).read()) == chksum,
+ self.assertTrue(md5sum(self.tar.extractfile(tarinfo).read()) == chksum,
"wrong md5sum for %s" % tarinfo.name)
kwargs["mtime"] = 0o7606136617
@@ -375,7 +375,7 @@ class MemberReadTest(ReadTest):
kwargs["uname"] = "tarfile"
kwargs["gname"] = "tarfile"
for k, v in kwargs.items():
- self.assert_(getattr(tarinfo, k) == v,
+ self.assertTrue(getattr(tarinfo, k) == v,
"wrong value in %s field of %s" % (k, tarinfo.name))
def test_find_regtype(self):
@@ -424,7 +424,7 @@ class MemberReadTest(ReadTest):
def test_find_ustar_longname(self):
name = "ustar/" + "12345/" * 39 + "1234567/longname"
- self.assert_(name in self.tar.getnames())
+ self.assertTrue(name in self.tar.getnames())
def test_find_regtype_oldv7(self):
tarinfo = self.tar.getmember("misc/regtype-old-v7")
@@ -445,7 +445,7 @@ class LongnameTest(ReadTest):
tarinfo = self.tar.getmember(longname)
except KeyError:
self.fail("longname not found")
- self.assert_(tarinfo.type != tarfile.DIRTYPE, "read longname as dirtype")
+ self.assertTrue(tarinfo.type != tarfile.DIRTYPE, "read longname as dirtype")
def test_read_longlink(self):
longname = self.subdir + "/" + "123/" * 125 + "longname"
@@ -454,7 +454,7 @@ class LongnameTest(ReadTest):
tarinfo = self.tar.getmember(longlink)
except KeyError:
self.fail("longlink not found")
- self.assert_(tarinfo.linkname == longname, "linkname wrong")
+ self.assertTrue(tarinfo.linkname == longname, "linkname wrong")
def test_truncated_longname(self):
longname = self.subdir + "/" + "123/" * 125 + "longname"
@@ -534,7 +534,7 @@ class WriteTestBase(unittest.TestCase):
tar = tarfile.open(fileobj=fobj, mode=self.mode)
tar.addfile(tarfile.TarInfo("foo"))
tar.close()
- self.assert_(fobj.closed is False, "external fileobjs must never closed")
+ self.assertTrue(fobj.closed is False, "external fileobjs must never closed")
class WriteTest(WriteTestBase):
@@ -553,7 +553,7 @@ class WriteTest(WriteTestBase):
tar.close()
tar = tarfile.open(tmpname)
- self.assert_(tar.getnames()[0] == name,
+ self.assertTrue(tar.getnames()[0] == name,
"failed to store 100 char filename")
tar.close()
@@ -566,7 +566,7 @@ class WriteTest(WriteTestBase):
fobj.close()
tar.add(path)
tar.close()
- self.assert_(os.path.getsize(tmpname) > 0,
+ self.assertTrue(os.path.getsize(tmpname) > 0,
"tarfile is empty")
# The test_*_size tests test for bug #1167128.
@@ -627,16 +627,16 @@ class WriteTest(WriteTestBase):
dstname = os.path.abspath(tmpname)
tar = tarfile.open(tmpname, self.mode)
- self.assert_(tar.name == dstname, "archive name must be absolute")
+ self.assertTrue(tar.name == dstname, "archive name must be absolute")
tar.add(dstname)
- self.assert_(tar.getnames() == [], "added the archive to itself")
+ self.assertTrue(tar.getnames() == [], "added the archive to itself")
cwd = os.getcwd()
os.chdir(TEMPDIR)
tar.add(dstname)
os.chdir(cwd)
- self.assert_(tar.getnames() == [], "added the archive to itself")
+ self.assertTrue(tar.getnames() == [], "added the archive to itself")
def test_exclude(self):
tempdir = os.path.join(TEMPDIR, "exclude")
@@ -677,14 +677,14 @@ class StreamWriteTest(WriteTestBase):
dec = bz2.BZ2Decompressor()
data = open(tmpname, "rb").read()
data = dec.decompress(data)
- self.assert_(len(dec.unused_data) == 0,
+ self.assertTrue(len(dec.unused_data) == 0,
"found trailing data")
else:
fobj = open(tmpname, "rb")
data = fobj.read()
fobj.close()
- self.assert_(data.count(b"\0") == tarfile.RECORDSIZE,
+ self.assertTrue(data.count(b"\0") == tarfile.RECORDSIZE,
"incorrect zero padding")
@@ -724,14 +724,14 @@ class GNUWriteTest(unittest.TestCase):
v1 = self._calc_size(name, link)
v2 = tar.offset
- self.assert_(v1 == v2, "GNU longname/longlink creation failed")
+ self.assertTrue(v1 == v2, "GNU longname/longlink creation failed")
tar.close()
tar = tarfile.open(tmpname)
member = tar.next()
- self.failIf(member is None, "unable to read longname member")
- self.assert_(tarinfo.name == member.name and \
+ self.assertFalse(member is None, "unable to read longname member")
+ self.assertTrue(tarinfo.name == member.name and \
tarinfo.linkname == member.linkname, \
"unable to read longname member")
@@ -791,18 +791,18 @@ class HardlinkTest(unittest.TestCase):
# The same name will be added as a REGTYPE every
# time regardless of st_nlink.
tarinfo = self.tar.gettarinfo(self.foo)
- self.assert_(tarinfo.type == tarfile.REGTYPE,
+ self.assertTrue(tarinfo.type == tarfile.REGTYPE,
"add file as regular failed")
def test_add_hardlink(self):
tarinfo = self.tar.gettarinfo(self.bar)
- self.assert_(tarinfo.type == tarfile.LNKTYPE,
+ self.assertTrue(tarinfo.type == tarfile.LNKTYPE,
"add file as hardlink failed")
def test_dereference_hardlink(self):
self.tar.dereference = True
tarinfo = self.tar.gettarinfo(self.bar)
- self.assert_(tarinfo.type == tarfile.REGTYPE,
+ self.assertTrue(tarinfo.type == tarfile.REGTYPE,
"dereferencing hardlink failed")
@@ -822,10 +822,10 @@ class PaxWriteTest(GNUWriteTest):
tar = tarfile.open(tmpname)
if link:
l = tar.getmembers()[0].linkname
- self.assert_(link == l, "PAX longlink creation failed")
+ self.assertTrue(link == l, "PAX longlink creation failed")
else:
n = tar.getmembers()[0].name
- self.assert_(name == n, "PAX longname creation failed")
+ self.assertTrue(name == n, "PAX longname creation failed")
def test_pax_global_header(self):
pax_headers = {
@@ -847,8 +847,8 @@ class PaxWriteTest(GNUWriteTest):
# Test if all the fields are strings.
for key, val in tar.pax_headers.items():
- self.assert_(type(key) is not bytes)
- self.assert_(type(val) is not bytes)
+ self.assertTrue(type(key) is not bytes)
+ self.assertTrue(type(val) is not bytes)
if key in tarfile.PAX_NUMBER_FIELDS:
try:
tarfile.PAX_NUMBER_FIELDS[key](val)
@@ -916,10 +916,10 @@ class UstarUnicodeTest(unittest.TestCase):
def test_unicode_argument(self):
tar = tarfile.open(tarname, "r", encoding="iso8859-1", errors="strict")
for t in tar:
- self.assert_(type(t.name) is str)
- self.assert_(type(t.linkname) is str)
- self.assert_(type(t.uname) is str)
- self.assert_(type(t.gname) is str)
+ self.assertTrue(type(t.name) is str)
+ self.assertTrue(type(t.linkname) is str)
+ self.assertTrue(type(t.uname) is str)
+ self.assertTrue(type(t.gname) is str)
tar.close()
def test_uname_unicode(self):