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):
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
.
assertIs
None
(
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.assert
True(match is not None
, "
Invalid
file
name
:
'%s'" % tail)
self.assert
IsNotNone(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.assert
True(int(groups[2]) ==
pid,
self.assert
Equal(int(groups[2]),
pid,
"
Process
ID
mismatch
:
'%s'
should
be
'%s'" %
(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'" %
(previous_groups[3], groups[3]))
self.assert
True(groups[4] ==
hostname,
self.assert
Equal(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.assert
True(tmp_file.read() ==
_sample_message)
self.assert
Equal(tmp_file.read(),
_sample_message)
tmp_file.close()
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'" %
(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
.
assert
Equal
(
msg
.
get_payload
(),
None
)
self
.
assert
IsNone
(
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
.
assert
True
(
abs
(
diff
)
<
60
,
diff
)
self
.
assert
Less
(
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
.
assertIs
None
(
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
.
assertIs
None
(
visible
.
get_payload
()
)
msg
.
update_visible
()
self
.
assertEqual
(
visible
.
keys
(),
[
'User-Agent'
,
'X-Whatever'
])
self
.
assertIs
(
visible
.
get_payload
(),
None
)
self
.
assertIs
None
(
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.assert
True(len(self.mbox.boxes) ==
0)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
#self.assert
Equal(len(self.mbox.boxes),
0)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
def
test_nonempty_maildir_cur
(
self
):
self
.
createMessage
(
"cur"
)
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
()
self
.
assertIsNot
(
msg
,
None
)
self
.
assertIsNot
None
(
msg
)
msg
.
fp
.
close
()
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
def
test_nonempty_maildir_new
(
self
):
self
.
createMessage
(
"new"
)
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
()
self
.
assertIsNot
(
msg
,
None
)
self
.
assertIsNot
None
(
msg
)
msg
.
fp
.
close
()
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
def
test_nonempty_maildir_both
(
self
):
self
.
createMessage
(
"cur"
)
self
.
createMessage
(
"new"
)
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
()
self
.
assertIsNot
(
msg
,
None
)
self
.
assertIsNot
None
(
msg
)
msg
.
fp
.
close
()
msg
=
self
.
mbox
.
next
()
self
.
assertIsNot
(
msg
,
None
)
self
.
assertIsNot
None
(
msg
)
msg
.
fp
.
close
()
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
(
self
.
mbox
.
next
(),
None
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
self
.
assertIs
None
(
self
.
mbox
.
next
()
)
def
test_unix_mbox
(
self
):
### should be better!
...
...
Lib/test/test_poplib.py
View file @
79b6f17d
...
...
@@ -308,7 +308,7 @@ class TestTimeouts(TestCase):
serv
.
close
()
def
testTimeoutDefault
(
self
):
self
.
assert
True
(
socket
.
getdefaulttimeout
()
is
None
)
self
.
assert
IsNone
(
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
.
assert
True
(
socket
.
getdefaulttimeout
()
is
None
)
self
.
assert
IsNone
(
socket
.
getdefaulttimeout
()
)
socket
.
setdefaulttimeout
(
30
)
try
:
pop
=
poplib
.
POP3
(
HOST
,
self
.
port
,
timeout
=
None
)
finally
:
socket
.
setdefaulttimeout
(
None
)
self
.
assert
True
(
pop
.
sock
.
gettimeout
()
is
None
)
self
.
assert
IsNone
(
pop
.
sock
.
gettimeout
()
)
pop
.
sock
.
close
()
def
testTimeoutValue
(
self
):
...
...
Lib/test/test_smtplib.py
View file @
79b6f17d
...
...
@@ -77,7 +77,7 @@ class GeneralTests(unittest.TestCase):
smtp
.
close
()
def
testTimeoutDefault
(
self
):
self
.
assert
True
(
socket
.
getdefaulttimeout
()
is
None
)
self
.
assert
IsNone
(
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
.
assert
True
(
socket
.
getdefaulttimeout
()
is
None
)
self
.
assert
IsNone
(
socket
.
getdefaulttimeout
()
)
socket
.
setdefaulttimeout
(
30
)
try
:
smtp
=
smtplib
.
SMTP
(
HOST
,
self
.
port
,
timeout
=
None
)
finally
:
socket
.
setdefaulttimeout
(
None
)
self
.
assert
True
(
smtp
.
sock
.
gettimeout
()
is
None
)
self
.
assert
IsNone
(
smtp
.
sock
.
gettimeout
()
)
smtp
.
close
()
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