Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Adam Osuchowski
Kea
Commits
ddde1f30
Commit
ddde1f30
authored
Jan 28, 2013
by
Jelte Jansen
Browse files
[master] Fix floating point issue in unit test
reviewed on jabber (muks)
parent
3d4f3cd9
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lib/python/isc/cc/tests/message_test.py
View file @
ddde1f30
...
...
@@ -27,20 +27,27 @@ class MessageTest(unittest.TestCase):
self
.
msg1_str
=
"{
\"
just
\"
: [
\"
an
\"
,
\"
arbitrary
\"
,
\"
structure
\"
]}"
;
self
.
msg1_wire
=
self
.
msg1_str
.
encode
()
self
.
msg2
=
{
"aaa"
:
[
1
,
1.1
,
True
,
False
,
None
]
}
self
.
msg2_str
=
"{
\"
aaa
\"
: [1,
1.1,
true, false, null]}"
;
self
.
msg2
=
{
"aaa"
:
[
1
,
True
,
False
,
None
]
}
self
.
msg2_str
=
"{
\"
aaa
\"
: [1, true, false, null]}"
;
self
.
msg2_wire
=
self
.
msg2_str
.
encode
()
self
.
msg3
=
{
"aaa"
:
[
1
,
1.1
,
True
,
False
,
"string
\n
"
]
}
self
.
msg3_str
=
"{
\"
aaa
\"
: [1, 1.1, true, false,
\"
string
\n\"
]}"
;
self
.
msg3_wire
=
self
.
msg3_str
.
encode
()
# Due to the inherent impreciseness of floating point values,
# we test this one separately (with AlmostEqual)
self
.
msg_float
=
1.1
self
.
msg_float_str
=
"1.1"
;
self
.
msg_float_wire
=
self
.
msg_float_str
.
encode
()
def
test_encode_json
(
self
):
self
.
assertEqual
(
self
.
msg1_wire
,
isc
.
cc
.
message
.
to_wire
(
self
.
msg1
))
self
.
assertEqual
(
self
.
msg2_wire
,
isc
.
cc
.
message
.
to_wire
(
self
.
msg2
))
self
.
assertAlmostEqual
(
float
(
self
.
msg_float_wire
),
float
(
isc
.
cc
.
message
.
to_wire
(
self
.
msg_float
)))
self
.
assertRaises
(
TypeError
,
isc
.
cc
.
message
.
to_wire
,
NotImplemented
)
def
test_decode_json
(
self
):
self
.
assertEqual
(
self
.
msg1
,
isc
.
cc
.
message
.
from_wire
(
self
.
msg1_wire
))
self
.
assertEqual
(
self
.
msg2
,
isc
.
cc
.
message
.
from_wire
(
self
.
msg2_wire
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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