Esempio n. 1
0
 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))
Esempio n. 2
0
 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))
Esempio n. 3
0
 def test_single_test(self):
     for path in (
         "store.bicycle",
         "$.store.bicycle",
         "$['store']['bicycle']",
         ):
         self.assertTrue(querypath.test(self.obj, path))
Esempio n. 4
0
 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))
Esempio n. 5
0
 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))
Esempio n. 6
0
 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))
Esempio n. 7
0
 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))
Esempio n. 8
0
 def test_empty_result_test(self):
     for path in (
         "folder",
         "$.folder",
         "$[folder]",
         "$[folder]",
         "['folder']",
         "store.books.7",
         ):
         self.assertFalse(querypath.test(self.obj, path))
Esempio n. 9
0
 def test_script_query_test(self):
     self.assertTrue(
         querypath.test(self.obj, "store.books.*[?(@.price<10)].title"))
Esempio n. 10
0
 def test_numeric_test(self):
     for path in (
         "store.books.0.author",
         "store.books[0].author",
         ):
         self.assertTrue(querypath.test(self.obj, path))
Esempio n. 11
0
 def test_root_test(self):
     path = "$"
     self.assertTrue(querypath.test(self.obj, path))
Esempio n. 12
0
 def test_empty_test(self):
     path = ""
     self.assertTrue(querypath.test(self.obj, path))