Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
4d2cf558
Kaydet (Commit)
4d2cf558
authored
Eyl 29, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Moved unpickling tests with prepickled data to separate class.
üst
958a9c75
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
47 deletions
+88
-47
pickletester.py
Lib/test/pickletester.py
+45
-38
test_cpickle.py
Lib/test/test_cpickle.py
+29
-6
test_pickle.py
Lib/test/test_pickle.py
+14
-3
No files found.
Lib/test/pickletester.py
Dosyayı görüntüle @
4d2cf558
...
@@ -420,11 +420,54 @@ def create_data():
...
@@ -420,11 +420,54 @@ def create_data():
x
.
append
(
5
)
x
.
append
(
5
)
return
x
return
x
class
AbstractPickleTests
(
unittest
.
TestCase
):
# Subclass must define self.dumps, self.loads, self.error.
class
AbstractUnpickleTests
(
unittest
.
TestCase
):
# Subclass must define self.loads, self.error.
_testdata
=
create_data
()
_testdata
=
create_data
()
def
test_load_from_canned_string
(
self
):
expected
=
self
.
_testdata
for
canned
in
DATA0
,
DATA1
,
DATA2
:
got
=
self
.
loads
(
canned
)
self
.
assertEqual
(
expected
,
got
)
def
test_garyp
(
self
):
self
.
assertRaises
(
self
.
error
,
self
.
loads
,
'garyp'
)
def
test_maxint64
(
self
):
maxint64
=
(
1L
<<
63
)
-
1
data
=
'I'
+
str
(
maxint64
)
+
'
\n
.'
got
=
self
.
loads
(
data
)
self
.
assertEqual
(
got
,
maxint64
)
# Try too with a bogus literal.
data
=
'I'
+
str
(
maxint64
)
+
'JUNK
\n
.'
self
.
assertRaises
(
ValueError
,
self
.
loads
,
data
)
def
test_insecure_strings
(
self
):
insecure
=
[
"abc"
,
"2 + 2"
,
# not quoted
#"'abc' + 'def'", # not a single quoted string
"'abc"
,
# quote is not closed
"'abc
\"
"
,
# open quote and close quote don't match
"'abc' ?"
,
# junk after close quote
"'
\\
'"
,
# trailing backslash
"'"
,
# issue #17710
"' "
,
# issue #17710
# some tests of the quoting rules
#"'abc\"\''",
#"'\\\\a\'\'\'\\\'\\\\\''",
]
for
s
in
insecure
:
buf
=
"S"
+
s
+
"
\012
p0
\012
."
self
.
assertRaises
(
ValueError
,
self
.
loads
,
buf
)
class
AbstractPickleTests
(
unittest
.
TestCase
):
# Subclass must define self.dumps, self.loads.
_testdata
=
AbstractUnpickleTests
.
_testdata
def
setUp
(
self
):
def
setUp
(
self
):
pass
pass
...
@@ -455,12 +498,6 @@ class AbstractPickleTests(unittest.TestCase):
...
@@ -455,12 +498,6 @@ class AbstractPickleTests(unittest.TestCase):
got
=
self
.
loads
(
s
)
got
=
self
.
loads
(
s
)
self
.
assertEqual
(
expected
,
got
)
self
.
assertEqual
(
expected
,
got
)
def
test_load_from_canned_string
(
self
):
expected
=
self
.
_testdata
for
canned
in
DATA0
,
DATA1
,
DATA2
:
got
=
self
.
loads
(
canned
)
self
.
assertEqual
(
expected
,
got
)
# There are gratuitous differences between pickles produced by
# There are gratuitous differences between pickles produced by
# pickle and cPickle, largely because cPickle starts PUT indices at
# pickle and cPickle, largely because cPickle starts PUT indices at
# 1 and pickle starts them at 0. See XXX comment in cPickle's put2() --
# 1 and pickle starts them at 0. See XXX comment in cPickle's put2() --
...
@@ -528,26 +565,6 @@ class AbstractPickleTests(unittest.TestCase):
...
@@ -528,26 +565,6 @@ class AbstractPickleTests(unittest.TestCase):
self
.
assertEqual
(
x
[
0
]
.
attr
.
keys
(),
[
1
])
self
.
assertEqual
(
x
[
0
]
.
attr
.
keys
(),
[
1
])
self
.
assertTrue
(
x
[
0
]
.
attr
[
1
]
is
x
)
self
.
assertTrue
(
x
[
0
]
.
attr
[
1
]
is
x
)
def
test_garyp
(
self
):
self
.
assertRaises
(
self
.
error
,
self
.
loads
,
'garyp'
)
def
test_insecure_strings
(
self
):
insecure
=
[
"abc"
,
"2 + 2"
,
# not quoted
#"'abc' + 'def'", # not a single quoted string
"'abc"
,
# quote is not closed
"'abc
\"
"
,
# open quote and close quote don't match
"'abc' ?"
,
# junk after close quote
"'
\\
'"
,
# trailing backslash
"'"
,
# issue #17710
"' "
,
# issue #17710
# some tests of the quoting rules
#"'abc\"\''",
#"'\\\\a\'\'\'\\\'\\\\\''",
]
for
s
in
insecure
:
buf
=
"S"
+
s
+
"
\012
p0
\012
."
self
.
assertRaises
(
ValueError
,
self
.
loads
,
buf
)
if
have_unicode
:
if
have_unicode
:
def
test_unicode
(
self
):
def
test_unicode
(
self
):
endcases
=
[
u''
,
u'<
\\
u>'
,
u'<
\\\u1234
>'
,
u'<
\n
>'
,
endcases
=
[
u''
,
u'<
\\
u>'
,
u'<
\\\u1234
>'
,
u'<
\n
>'
,
...
@@ -576,16 +593,6 @@ class AbstractPickleTests(unittest.TestCase):
...
@@ -576,16 +593,6 @@ class AbstractPickleTests(unittest.TestCase):
self
.
assertEqual
(
expected
,
n2
)
self
.
assertEqual
(
expected
,
n2
)
n
=
n
>>
1
n
=
n
>>
1
def
test_maxint64
(
self
):
maxint64
=
(
1L
<<
63
)
-
1
data
=
'I'
+
str
(
maxint64
)
+
'
\n
.'
got
=
self
.
loads
(
data
)
self
.
assertEqual
(
got
,
maxint64
)
# Try too with a bogus literal.
data
=
'I'
+
str
(
maxint64
)
+
'JUNK
\n
.'
self
.
assertRaises
(
ValueError
,
self
.
loads
,
data
)
def
test_long
(
self
):
def
test_long
(
self
):
for
proto
in
protocols
:
for
proto
in
protocols
:
# 256 bytes is where LONG4 begins.
# 256 bytes is where LONG4 begins.
...
...
Lib/test/test_cpickle.py
Dosyayı görüntüle @
4d2cf558
...
@@ -2,7 +2,8 @@ import cPickle
...
@@ -2,7 +2,8 @@ import cPickle
import
cStringIO
import
cStringIO
import
io
import
io
import
unittest
import
unittest
from
test.pickletester
import
(
AbstractPickleTests
,
from
test.pickletester
import
(
AbstractUnpickleTests
,
AbstractPickleTests
,
AbstractPickleModuleTests
,
AbstractPickleModuleTests
,
AbstractPicklerUnpicklerObjectTests
,
AbstractPicklerUnpicklerObjectTests
,
BigmemPickleTests
)
BigmemPickleTests
)
...
@@ -40,7 +41,8 @@ class FileIOMixin:
...
@@ -40,7 +41,8 @@ class FileIOMixin:
test_support
.
unlink
(
test_support
.
TESTFN
)
test_support
.
unlink
(
test_support
.
TESTFN
)
class
cPickleTests
(
AbstractPickleTests
,
AbstractPickleModuleTests
):
class
cPickleTests
(
AbstractUnpickleTests
,
AbstractPickleTests
,
AbstractPickleModuleTests
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
dumps
=
cPickle
.
dumps
self
.
dumps
=
cPickle
.
dumps
...
@@ -49,6 +51,28 @@ class cPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
...
@@ -49,6 +51,28 @@ class cPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
error
=
cPickle
.
BadPickleGet
error
=
cPickle
.
BadPickleGet
module
=
cPickle
module
=
cPickle
class
cPickleUnpicklerTests
(
AbstractUnpickleTests
):
def
loads
(
self
,
buf
):
f
=
self
.
input
(
buf
)
try
:
p
=
cPickle
.
Unpickler
(
f
)
return
p
.
load
()
finally
:
self
.
close
(
f
)
error
=
cPickle
.
BadPickleGet
class
cStringIOCUnpicklerTests
(
cStringIOMixin
,
cPickleUnpicklerTests
):
pass
class
BytesIOCUnpicklerTests
(
BytesIOMixin
,
cPickleUnpicklerTests
):
pass
class
FileIOCUnpicklerTests
(
FileIOMixin
,
cPickleUnpicklerTests
):
pass
class
cPicklePicklerTests
(
AbstractPickleTests
):
class
cPicklePicklerTests
(
AbstractPickleTests
):
def
dumps
(
self
,
arg
,
proto
=
0
):
def
dumps
(
self
,
arg
,
proto
=
0
):
...
@@ -69,8 +93,6 @@ class cPicklePicklerTests(AbstractPickleTests):
...
@@ -69,8 +93,6 @@ class cPicklePicklerTests(AbstractPickleTests):
finally
:
finally
:
self
.
close
(
f
)
self
.
close
(
f
)
error
=
cPickle
.
BadPickleGet
class
cStringIOCPicklerTests
(
cStringIOMixin
,
cPicklePicklerTests
):
class
cStringIOCPicklerTests
(
cStringIOMixin
,
cPicklePicklerTests
):
pass
pass
...
@@ -129,8 +151,6 @@ class cPickleFastPicklerTests(AbstractPickleTests):
...
@@ -129,8 +151,6 @@ class cPickleFastPicklerTests(AbstractPickleTests):
finally
:
finally
:
self
.
close
(
f
)
self
.
close
(
f
)
error
=
cPickle
.
BadPickleGet
def
test_recursive_list
(
self
):
def
test_recursive_list
(
self
):
self
.
assertRaises
(
ValueError
,
self
.
assertRaises
(
ValueError
,
AbstractPickleTests
.
test_recursive_list
,
AbstractPickleTests
.
test_recursive_list
,
...
@@ -219,6 +239,9 @@ class cPickleDeepRecursive(unittest.TestCase):
...
@@ -219,6 +239,9 @@ class cPickleDeepRecursive(unittest.TestCase):
def
test_main
():
def
test_main
():
test_support
.
run_unittest
(
test_support
.
run_unittest
(
cPickleTests
,
cPickleTests
,
cStringIOCUnpicklerTests
,
BytesIOCUnpicklerTests
,
FileIOCUnpicklerTests
,
cStringIOCPicklerTests
,
cStringIOCPicklerTests
,
BytesIOCPicklerTests
,
BytesIOCPicklerTests
,
FileIOCPicklerTests
,
FileIOCPicklerTests
,
...
...
Lib/test/test_pickle.py
Dosyayı görüntüle @
4d2cf558
...
@@ -3,13 +3,15 @@ from cStringIO import StringIO
...
@@ -3,13 +3,15 @@ from cStringIO import StringIO
from
test
import
test_support
from
test
import
test_support
from
test.pickletester
import
(
AbstractPickleTests
,
from
test.pickletester
import
(
AbstractUnpickleTests
,
AbstractPickleTests
,
AbstractPickleModuleTests
,
AbstractPickleModuleTests
,
AbstractPersistentPicklerTests
,
AbstractPersistentPicklerTests
,
AbstractPicklerUnpicklerObjectTests
,
AbstractPicklerUnpicklerObjectTests
,
BigmemPickleTests
)
BigmemPickleTests
)
class
PickleTests
(
AbstractPickleTests
,
AbstractPickleModuleTests
):
class
PickleTests
(
AbstractUnpickleTests
,
AbstractPickleTests
,
AbstractPickleModuleTests
):
def
dumps
(
self
,
arg
,
proto
=
0
,
fast
=
0
):
def
dumps
(
self
,
arg
,
proto
=
0
,
fast
=
0
):
# Ignore fast
# Ignore fast
...
@@ -22,10 +24,18 @@ class PickleTests(AbstractPickleTests, AbstractPickleModuleTests):
...
@@ -22,10 +24,18 @@ class PickleTests(AbstractPickleTests, AbstractPickleModuleTests):
module
=
pickle
module
=
pickle
error
=
KeyError
error
=
KeyError
class
PicklerTests
(
AbstractP
ickleTests
):
class
UnpicklerTests
(
AbstractUnp
ickleTests
):
error
=
KeyError
error
=
KeyError
def
loads
(
self
,
buf
):
f
=
StringIO
(
buf
)
u
=
pickle
.
Unpickler
(
f
)
return
u
.
load
()
class
PicklerTests
(
AbstractPickleTests
):
def
dumps
(
self
,
arg
,
proto
=
0
,
fast
=
0
):
def
dumps
(
self
,
arg
,
proto
=
0
,
fast
=
0
):
f
=
StringIO
()
f
=
StringIO
()
p
=
pickle
.
Pickler
(
f
,
proto
)
p
=
pickle
.
Pickler
(
f
,
proto
)
...
@@ -81,6 +91,7 @@ class PickleBigmemPickleTests(BigmemPickleTests):
...
@@ -81,6 +91,7 @@ class PickleBigmemPickleTests(BigmemPickleTests):
def
test_main
():
def
test_main
():
test_support
.
run_unittest
(
test_support
.
run_unittest
(
PickleTests
,
PickleTests
,
UnpicklerTests
,
PicklerTests
,
PicklerTests
,
PersPicklerTests
,
PersPicklerTests
,
PicklerUnpicklerObjectTests
,
PicklerUnpicklerObjectTests
,
...
...
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