def test_wildcard(self): wildcard = object() class A: def __init__(self, a=None): self.i = 1 self.s = wildcard self.a = a obj = A(A()) self.assertTrue(querypath.test(obj, "a.s.unexistant", wildcard)) self.assertFalse(querypath.test(obj, "a.a.unexistant", wildcard))
def test_wildcard(self): wildcard = object() obj = { "i": 1, "f": 0.1, "d": { "inner": wildcard, "container": { "value": 1, }, }, } self.assertTrue(querypath.test(obj, "d.inner.unexistant", wildcard)) self.assertFalse(querypath.test(obj, "d.container.unexistant", wildcard))
def test_single_test(self): for path in ( "store.bicycle", "$.store.bicycle", "$['store']['bicycle']", ): self.assertTrue(querypath.test(self.obj, path))
def test_slice_step_test(self): for path in ( "store.books[::2].price", "store.books.:2.price", "['store']['books']['::2']['price']", "['store']['books'][::2]['price']", ): self.assertTrue(querypath.test(self.obj, path))
def test_slice_end_test(self): for path in ( "store.books[:-1].price", "store.books.:-1.price", "['store']['books'][':-1']['price']", "['store']['books'][:-1]['price']", ): self.assertTrue(querypath.test(self.obj, path))
def test_fullslice_test(self): for path in ( "store.books[:].price", "store.books.:.price", "['store']['books'][':']['price']", "['store']['books'][:]['price']", ): self.assertTrue(querypath.test(self.obj, path))
def test_pipe_union_test(self): for path in ( "store.books.*.category|..bicycle.color", "store.books.*.category |..bicycle.color", "store.books.*.category| ..bicycle.color", "store.books.*.category | ..bicycle.color", "[store][books][:][category]|[store][bicycle][color]", "store.books.*.category|store.bicycle.color", ): self.assertTrue(querypath.test(self.obj, path))
def test_empty_result_test(self): for path in ( "folder", "$.folder", "$[folder]", "$[folder]", "['folder']", "store.books.7", ): self.assertFalse(querypath.test(self.obj, path))
def test_script_query_test(self): self.assertTrue( querypath.test(self.obj, "store.books.*[?(@.price<10)].title"))
def test_numeric_test(self): for path in ( "store.books.0.author", "store.books[0].author", ): self.assertTrue(querypath.test(self.obj, path))
def test_root_test(self): path = "$" self.assertTrue(querypath.test(self.obj, path))
def test_empty_test(self): path = "" self.assertTrue(querypath.test(self.obj, path))