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
f008203c
Commit
f008203c
authored
Dec 01, 2006
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move xdrlib tests from the module into a separate test script,
port the tests to unittest and add a few new tests.
parent
c764340b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
78 deletions
+54
-78
Lib/test/output/test_xdrlib
Lib/test/output/test_xdrlib
+0
-19
Lib/test/test_xdrlib.py
Lib/test/test_xdrlib.py
+54
-1
Lib/xdrlib.py
Lib/xdrlib.py
+0
-58
No files found.
Lib/test/output/test_xdrlib
deleted
100644 → 0
View file @
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
View file @
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
View file @
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