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
f008203c
Kaydet (Commit)
f008203c
authored
Ara 01, 2006
tarafından
Walter Dörwald
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Move xdrlib tests from the module into a separate test script,
port the tests to unittest and add a few new tests.
üst
c764340b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
78 deletions
+54
-78
test_xdrlib
Lib/test/output/test_xdrlib
+0
-19
test_xdrlib.py
Lib/test/test_xdrlib.py
+54
-1
xdrlib.py
Lib/xdrlib.py
+0
-58
No files found.
Lib/test/output/test_xdrlib
deleted
100644 → 0
Dosyayı görüntüle @
c764340b
test_xdrlib
pack test 0 succeeded
pack test 1 succeeded
pack test 2 succeeded
pack test 3 succeeded
pack test 4 succeeded
pack test 5 succeeded
pack test 6 succeeded
pack test 7 succeeded
pack test 8 succeeded
unpack test 0 succeeded : 9
unpack test 1 succeeded : True
unpack test 2 succeeded : False
unpack test 3 succeeded : 45
unpack test 4 succeeded : 1.89999997616
unpack test 5 succeeded : 1.9
unpack test 6 succeeded : hello world
unpack test 7 succeeded : [0, 1, 2, 3, 4]
unpack test 8 succeeded : ['what', 'is', 'hapnin', 'doctor']
Lib/test/test_xdrlib.py
Dosyayı görüntüle @
f008203c
from
test
import
test_support
import
unittest
import
xdrlib
xdrlib
.
_test
()
class
XDRTest
(
unittest
.
TestCase
):
def
test_xdr
(
self
):
p
=
xdrlib
.
Packer
()
s
=
'hello world'
a
=
[
'what'
,
'is'
,
'hapnin'
,
'doctor'
]
p
.
pack_int
(
42
)
p
.
pack_uint
(
9
)
p
.
pack_bool
(
True
)
p
.
pack_bool
(
False
)
p
.
pack_uhyper
(
45L
)
p
.
pack_float
(
1.9
)
p
.
pack_double
(
1.9
)
p
.
pack_string
(
s
)
p
.
pack_list
(
range
(
5
),
p
.
pack_uint
)
p
.
pack_array
(
a
,
p
.
pack_string
)
# now verify
data
=
p
.
get_buffer
()
up
=
xdrlib
.
Unpacker
(
data
)
self
.
assertEqual
(
up
.
get_position
(),
0
)
self
.
assertEqual
(
up
.
unpack_int
(),
42
)
self
.
assertEqual
(
up
.
unpack_uint
(),
9
)
self
.
assert_
(
up
.
unpack_bool
()
is
True
)
# remember position
pos
=
up
.
get_position
()
self
.
assert_
(
up
.
unpack_bool
()
is
False
)
# rewind and unpack again
up
.
set_position
(
pos
)
self
.
assert_
(
up
.
unpack_bool
()
is
False
)
self
.
assertEqual
(
up
.
unpack_uhyper
(),
45L
)
self
.
assertAlmostEqual
(
up
.
unpack_float
(),
1.9
)
self
.
assertAlmostEqual
(
up
.
unpack_double
(),
1.9
)
self
.
assertEqual
(
up
.
unpack_string
(),
s
)
self
.
assertEqual
(
up
.
unpack_list
(
up
.
unpack_uint
),
range
(
5
))
self
.
assertEqual
(
up
.
unpack_array
(
up
.
unpack_string
),
a
)
up
.
done
()
self
.
assertRaises
(
EOFError
,
up
.
unpack_uint
)
def
test_main
():
test_support
.
run_unittest
(
XDRTest
)
if
__name__
==
"__main__"
:
test_main
()
Lib/xdrlib.py
Dosyayı görüntüle @
f008203c
...
...
@@ -227,61 +227,3 @@ class Unpacker:
def
unpack_array
(
self
,
unpack_item
):
n
=
self
.
unpack_uint
()
return
self
.
unpack_farray
(
n
,
unpack_item
)
# test suite
def
_test
():
p
=
Packer
()
packtest
=
[
(
p
.
pack_uint
,
(
9
,)),
(
p
.
pack_bool
,
(
True
,)),
(
p
.
pack_bool
,
(
False
,)),
(
p
.
pack_uhyper
,
(
45L
,)),
(
p
.
pack_float
,
(
1.9
,)),
(
p
.
pack_double
,
(
1.9
,)),
(
p
.
pack_string
,
(
'hello world'
,)),
(
p
.
pack_list
,
(
range
(
5
),
p
.
pack_uint
)),
(
p
.
pack_array
,
([
'what'
,
'is'
,
'hapnin'
,
'doctor'
],
p
.
pack_string
)),
]
succeedlist
=
[
1
]
*
len
(
packtest
)
count
=
0
for
method
,
args
in
packtest
:
print
'pack test'
,
count
,
try
:
method
(
*
args
)
print
'succeeded'
except
ConversionError
,
var
:
print
'ConversionError:'
,
var
.
msg
succeedlist
[
count
]
=
0
count
=
count
+
1
data
=
p
.
get_buffer
()
# now verify
up
=
Unpacker
(
data
)
unpacktest
=
[
(
up
.
unpack_uint
,
(),
lambda
x
:
x
==
9
),
(
up
.
unpack_bool
,
(),
lambda
x
:
x
is
True
),
(
up
.
unpack_bool
,
(),
lambda
x
:
x
is
False
),
(
up
.
unpack_uhyper
,
(),
lambda
x
:
x
==
45L
),
(
up
.
unpack_float
,
(),
lambda
x
:
1.89
<
x
<
1.91
),
(
up
.
unpack_double
,
(),
lambda
x
:
1.89
<
x
<
1.91
),
(
up
.
unpack_string
,
(),
lambda
x
:
x
==
'hello world'
),
(
up
.
unpack_list
,
(
up
.
unpack_uint
,),
lambda
x
:
x
==
range
(
5
)),
(
up
.
unpack_array
,
(
up
.
unpack_string
,),
lambda
x
:
x
==
[
'what'
,
'is'
,
'hapnin'
,
'doctor'
]),
]
count
=
0
for
method
,
args
,
pred
in
unpacktest
:
print
'unpack test'
,
count
,
try
:
if
succeedlist
[
count
]:
x
=
method
(
*
args
)
print
pred
(
x
)
and
'succeeded'
or
'failed'
,
':'
,
x
else
:
print
'skipping'
except
ConversionError
,
var
:
print
'ConversionError:'
,
var
.
msg
count
=
count
+
1
if
__name__
==
'__main__'
:
_test
()
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