]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Fix floating point issue in unit test
authorJelte Jansen <jelte@isc.org>
Mon, 28 Jan 2013 10:34:39 +0000 (11:34 +0100)
committerJelte Jansen <jelte@isc.org>
Mon, 28 Jan 2013 10:34:39 +0000 (11:34 +0100)
reviewed on jabber (muks)

src/lib/python/isc/cc/tests/message_test.py

index c4170681209fb3b5831e63f8336e857f82a01a95..17f034d0dc0980d91f328677cd5180d8df9959a8 100644 (file)
@@ -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))