summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-08-02 15:17:49 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2015-08-02 15:17:49 +0300
commit69c9d02fc41e0aea1cf26e656fa3364b21878a63 (patch)
tree85da3611dc28860f176528981727218bbeeb09e7
parentdbea284966761c7072e6a4ffbe9198e973223607 (diff)
downloadcpython-69c9d02fc41e0aea1cf26e656fa3364b21878a63.tar.gz
Issue #20557: Use specific asserts in io tests.
-rw-r--r--Lib/test/test_bufio.py2
-rw-r--r--Lib/test/test_file.py4
-rw-r--r--Lib/test/test_fileio.py6
-rw-r--r--Lib/test/test_io.py20
-rw-r--r--Lib/test/test_memoryio.py6
5 files changed, 20 insertions, 18 deletions
diff --git a/Lib/test/test_bufio.py b/Lib/test/test_bufio.py
index 6338ad8e3c..9931c84680 100644
--- a/Lib/test/test_bufio.py
+++ b/Lib/test/test_bufio.py
@@ -34,7 +34,7 @@ class BufferSizeTest:
line = f.readline()
self.assertEqual(line, s)
line = f.readline()
- self.assertTrue(not line) # Must be at EOF
+ self.assertFalse(line) # Must be at EOF
f.close()
finally:
support.unlink(support.TESTFN)
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index d54e976143..4e392b770c 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -83,8 +83,8 @@ class AutoFileTests:
def testErrors(self):
f = self.f
self.assertEqual(f.name, TESTFN)
- self.assertTrue(not f.isatty())
- self.assertTrue(not f.closed)
+ self.assertFalse(f.isatty())
+ self.assertFalse(f.closed)
if hasattr(f, "readinto"):
self.assertRaises((OSError, TypeError), f.readinto, "")
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index fe5da695a5..a4fd20dcf2 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -113,15 +113,15 @@ class AutoFileTests(unittest.TestCase):
def testErrors(self):
f = self.f
- self.assertTrue(not f.isatty())
- self.assertTrue(not f.closed)
+ self.assertFalse(f.isatty())
+ self.assertFalse(f.closed)
#self.assertEqual(f.name, TESTFN)
self.assertRaises(ValueError, f.read, 10) # Open for reading
f.close()
self.assertTrue(f.closed)
f = _FileIO(TESTFN, 'r')
self.assertRaises(TypeError, f.readinto, "")
- self.assertTrue(not f.closed)
+ self.assertFalse(f.closed)
f.close()
self.assertTrue(f.closed)
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 416c547334..f65440624f 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -453,7 +453,7 @@ class IOTest(unittest.TestCase):
with self.open(support.TESTFN, "ab") as f:
self.assertEqual(f.tell(), 3)
with self.open(support.TESTFN, "a") as f:
- self.assertTrue(f.tell() > 0)
+ self.assertGreater(f.tell(), 0)
def test_destructor(self):
record = []
@@ -573,7 +573,7 @@ class IOTest(unittest.TestCase):
wr = weakref.ref(f)
del f
support.gc_collect()
- self.assertTrue(wr() is None, wr)
+ self.assertIsNone(wr(), wr)
with self.open(support.TESTFN, "rb") as f:
self.assertEqual(f.read(), b"abcxxx")
@@ -717,7 +717,7 @@ class CIOTest(IOTest):
del MyIO
del obj
support.gc_collect()
- self.assertTrue(wr() is None, wr)
+ self.assertIsNone(wr(), wr)
class PyIOTest(IOTest):
pass
@@ -1164,7 +1164,7 @@ class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
wr = weakref.ref(f)
del f
support.gc_collect()
- self.assertTrue(wr() is None, wr)
+ self.assertIsNone(wr(), wr)
def test_args_error(self):
# Issue #17275
@@ -1467,7 +1467,7 @@ class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
wr = weakref.ref(f)
del f
support.gc_collect()
- self.assertTrue(wr() is None, wr)
+ self.assertIsNone(wr(), wr)
with self.open(support.TESTFN, "rb") as f:
self.assertEqual(f.read(), b"123xxx")
@@ -2199,7 +2199,7 @@ class TextIOWrapperTest(unittest.TestCase):
t = self.TextIOWrapper(b, encoding="utf-8")
self.assertEqual(t.encoding, "utf-8")
t = self.TextIOWrapper(b)
- self.assertTrue(t.encoding is not None)
+ self.assertIsNotNone(t.encoding)
codecs.lookup(t.encoding)
def test_encoding_errors_reading(self):
@@ -2958,7 +2958,7 @@ class CTextIOWrapperTest(TextIOWrapperTest):
wr = weakref.ref(t)
del t
support.gc_collect()
- self.assertTrue(wr() is None, wr)
+ self.assertIsNone(wr(), wr)
with self.open(support.TESTFN, "rb") as f:
self.assertEqual(f.read(), b"456def")
@@ -3106,7 +3106,7 @@ class MiscIOTest(unittest.TestCase):
def test___all__(self):
for name in self.io.__all__:
obj = getattr(self.io, name, None)
- self.assertTrue(obj is not None, name)
+ self.assertIsNotNone(obj, name)
if name == "open":
continue
elif "error" in name.lower() or name == "UnsupportedOperation":
@@ -3196,7 +3196,7 @@ class MiscIOTest(unittest.TestCase):
wr = weakref.ref(c)
del c, b
support.gc_collect()
- self.assertTrue(wr() is None, wr)
+ self.assertIsNone(wr(), wr)
def test_abcs(self):
# Test the visible base classes are ABCs.
@@ -3348,7 +3348,7 @@ class MiscIOTest(unittest.TestCase):
received += iter(rf.read, None)
sent, received = b''.join(sent), b''.join(received)
- self.assertTrue(sent == received)
+ self.assertEqual(sent, received)
self.assertTrue(wf.closed)
self.assertTrue(rf.closed)
diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py
index 9a2461dea6..7ce95b9dd8 100644
--- a/Lib/test/test_memoryio.py
+++ b/Lib/test/test_memoryio.py
@@ -693,7 +693,8 @@ class CBytesIOTest(PyBytesIOTest):
self.assertEqual(len(state), 3)
bytearray(state[0]) # Check if state[0] supports the buffer interface.
self.assertIsInstance(state[1], int)
- self.assertTrue(isinstance(state[2], dict) or state[2] is None)
+ if state[2] is not None:
+ self.assertIsInstance(state[2], dict)
memio.close()
self.assertRaises(ValueError, memio.__getstate__)
@@ -749,7 +750,8 @@ class CStringIOTest(PyStringIOTest):
self.assertIsInstance(state[0], str)
self.assertIsInstance(state[1], str)
self.assertIsInstance(state[2], int)
- self.assertTrue(isinstance(state[3], dict) or state[3] is None)
+ if state[3] is not None:
+ self.assertIsInstance(state[3], dict)
memio.close()
self.assertRaises(ValueError, memio.__getstate__)