From 1ed2b17c8522c518919db7ba27410462edc8f029 Mon Sep 17 00:00:00 2001 From: Ferri Date: Wed, 24 Jan 2018 09:55:53 +0100 Subject: [PATCH] Add float comparison to test file --- tests/test_ObjectPath.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_ObjectPath.py b/tests/test_ObjectPath.py index 4c89f51..0e2558e 100644 --- a/tests/test_ObjectPath.py +++ b/tests/test_ObjectPath.py @@ -68,8 +68,27 @@ } } +object3={ + "item_1": { + "value": "foo", + "x": 5.6, + "y": 9 + }, + "item_2": { + "value": "bar", + "x": 5.6, + "y": 9.891 + }, + "item_3": { + "value": "foobar", + "x": 5.6, + "y": 9.8 + } +} + tree1=Tree(object1) tree2=Tree(object2) +tree3=Tree(object3) def execute_raw(expr): return tree1.execute(expr) @@ -93,6 +112,13 @@ def execute2(expr): else: return r +def execute3(expr): + r=tree3.execute(expr) + if isinstance(r, TYPES): + return list(r) + else: + return r + class ObjectPath(unittest.TestCase): def test_simple_types(self): self.assertEqual(execute("null"), None) @@ -424,6 +450,7 @@ def test_selectors(self): self.assertEqual(execute("$..*[@._id>1 and @._id<3][0]"), {'_id': 2}) # very bad syntax!!! self.assertEqual(sorted(execute2("$.store.book[@.price]")), sorted([8.95,12.99,8.99,22.99])) + self.assertEqual(execute3("$..*[@.x is 5.6 and @.y is 9.891].value"), ['bar']) #testcase2=unittest.FunctionTestCase(test_efficiency(2)) testcase1=unittest.TestLoader().loadTestsFromTestCase(ObjectPath)