Example #1
0
 def test_script_index_paths(self):
     for path in (
         "store.books[(@.__len__()-1)].isbn",
         "..['books'][(@.__len__()-1)]['isbn']",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = ['store.books.3.isbn']
         self.assertItemsEqual(result, expected)
Example #2
0
 def test_numeric_paths(self):
     for path in (
         "store.books.0.author",
         "store.books[0].author",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = ['store.books.0.author']
         self.assertItemsEqual(result, expected)
Example #3
0
 def test_single_paths(self):
     for path in (
         "store.bicycle.color",
         "$.store.bicycle.color",
         "$['store']['bicycle']['color']",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = ['store.bicycle.color']
         self.assertItemsEqual(result, expected)
Example #4
0
 def test_pipe_intersection_paths(self):
     result = querypath.paths(self.obj, "..price|store.books[0].price")
     expected = [
         'store.books.0.price',
         'store.books.1.price',
         'store.books.2.price',
         'store.books.3.price',
         'store.bicycle.price',
         ]
     self.assertItemsEqual(result, expected)
Example #5
0
 def test_script_query2_paths(self):
     for path in (
         "store.books.*[?(@.isbn)].title",
         "store.books.*[?('isbn' in @.__dict__)].title",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = [
             'store.books.2.title',
             'store.books.3.title',
             ]
         self.assertItemsEqual(result, expected)
Example #6
0
 def test_slice_step_paths(self):
     for path in (
         "store.books[::2].price",
         "store.books.::2.price",
         "['store']['books']['::2']['price']",
         "['store']['books'][::2]['price']",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = [
             'store.books.0.price',
             'store.books.2.price',
             ]
         self.assertItemsEqual(result, expected)
Example #7
0
 def test_slice_begin_paths(self):
     for path in (
         "store.books[2:].price",
         "store.books.2:.price",
         "['store']['books']['2:']['price']",
         "['store']['books'][2:]['price']",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = [
             'store.books.2.price',
             'store.books.3.price',
             ]
         self.assertItemsEqual(result, expected)
Example #8
0
 def test_comma_union_paths(self):
     for path in (
         "store.books,bicycle,car..price",
         "$['store']['books,bicycle']..['price']",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = [
             'store.books.0.price',
             'store.books.1.price',
             'store.books.2.price',
             'store.books.3.price',
             'store.bicycle.price',
             ]
         self.assertItemsEqual(result, expected)
Example #9
0
 def test_wildcard_paths(self):
     for path in (
         "store.books.*.price",
         "['store']['books'][*]['price']",
         "['store']['books']['*']['price']",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = [
             'store.books.0.price',
             'store.books.1.price',
             'store.books.2.price',
             'store.books.3.price',
             ]
         self.assertItemsEqual(result, expected)
Example #10
0
 def test_fullslice_paths(self):
     for path in (
         "store.books[:].price",
         "store.books.:.price",
         "['store']['books'][':']['price']",
         "['store']['books'][:]['price']",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = [
             'store.books.0.price',
             'store.books.1.price',
             'store.books.2.price',
             'store.books.3.price'
             ]
         self.assertItemsEqual(result, expected)
Example #11
0
 def test_recursive_descent_paths(self):
     for path in (
         "store..price",
         "['store']..['price']",
         "$..price",
         "..price",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = [
             'store.books.0.price',
             'store.books.1.price',
             'store.books.2.price',
             'store.books.3.price',
             'store.bicycle.price',
             ]
         self.assertItemsEqual(result, expected)
Example #12
0
 def test_pipe_union_paths(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",
         ):
         result = list(querypath.paths(self.obj, path))
         expected = [
             'store.books.0.category',
             'store.books.1.category',
             'store.books.2.category',
             'store.books.3.category',
             'store.bicycle.color',
             ]
         self.assertItemsEqual(result, expected)
Example #13
0
 def test_script_query_paths(self):
     result = querypath.paths(self.obj, "store.books.*[?(@.price<10)].title")
     expected = ['store.books.0.title', 'store.books.2.title']
     self.assertItemsEqual(result, expected)
Example #14
0
 def test_root_paths(self):
     path = "$"
     result = list(querypath.paths(self.obj, path))
     expected = ['$']
     self.assertItemsEqual(result, expected)