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
d71f3170
Commit
d71f3170
authored
Jun 02, 2019
by
Serhiy Storchaka
Committed by
GitHub
Jun 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests for preserving identity in marshal. (GH-13736)
parent
b7daabd7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
18 deletions
+51
-18
Lib/test/test_marshal.py
Lib/test/test_marshal.py
+51
-18
No files found.
Lib/test/test_marshal.py
View file @
d71f3170
...
...
@@ -383,10 +383,7 @@ def CollectObjectIDs(ids, obj):
return
len
(
ids
)
class
InstancingTestCase
(
unittest
.
TestCase
,
HelperMixin
):
intobj
=
123321
floatobj
=
1.2345
strobj
=
"abcde"
*
3
dictobj
=
{
"hello"
:
floatobj
,
"goodbye"
:
floatobj
,
floatobj
:
"hello"
}
keys
=
(
123
,
1.2345
,
'abc'
,
(
123
,
'abc'
),
frozenset
({
123
,
'abc'
}))
def
helper3
(
self
,
rsample
,
recursive
=
False
,
simple
=
False
):
#we have two instances
...
...
@@ -394,11 +391,12 @@ class InstancingTestCase(unittest.TestCase, HelperMixin):
n0
=
CollectObjectIDs
(
set
(),
sample
)
s3
=
marshal
.
dumps
(
sample
,
3
)
n3
=
CollectObjectIDs
(
set
(),
marshal
.
loads
(
s3
))
for
v
in
range
(
3
,
marshal
.
version
+
1
):
s3
=
marshal
.
dumps
(
sample
,
v
)
n3
=
CollectObjectIDs
(
set
(),
marshal
.
loads
(
s3
))
#same number of instances generated
self
.
assertEqual
(
n3
,
n0
)
#same number of instances generated
self
.
assertEqual
(
n3
,
n0
)
if
not
recursive
:
#can compare with version 2
...
...
@@ -414,20 +412,54 @@ class InstancingTestCase(unittest.TestCase, HelperMixin):
self
.
assertGreaterEqual
(
len
(
s2
),
len
(
s3
))
def
testInt
(
self
):
self
.
helper
(
self
.
intobj
)
self
.
helper3
(
self
.
intobj
,
simple
=
True
)
intobj
=
123321
self
.
helper
(
intobj
)
self
.
helper3
(
intobj
,
simple
=
True
)
def
testFloat
(
self
):
self
.
helper
(
self
.
floatobj
)
self
.
helper3
(
self
.
floatobj
)
floatobj
=
1.2345
self
.
helper
(
floatobj
)
self
.
helper3
(
floatobj
)
def
testStr
(
self
):
self
.
helper
(
self
.
strobj
)
self
.
helper3
(
self
.
strobj
)
strobj
=
"abcde"
*
3
self
.
helper
(
strobj
)
self
.
helper3
(
strobj
)
def
testBytes
(
self
):
bytesobj
=
b"abcde"
*
3
self
.
helper
(
bytesobj
)
self
.
helper3
(
bytesobj
)
def
testList
(
self
):
for
obj
in
self
.
keys
:
listobj
=
[
obj
,
obj
]
self
.
helper
(
listobj
)
self
.
helper3
(
listobj
)
def
testTuple
(
self
):
for
obj
in
self
.
keys
:
tupleobj
=
(
obj
,
obj
)
self
.
helper
(
tupleobj
)
self
.
helper3
(
tupleobj
)
def
testSet
(
self
):
for
obj
in
self
.
keys
:
setobj
=
{(
obj
,
1
),
(
obj
,
2
)}
self
.
helper
(
setobj
)
self
.
helper3
(
setobj
)
def
testFrozenSet
(
self
):
for
obj
in
self
.
keys
:
frozensetobj
=
frozenset
({(
obj
,
1
),
(
obj
,
2
)})
self
.
helper
(
frozensetobj
)
self
.
helper3
(
frozensetobj
)
def
testDict
(
self
):
self
.
helper
(
self
.
dictobj
)
self
.
helper3
(
self
.
dictobj
)
for
obj
in
self
.
keys
:
dictobj
=
{
"hello"
:
obj
,
"goodbye"
:
obj
,
obj
:
"hello"
}
self
.
helper
(
dictobj
)
self
.
helper3
(
dictobj
)
def
testModule
(
self
):
with
open
(
__file__
,
"rb"
)
as
f
:
...
...
@@ -438,10 +470,11 @@ class InstancingTestCase(unittest.TestCase, HelperMixin):
self
.
helper3
(
code
)
def
testRecursion
(
self
):
d
=
dict
(
self
.
dictobj
)
obj
=
1.2345
d
=
{
"hello"
:
obj
,
"goodbye"
:
obj
,
obj
:
"hello"
}
d
[
"self"
]
=
d
self
.
helper3
(
d
,
recursive
=
True
)
l
=
[
self
.
dict
obj
]
l
=
[
obj
,
obj
]
l
.
append
(
l
)
self
.
helper3
(
l
,
recursive
=
True
)
...
...
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