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
6bed342b
Commit
6bed342b
authored
May 28, 2012
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor test_email/test_pickleable and add tests for date headers
parent
a7c9ddb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
28 deletions
+59
-28
Lib/test/test_email/test_pickleable.py
Lib/test/test_email/test_pickleable.py
+59
-28
No files found.
Lib/test/test_email/test_pickleable.py
View file @
6bed342b
...
...
@@ -2,55 +2,86 @@ import unittest
import
textwrap
import
copy
import
pickle
import
email
import
email.message
from
email
import
policy
from
email
import
message_from_string
from
email.headerregistry
import
HeaderRegistry
from
test.test_email
import
TestEmailBase
class
TestPickleCopyHeader
(
TestEmailBase
):
unstructured
=
HeaderRegistry
()(
'subject'
,
'this is a test'
)
header_factory
=
HeaderRegistry
(
)
def
test_deepcopy_unstructured
(
self
):
h
=
copy
.
deepcopy
(
self
.
unstructured
)
self
.
assertEqual
(
str
(
h
),
str
(
self
.
unstructured
))
unstructured
=
header_factory
(
'subject'
,
'this is a test'
)
def
test_pickle_unstructured
(
self
):
p
=
pickle
.
dumps
(
self
.
unstructured
)
def
_test_deepcopy
(
self
,
name
,
value
):
header
=
self
.
header_factory
(
name
,
value
)
h
=
copy
.
deepcopy
(
header
)
self
.
assertEqual
(
str
(
h
),
str
(
header
))
def
_test_pickle
(
self
,
name
,
value
):
header
=
self
.
header_factory
(
name
,
value
)
p
=
pickle
.
dumps
(
header
)
h
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
str
(
h
),
str
(
self
.
unstructured
))
self
.
assertEqual
(
str
(
h
),
str
(
header
))
address
=
HeaderRegistry
()(
'from'
,
'frodo@mordor.net'
)
headers
=
(
(
'subject'
,
'this is a test'
),
(
'from'
,
'frodo@mordor.net'
),
(
'to'
,
'a: k@b.com, y@z.com;, j@f.com'
),
(
'date'
,
'Tue, 29 May 2012 09:24:26 +1000'
),
)
def
test_deepcopy_address
(
self
):
h
=
copy
.
deepcopy
(
self
.
address
)
self
.
assertEqual
(
str
(
h
),
str
(
self
.
address
))
for
header
in
headers
:
locals
()[
'test_deepcopy_'
+
header
[
0
]]
=
(
lambda
self
,
header
=
header
:
self
.
_test_deepcopy
(
*
header
))
def
test_pickle_address
(
self
)
:
p
=
pickle
.
dumps
(
self
.
address
)
h
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
str
(
h
),
str
(
self
.
address
))
for
header
in
headers
:
locals
()[
'test_pickle_'
+
header
[
0
]]
=
(
lambda
self
,
header
=
header
:
self
.
_test_pickle
(
*
header
))
class
TestPickleCopyMessage
(
TestEmailBase
):
testmsg
=
message_from_string
(
textwrap
.
dedent
(
"""
\
From: frodo@mordor.net
To: bilbo@underhill.org
Subject: help
msgs
=
{}
# Note: there will be no custom header objects in the parsed message.
msgs
[
'parsed'
]
=
email
.
message_from_string
(
textwrap
.
dedent
(
"""
\
Date: Tue, 29 May 2012 09:24:26 +1000
From: frodo@mordor.net
To: bilbo@underhill.org
Subject: help
I think I forgot the ring.
"""
),
policy
=
policy
.
default
)
I think I forgot the ring.
"""
),
policy
=
policy
.
default
)
def
test_deepcopy
(
self
):
msg2
=
copy
.
deepcopy
(
self
.
testmsg
)
self
.
assertEqual
(
msg2
.
as_string
(),
self
.
testmsg
.
as_string
())
msgs
[
'created'
]
=
email
.
message
.
Message
(
policy
=
policy
.
default
)
msgs
[
'created'
][
'Date'
]
=
'Tue, 29 May 2012 09:24:26 +1000'
msgs
[
'created'
][
'From'
]
=
'frodo@mordor.net'
msgs
[
'created'
][
'To'
]
=
'bilbo@underhill.org'
msgs
[
'created'
][
'Subject'
]
=
'help'
msgs
[
'created'
].
set_payload
(
'I think I forgot the ring.'
)
def
test_pickle
(
self
):
p
=
pickle
.
dumps
(
self
.
testmsg
)
def
_test_deepcopy
(
self
,
msg
):
msg2
=
copy
.
deepcopy
(
msg
)
self
.
assertEqual
(
msg2
.
as_string
(),
msg
.
as_string
())
def
_test_pickle
(
self
,
msg
):
p
=
pickle
.
dumps
(
msg
)
msg2
=
pickle
.
loads
(
p
)
self
.
assertEqual
(
msg2
.
as_string
(),
self
.
testmsg
.
as_string
())
self
.
assertEqual
(
msg2
.
as_string
(),
msg
.
as_string
())
for
name
,
msg
in
msgs
.
items
():
locals
()[
'test_deepcopy_'
+
name
]
=
(
lambda
self
,
msg
=
msg
:
self
.
_test_deepcopy
(
msg
))
for
name
,
msg
in
msgs
.
items
():
locals
()[
'test_pickle_'
+
name
]
=
(
lambda
self
,
msg
=
msg
:
self
.
_test_pickle
(
msg
))
if
__name__
==
'__main__'
:
...
...
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