Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
79b6f17d
Commit
79b6f17d
authored
Feb 08, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20549: Use specific asserts in mailbox, smtplib and poplib tests.
parent
528bed8e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
38 deletions
+38
-38
Lib/test/test_mailbox.py
Lib/test/test_mailbox.py
+32
-32
Lib/test/test_poplib.py
Lib/test/test_poplib.py
+3
-3
Lib/test/test_smtplib.py
Lib/test/test_smtplib.py
+3
-3
No files found.
Lib/test/test_mailbox.py
View file @
79b6f17d
...
@@ -138,7 +138,7 @@ class TestMailbox(TestBase):
...
@@ -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
.
assertIs
None
(
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):
...
@@ -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):
...
@@ -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.assert
True(match is not None
, "
Invalid
file
name
:
'%s'" % tail)
self.assert
IsNotNone(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):
...
@@ -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.assert
True(int(groups[2]) ==
pid,
self.assert
Equal(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.assert
True(int(groups[3]) ==
int(previous_groups[3]) + 1,
self.assert
Equal(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.assert
True(groups[4] ==
hostname,
self.assert
Equal(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.assert
True(tmp_file.read() ==
_sample_message)
self.assert
Equal(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.assert
True(file_count ==
repetitions,
self.assert
Equal(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):
...
@@ -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
.
assert
Equal
(
msg
.
get_payload
(),
None
)
self
.
assert
IsNone
(
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):
...
@@ -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
.
assert
True
(
abs
(
diff
)
<
60
,
diff
)
self
.
assert
Less
(
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:
...
@@ -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):
...
@@ -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
.
assertIs
None
(
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):
...
@@ -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
.
assertIs
None
(
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
.
assertIs
None
(
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):
...
@@ -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.assert
True(len(self.mbox.boxes) ==
0)
#self.assert
Equal(len(self.mbox.boxes),
0)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
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.assert
True(len(self.mbox.boxes) ==
1)
#self.assert
Equal(len(self.mbox.boxes),
1)
msg
=
self
.
mbox
.
next
()
msg
=
self
.
mbox
.
next
()
self
.
assertIsNot
(
msg
,
None
)
self
.
assertIsNot
None
(
msg
)
msg
.
fp
.
close
()
msg
.
fp
.
close
()
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
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.assert
True(len(self.mbox.boxes) ==
1)
#self.assert
Equal(len(self.mbox.boxes),
1)
msg
=
self
.
mbox
.
next
()
msg
=
self
.
mbox
.
next
()
self
.
assertIsNot
(
msg
,
None
)
self
.
assertIsNot
None
(
msg
)
msg
.
fp
.
close
()
msg
.
fp
.
close
()
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
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.assert
True(len(self.mbox.boxes) ==
2)
#self.assert
Equal(len(self.mbox.boxes),
2)
msg
=
self
.
mbox
.
next
()
msg
=
self
.
mbox
.
next
()
self
.
assertIsNot
(
msg
,
None
)
self
.
assertIsNot
None
(
msg
)
msg
.
fp
.
close
()
msg
.
fp
.
close
()
msg
=
self
.
mbox
.
next
()
msg
=
self
.
mbox
.
next
()
self
.
assertIsNot
(
msg
,
None
)
self
.
assertIsNot
None
(
msg
)
msg
.
fp
.
close
()
msg
.
fp
.
close
()
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
def
test_unix_mbox
(
self
):
def
test_unix_mbox
(
self
):
### should be better!
### should be better!
...
...
Lib/test/test_poplib.py
View file @
79b6f17d
...
@@ -308,7 +308,7 @@ class TestTimeouts(TestCase):
...
@@ -308,7 +308,7 @@ class TestTimeouts(TestCase):
serv
.
close
()
serv
.
close
()
def
testTimeoutDefault
(
self
):
def
testTimeoutDefault
(
self
):
self
.
assert
True
(
socket
.
getdefaulttimeout
()
is
None
)
self
.
assert
IsNone
(
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):
...
@@ -318,13 +318,13 @@ class TestTimeouts(TestCase):
pop
.
sock
.
close
()
pop
.
sock
.
close
()
def
testTimeoutNone
(
self
):
def
testTimeoutNone
(
self
):
self
.
assert
True
(
socket
.
getdefaulttimeout
()
is
None
)
self
.
assert
IsNone
(
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
.
assert
True
(
pop
.
sock
.
gettimeout
()
is
None
)
self
.
assert
IsNone
(
pop
.
sock
.
gettimeout
()
)
pop
.
sock
.
close
()
pop
.
sock
.
close
()
def
testTimeoutValue
(
self
):
def
testTimeoutValue
(
self
):
...
...
Lib/test/test_smtplib.py
View file @
79b6f17d
...
@@ -77,7 +77,7 @@ class GeneralTests(unittest.TestCase):
...
@@ -77,7 +77,7 @@ class GeneralTests(unittest.TestCase):
smtp
.
close
()
smtp
.
close
()
def
testTimeoutDefault
(
self
):
def
testTimeoutDefault
(
self
):
self
.
assert
True
(
socket
.
getdefaulttimeout
()
is
None
)
self
.
assert
IsNone
(
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):
...
@@ -87,13 +87,13 @@ class GeneralTests(unittest.TestCase):
smtp
.
close
()
smtp
.
close
()
def
testTimeoutNone
(
self
):
def
testTimeoutNone
(
self
):
self
.
assert
True
(
socket
.
getdefaulttimeout
()
is
None
)
self
.
assert
IsNone
(
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
.
assert
True
(
smtp
.
sock
.
gettimeout
()
is
None
)
self
.
assert
IsNone
(
smtp
.
sock
.
gettimeout
()
)
smtp
.
close
()
smtp
.
close
()
def
testTimeoutValue
(
self
):
def
testTimeoutValue
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment