Issue #20549: Use specific asserts in mailbox, smtplib and poplib tests.
This commit is contained in:
parent
528bed8e4a
commit
79b6f17d70
|
@ -138,7 +138,7 @@ class TestMailbox(TestBase):
|
|||
msg = self._box.get(key0)
|
||||
self.assertEqual(msg['from'], 'foo')
|
||||
self.assertEqual(msg.get_payload(), '0\n')
|
||||
self.assertIs(self._box.get('foo'), None)
|
||||
self.assertIsNone(self._box.get('foo'))
|
||||
self.assertFalse(self._box.get('foo', False))
|
||||
self._box.close()
|
||||
self._box = self._factory(self._path, factory=rfc822.Message)
|
||||
|
@ -249,8 +249,7 @@ class TestMailbox(TestBase):
|
|||
count = 0
|
||||
for value in returned_values:
|
||||
self.assertEqual(value['from'], 'foo')
|
||||
self.assertTrue(int(value.get_payload()) < repetitions,
|
||||
(value.get_payload(), repetitions))
|
||||
self.assertLess(int(value.get_payload()), repetitions)
|
||||
count += 1
|
||||
self.assertEqual(len(values), count)
|
||||
|
||||
|
@ -664,7 +663,7 @@ class TestMaildir(TestMailbox, unittest.TestCase):
|
|||
"tmp")),
|
||||
"File in wrong location: '%s'" % head)
|
||||
match = pattern.match(tail)
|
||||
self.assertTrue(match is not None, "Invalid file name: '%s'" % tail)
|
||||
self.assertIsNotNone(match, "Invalid file name: '%s'" % tail)
|
||||
groups = match.groups()
|
||||
if previous_groups is not None:
|
||||
self.assertGreaterEqual(int(groups[0]), int(previous_groups[0]),
|
||||
|
@ -674,22 +673,22 @@ class TestMaildir(TestMailbox, unittest.TestCase):
|
|||
self.assertGreaterEqual(int(groups[1]), int(previous_groups[1]),
|
||||
"Non-monotonic milliseconds: '%s' before '%s'" %
|
||||
(previous_groups[1], groups[1]))
|
||||
self.assertTrue(int(groups[2]) == pid,
|
||||
self.assertEqual(int(groups[2]), pid,
|
||||
"Process ID mismatch: '%s' should be '%s'" %
|
||||
(groups[2], pid))
|
||||
self.assertTrue(int(groups[3]) == int(previous_groups[3]) + 1,
|
||||
self.assertEqual(int(groups[3]), int(previous_groups[3]) + 1,
|
||||
"Non-sequential counter: '%s' before '%s'" %
|
||||
(previous_groups[3], groups[3]))
|
||||
self.assertTrue(groups[4] == hostname,
|
||||
self.assertEqual(groups[4], hostname,
|
||||
"Host name mismatch: '%s' should be '%s'" %
|
||||
(groups[4], hostname))
|
||||
previous_groups = groups
|
||||
tmp_file.write(_sample_message)
|
||||
tmp_file.seek(0)
|
||||
self.assertTrue(tmp_file.read() == _sample_message)
|
||||
self.assertEqual(tmp_file.read(), _sample_message)
|
||||
tmp_file.close()
|
||||
file_count = len(os.listdir(os.path.join(self._path, "tmp")))
|
||||
self.assertTrue(file_count == repetitions,
|
||||
self.assertEqual(file_count, repetitions,
|
||||
"Wrong file count: '%s' should be '%s'" %
|
||||
(file_count, repetitions))
|
||||
|
||||
|
@ -1240,7 +1239,7 @@ class TestMessage(TestBase, unittest.TestCase):
|
|||
self.assertIsInstance(msg, self._factory)
|
||||
self.assertEqual(msg.keys(), [])
|
||||
self.assertFalse(msg.is_multipart())
|
||||
self.assertEqual(msg.get_payload(), None)
|
||||
self.assertIsNone(msg.get_payload())
|
||||
|
||||
def test_initialize_incorrectly(self):
|
||||
# Initialize with invalid argument
|
||||
|
@ -1313,7 +1312,7 @@ class TestMaildirMessage(TestMessage, unittest.TestCase):
|
|||
# Use get_date() and set_date()
|
||||
msg = mailbox.MaildirMessage(_sample_message)
|
||||
diff = msg.get_date() - time.time()
|
||||
self.assertTrue(abs(diff) < 60, diff)
|
||||
self.assertLess(abs(diff), 60, diff)
|
||||
msg.set_date(0.0)
|
||||
self.assertEqual(msg.get_date(), 0.0)
|
||||
|
||||
|
@ -1388,8 +1387,9 @@ class _TestMboxMMDFMessage:
|
|||
# Check contents of "From " line
|
||||
if sender is None:
|
||||
sender = "MAILER-DAEMON"
|
||||
self.assertTrue(re.match(sender + r" \w{3} \w{3} [\d ]\d [\d ]\d:\d{2}:"
|
||||
r"\d{2} \d{4}", msg.get_from()))
|
||||
self.assertIsNotNone(re.match(
|
||||
sender + r" \w{3} \w{3} [\d ]\d [\d ]\d:\d{2}:\d{2} \d{4}",
|
||||
msg.get_from()))
|
||||
|
||||
|
||||
class TestMboxMessage(_TestMboxMMDFMessage, TestMessage):
|
||||
|
@ -1463,7 +1463,7 @@ class TestBabylMessage(TestMessage, unittest.TestCase):
|
|||
msg = mailbox.BabylMessage(_sample_message)
|
||||
visible = msg.get_visible()
|
||||
self.assertEqual(visible.keys(), [])
|
||||
self.assertIs(visible.get_payload(), None)
|
||||
self.assertIsNone(visible.get_payload())
|
||||
visible['User-Agent'] = 'FooBar 1.0'
|
||||
visible['X-Whatever'] = 'Blah'
|
||||
self.assertEqual(msg.get_visible().keys(), [])
|
||||
|
@ -1472,10 +1472,10 @@ class TestBabylMessage(TestMessage, unittest.TestCase):
|
|||
self.assertEqual(visible.keys(), ['User-Agent', 'X-Whatever'])
|
||||
self.assertEqual(visible['User-Agent'], 'FooBar 1.0')
|
||||
self.assertEqual(visible['X-Whatever'], 'Blah')
|
||||
self.assertIs(visible.get_payload(), None)
|
||||
self.assertIsNone(visible.get_payload())
|
||||
msg.update_visible()
|
||||
self.assertEqual(visible.keys(), ['User-Agent', 'X-Whatever'])
|
||||
self.assertIs(visible.get_payload(), None)
|
||||
self.assertIsNone(visible.get_payload())
|
||||
visible = msg.get_visible()
|
||||
self.assertEqual(visible.keys(), ['User-Agent', 'Date', 'From', 'To',
|
||||
'Subject'])
|
||||
|
@ -1971,43 +1971,43 @@ class MaildirTestCase(unittest.TestCase):
|
|||
# Make sure the boxes attribute actually gets set.
|
||||
self.mbox = mailbox.Maildir(test_support.TESTFN)
|
||||
#self.assertTrue(hasattr(self.mbox, "boxes"))
|
||||
#self.assertTrue(len(self.mbox.boxes) == 0)
|
||||
self.assertIs(self.mbox.next(), None)
|
||||
self.assertIs(self.mbox.next(), None)
|
||||
#self.assertEqual(len(self.mbox.boxes), 0)
|
||||
self.assertIsNone(self.mbox.next())
|
||||
self.assertIsNone(self.mbox.next())
|
||||
|
||||
def test_nonempty_maildir_cur(self):
|
||||
self.createMessage("cur")
|
||||
self.mbox = mailbox.Maildir(test_support.TESTFN)
|
||||
#self.assertTrue(len(self.mbox.boxes) == 1)
|
||||
#self.assertEqual(len(self.mbox.boxes), 1)
|
||||
msg = self.mbox.next()
|
||||
self.assertIsNot(msg, None)
|
||||
self.assertIsNotNone(msg)
|
||||
msg.fp.close()
|
||||
self.assertIs(self.mbox.next(), None)
|
||||
self.assertIs(self.mbox.next(), None)
|
||||
self.assertIsNone(self.mbox.next())
|
||||
self.assertIsNone(self.mbox.next())
|
||||
|
||||
def test_nonempty_maildir_new(self):
|
||||
self.createMessage("new")
|
||||
self.mbox = mailbox.Maildir(test_support.TESTFN)
|
||||
#self.assertTrue(len(self.mbox.boxes) == 1)
|
||||
#self.assertEqual(len(self.mbox.boxes), 1)
|
||||
msg = self.mbox.next()
|
||||
self.assertIsNot(msg, None)
|
||||
self.assertIsNotNone(msg)
|
||||
msg.fp.close()
|
||||
self.assertIs(self.mbox.next(), None)
|
||||
self.assertIs(self.mbox.next(), None)
|
||||
self.assertIsNone(self.mbox.next())
|
||||
self.assertIsNone(self.mbox.next())
|
||||
|
||||
def test_nonempty_maildir_both(self):
|
||||
self.createMessage("cur")
|
||||
self.createMessage("new")
|
||||
self.mbox = mailbox.Maildir(test_support.TESTFN)
|
||||
#self.assertTrue(len(self.mbox.boxes) == 2)
|
||||
#self.assertEqual(len(self.mbox.boxes), 2)
|
||||
msg = self.mbox.next()
|
||||
self.assertIsNot(msg, None)
|
||||
self.assertIsNotNone(msg)
|
||||
msg.fp.close()
|
||||
msg = self.mbox.next()
|
||||
self.assertIsNot(msg, None)
|
||||
self.assertIsNotNone(msg)
|
||||
msg.fp.close()
|
||||
self.assertIs(self.mbox.next(), None)
|
||||
self.assertIs(self.mbox.next(), None)
|
||||
self.assertIsNone(self.mbox.next())
|
||||
self.assertIsNone(self.mbox.next())
|
||||
|
||||
def test_unix_mbox(self):
|
||||
### should be better!
|
||||
|
|
|
@ -308,7 +308,7 @@ class TestTimeouts(TestCase):
|
|||
serv.close()
|
||||
|
||||
def testTimeoutDefault(self):
|
||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||
self.assertIsNone(socket.getdefaulttimeout())
|
||||
socket.setdefaulttimeout(30)
|
||||
try:
|
||||
pop = poplib.POP3(HOST, self.port)
|
||||
|
@ -318,13 +318,13 @@ class TestTimeouts(TestCase):
|
|||
pop.sock.close()
|
||||
|
||||
def testTimeoutNone(self):
|
||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||
self.assertIsNone(socket.getdefaulttimeout())
|
||||
socket.setdefaulttimeout(30)
|
||||
try:
|
||||
pop = poplib.POP3(HOST, self.port, timeout=None)
|
||||
finally:
|
||||
socket.setdefaulttimeout(None)
|
||||
self.assertTrue(pop.sock.gettimeout() is None)
|
||||
self.assertIsNone(pop.sock.gettimeout())
|
||||
pop.sock.close()
|
||||
|
||||
def testTimeoutValue(self):
|
||||
|
|
|
@ -77,7 +77,7 @@ class GeneralTests(unittest.TestCase):
|
|||
smtp.close()
|
||||
|
||||
def testTimeoutDefault(self):
|
||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||
self.assertIsNone(socket.getdefaulttimeout())
|
||||
socket.setdefaulttimeout(30)
|
||||
try:
|
||||
smtp = smtplib.SMTP(HOST, self.port)
|
||||
|
@ -87,13 +87,13 @@ class GeneralTests(unittest.TestCase):
|
|||
smtp.close()
|
||||
|
||||
def testTimeoutNone(self):
|
||||
self.assertTrue(socket.getdefaulttimeout() is None)
|
||||
self.assertIsNone(socket.getdefaulttimeout())
|
||||
socket.setdefaulttimeout(30)
|
||||
try:
|
||||
smtp = smtplib.SMTP(HOST, self.port, timeout=None)
|
||||
finally:
|
||||
socket.setdefaulttimeout(None)
|
||||
self.assertTrue(smtp.sock.gettimeout() is None)
|
||||
self.assertIsNone(smtp.sock.gettimeout())
|
||||
smtp.close()
|
||||
|
||||
def testTimeoutValue(self):
|
||||
|
|
Loading…
Reference in New Issue