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
e9358161
Kaydet (Commit)
e9358161
authored
Ock 22, 2001
tarafından
Tim Peters
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Reorganize pickle/cPickle testing so the tests pass regardless of the order
they're run.
üst
da6daee4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
157 additions
and
170 deletions
+157
-170
test_cpickle
Lib/test/output/test_cpickle
+0
-12
pickletester.py
Lib/test/pickletester.py
+153
-0
test_cpickle.py
Lib/test/test_cpickle.py
+2
-4
test_pickle.py
Lib/test/test_pickle.py
+2
-154
No files found.
Lib/test/output/test_cpickle
Dosyayı görüntüle @
e9358161
...
...
@@ -11,15 +11,3 @@ loads() BINDATA
ok
dumps() RECURSIVE
ok
dumps()
loads()
ok
loads() DATA
ok
dumps() binary
loads() binary
ok
loads() BINDATA
ok
dumps() RECURSIVE
ok
Lib/test/pickletester.py
0 → 100644
Dosyayı görüntüle @
e9358161
# test_pick and test_cpickle both use this.
# break into multiple strings to please font-lock-mode
DATA
=
"""(lp0
I0
aL1L
aF2.0
ac__builtin__
complex
p1
"""
\
"""(F3.0
F0.0
tp2
Rp3
a(S'abc'
p4
g4
"""
\
"""(i__main__
C
p5
"""
\
"""(dp6
S'foo'
p7
I1
sS'bar'
p8
I2
sbg5
tp9
ag9
aI5
a.
"""
BINDATA
=
']q
\000
(K
\000
L1L
\012
G@
\000\000\000\000\000\000\000
c__builtin__
\012
complex
\012
q
\001
(G@
\010\000\000\000\000\000\000
G
\000\000\000\000\000\000\000\000
tq
\002
Rq
\003
(U
\003
abcq
\004
h
\004
(c__main__
\012
C
\012
q
\005
oq
\006
}q
\007
(U
\003
fooq
\010
K
\001
U
\003
barq
\011
K
\002
ubh
\006
tq
\012
h
\012
K
\005
e.'
class
C
:
def
__cmp__
(
self
,
other
):
return
cmp
(
self
.
__dict__
,
other
.
__dict__
)
import
__main__
__main__
.
C
=
C
# Call this with the module to be tested (pickle or cPickle).
def
dotest
(
pickle
):
c
=
C
()
c
.
foo
=
1
c
.
bar
=
2
x
=
[
0
,
1L
,
2.0
,
3.0
+
0
j
]
y
=
(
'abc'
,
'abc'
,
c
,
c
)
x
.
append
(
y
)
x
.
append
(
y
)
x
.
append
(
5
)
r
=
[]
r
.
append
(
r
)
print
"dumps()"
s
=
pickle
.
dumps
(
x
)
print
"loads()"
x2
=
pickle
.
loads
(
s
)
if
x2
==
x
:
print
"ok"
else
:
print
"bad"
print
"loads() DATA"
x2
=
pickle
.
loads
(
DATA
)
if
x2
==
x
:
print
"ok"
else
:
print
"bad"
print
"dumps() binary"
s
=
pickle
.
dumps
(
x
,
1
)
print
"loads() binary"
x2
=
pickle
.
loads
(
s
)
if
x2
==
x
:
print
"ok"
else
:
print
"bad"
print
"loads() BINDATA"
x2
=
pickle
.
loads
(
BINDATA
)
if
x2
==
x
:
print
"ok"
else
:
print
"bad"
s
=
pickle
.
dumps
(
r
)
print
"dumps() RECURSIVE"
x2
=
pickle
.
loads
(
s
)
if
x2
==
r
:
print
"ok"
else
:
print
"bad"
# don't create cyclic garbage
del
x2
[
0
]
del
r
[
0
]
# Test protection against closed files
import
tempfile
,
os
fn
=
tempfile
.
mktemp
()
f
=
open
(
fn
,
"w"
)
f
.
close
()
try
:
pickle
.
dump
(
123
,
f
)
except
ValueError
:
pass
else
:
print
"dump to closed file should raise ValueError"
f
=
open
(
fn
,
"r"
)
f
.
close
()
try
:
pickle
.
load
(
f
)
except
ValueError
:
pass
else
:
print
"load from closed file should raise ValueError"
os
.
remove
(
fn
)
# Test specific bad cases
for
i
in
range
(
10
):
try
:
x
=
pickle
.
loads
(
'garyp'
)
except
KeyError
,
y
:
# pickle
del
y
except
pickle
.
BadPickleGet
,
y
:
# cPickle
del
y
else
:
print
"unexpected success!"
break
# Test insecure strings
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
# some tests of the quoting rules
"'abc
\"\'
'"
,
"'
\\\\
a
\'\'\'\\\'\\\\\'
'"
,
]
for
s
in
insecure
:
buf
=
"S"
+
s
+
"
\012
p0
\012
."
try
:
x
=
pickle
.
loads
(
buf
)
except
ValueError
:
pass
else
:
print
"accepted insecure string:
%
s"
%
repr
(
buf
)
# Test some Unicode end cases
endcases
=
[
u''
,
u'<
\\
u>'
,
u'<
\\\u1234
>'
,
u'<
\n
>'
,
u'<
\\
>'
]
for
u
in
endcases
:
try
:
u2
=
pickle
.
loads
(
pickle
.
dumps
(
u
))
except
Exception
,
msg
:
print
"Endcase exception:
%
s =>
%
s(
%
s)"
%
\
(
`u`
,
msg
.
__class__
.
__name__
,
str
(
msg
))
else
:
if
u2
!=
u
:
print
"Endcase failure:
%
s =>
%
s"
%
(
`u`
,
`u2`
)
Lib/test/test_cpickle.py
Dosyayı görüntüle @
e9358161
# Test the cPickle module
import
cPickle
import
test_pickle
test_pickle
.
dotest
(
cPickle
)
import
pickletester
pickletester
.
dotest
(
cPickle
)
Lib/test/test_pickle.py
Dosyayı görüntüle @
e9358161
# Test the pickle module
# break into multiple strings to please font-lock-mode
DATA
=
"""(lp0
I0
aL1L
aF2.0
ac__builtin__
complex
p1
"""
\
"""(F3.0
F0.0
tp2
Rp3
a(S'abc'
p4
g4
"""
\
"""(i__main__
C
p5
"""
\
"""(dp6
S'foo'
p7
I1
sS'bar'
p8
I2
sbg5
tp9
ag9
aI5
a.
"""
BINDATA
=
']q
\000
(K
\000
L1L
\012
G@
\000\000\000\000\000\000\000
c__builtin__
\012
complex
\012
q
\001
(G@
\010\000\000\000\000\000\000
G
\000\000\000\000\000\000\000\000
tq
\002
Rq
\003
(U
\003
abcq
\004
h
\004
(c__main__
\012
C
\012
q
\005
oq
\006
}q
\007
(U
\003
fooq
\010
K
\001
U
\003
barq
\011
K
\002
ubh
\006
tq
\012
h
\012
K
\005
e.'
class
C
:
def
__cmp__
(
self
,
other
):
return
cmp
(
self
.
__dict__
,
other
.
__dict__
)
import
__main__
__main__
.
C
=
C
def
dotest
(
pickle
):
c
=
C
()
c
.
foo
=
1
c
.
bar
=
2
x
=
[
0
,
1L
,
2.0
,
3.0
+
0
j
]
y
=
(
'abc'
,
'abc'
,
c
,
c
)
x
.
append
(
y
)
x
.
append
(
y
)
x
.
append
(
5
)
r
=
[]
r
.
append
(
r
)
print
"dumps()"
s
=
pickle
.
dumps
(
x
)
print
"loads()"
x2
=
pickle
.
loads
(
s
)
if
x2
==
x
:
print
"ok"
else
:
print
"bad"
print
"loads() DATA"
x2
=
pickle
.
loads
(
DATA
)
if
x2
==
x
:
print
"ok"
else
:
print
"bad"
print
"dumps() binary"
s
=
pickle
.
dumps
(
x
,
1
)
print
"loads() binary"
x2
=
pickle
.
loads
(
s
)
if
x2
==
x
:
print
"ok"
else
:
print
"bad"
print
"loads() BINDATA"
x2
=
pickle
.
loads
(
BINDATA
)
if
x2
==
x
:
print
"ok"
else
:
print
"bad"
s
=
pickle
.
dumps
(
r
)
print
"dumps() RECURSIVE"
x2
=
pickle
.
loads
(
s
)
if
x2
==
r
:
print
"ok"
else
:
print
"bad"
# don't create cyclic garbage
del
x2
[
0
]
del
r
[
0
]
# Test protection against closed files
import
tempfile
,
os
fn
=
tempfile
.
mktemp
()
f
=
open
(
fn
,
"w"
)
f
.
close
()
try
:
pickle
.
dump
(
123
,
f
)
except
ValueError
:
pass
else
:
print
"dump to closed file should raise ValueError"
f
=
open
(
fn
,
"r"
)
f
.
close
()
try
:
pickle
.
load
(
f
)
except
ValueError
:
pass
else
:
print
"load from closed file should raise ValueError"
os
.
remove
(
fn
)
# Test specific bad cases
for
i
in
range
(
10
):
try
:
x
=
pickle
.
loads
(
'garyp'
)
except
KeyError
,
y
:
# pickle
del
y
except
pickle
.
BadPickleGet
,
y
:
# cPickle
del
y
else
:
print
"unexpected success!"
break
# Test insecure strings
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
# some tests of the quoting rules
"'abc
\"\'
'"
,
"'
\\\\
a
\'\'\'\\\'\\\\\'
'"
,
]
for
s
in
insecure
:
buf
=
"S"
+
s
+
"
\012
p0
\012
."
try
:
x
=
pickle
.
loads
(
buf
)
except
ValueError
:
pass
else
:
print
"accepted insecure string:
%
s"
%
repr
(
buf
)
# Test some Unicode end cases
endcases
=
[
u''
,
u'<
\\
u>'
,
u'<
\\\u1234
>'
,
u'<
\n
>'
,
u'<
\\
>'
]
for
u
in
endcases
:
try
:
u2
=
pickle
.
loads
(
pickle
.
dumps
(
u
))
except
Exception
,
msg
:
print
"Endcase exception:
%
s =>
%
s(
%
s)"
%
\
(
`u`
,
msg
.
__class__
.
__name__
,
str
(
msg
))
else
:
if
u2
!=
u
:
print
"Endcase failure:
%
s =>
%
s"
%
(
`u`
,
`u2`
)
import
pickle
dotest
(
pickle
)
import
pickletester
pickletester
.
dotest
(
pickle
)
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