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