-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
1190 lines (975 loc) · 51.8 KB
/
tests.py
File metadata and controls
1190 lines (975 loc) · 51.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import unittest
import logging
import jsonpyth as jp
logging.getLogger().setLevel(logging.ERROR)
class TestParse(unittest.TestCase):
# empty path
def test_raises_error_for_empty_path(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('')
# root symbol
def test_parses_start_root(self):
result = jp.parse('$')
self.assert_child_steps((jp.PRoot,), result)
def test_parses_root_in_path(self):
result = jp.parse('$.$')
self.assert_child_steps((jp.PRoot, jp.PRoot), result)
# name property
def test_parses_name_child(self):
result = jp.parse('$.foo')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('foo', result[1].targets[0].name)
def test_name_can_include_digit(self):
result = jp.parse('$.f00')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('f00', result[1].targets[0].name)
def test_raises_error_for_name_leading_digit(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.00f')
def test_name_can_include_underscore(self):
result = jp.parse('$.f_o')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('f_o', result[1].targets[0].name)
def test_raises_error_for_punctuation_in_name(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.f**')
# double-quoted string property
def test_parses_double_string_child(self):
result = jp.parse('$."foo"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('foo', result[1].targets[0].name)
def test_double_string_can_include_punctuation(self):
result = jp.parse('$."f**"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('f**', result[1].targets[0].name)
def test_double_string_can_include_unicode(self):
result = jp.parse('$."仮借文字"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('仮借文字', result[1].targets[0].name)
def test_raises_error_for_unclosed_double_string(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$."foo')
def test_raises_error_for_newline_in_double_string(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$."fo\no"')
def test_double_string_can_include_escaped_double_quote(self):
result = jp.parse('$."fo\\"o"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('fo"o', result[1].targets[0].name)
def test_double_string_can_include_escaped_backslash(self):
result = jp.parse('$."fo\\\\o"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('fo\\o', result[1].targets[0].name)
def test_double_string_can_include_single_quote(self):
result = jp.parse('$."fo\'o"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("fo'o", result[1].targets[0].name)
def test_double_string_can_start_with_digit(self):
result = jp.parse('$."00f"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("00f", result[1].targets[0].name)
def test_double_string_asterisk_is_not_wildcard(self):
result = jp.parse('$."*"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("*", result[1].targets[0].name)
def test_double_string_digit_is_not_index(self):
result = jp.parse('$."9"')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("9", result[1].targets[0].name)
def test_double_string_preserves_whitespace(self):
result = jp.parse('$." f o o "')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual(' f o o ', result[1].targets[0].name)
# single-quoted string property
def test_parses_single_string_child(self):
result = jp.parse("$.'foo'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('foo', result[1].targets[0].name)
def test_single_string_can_include_punctuation(self):
result = jp.parse("$.'f**'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('f**', result[1].targets[0].name)
def test_single_string_can_include_unicode(self):
result = jp.parse("$.'仮借文字'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('仮借文字', result[1].targets[0].name)
def test_raises_error_for_unclosed_single_string(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse("$.'foo")
def test_raises_error_for_newline_in_single_string(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse("$.'fo\no'")
def test_single_string_can_include_escaped_single_quote(self):
result = jp.parse("$.'fo\\'o'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("fo'o", result[1].targets[0].name)
def test_single_string_can_include_escaped_backslash(self):
result = jp.parse("$.'fo\\\\o'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("fo\\o", result[1].targets[0].name)
def test_single_string_can_include_double_quote(self):
result = jp.parse("$.'fo\"o'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('fo"o', result[1].targets[0].name)
def test_single_string_can_start_with_digit(self):
result = jp.parse("$.'00f'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("00f", result[1].targets[0].name)
def test_single_string_asterisk_is_not_wildcard(self):
result = jp.parse("$.'*'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("*", result[1].targets[0].name)
def test_single_string_digit_is_not_index(self):
result = jp.parse("$.'9'")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual("9", result[1].targets[0].name)
def test_single_string_preserves_whitespace(self):
result = jp.parse("$.' f o o '")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual(' f o o ', result[1].targets[0].name)
# child steps
def test_parses_multiple_child_steps(self):
result = jp.parse('$.foo.bar.weh.blah')
self.assert_types((jp.PChild, jp.PChild, jp.PChild, jp.PChild, jp.PChild), result)
def test_parses_first_child_step_without_root(self):
result = jp.parse('.foo')
self.assert_types((jp.PChild,), result)
self.assert_types((jp.PProperty,), result[0].targets)
self.assertEqual('foo', result[0].targets[0].name)
def test_parses_implicit_first_child_step_without_dot(self):
result = jp.parse('foo')
self.assert_types((jp.PChild,), result)
self.assert_types((jp.PProperty,), result[0].targets)
self.assertEqual('foo', result[0].targets[0].name)
def test_raises_error_for_child_dot_without_target(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.')
def test_parses_square_bracketted_child_step(self):
result = jp.parse('$[foo]')
self.assert_types((jp.PChild, jp.PChild), result)
self.assert_types((jp.PProperty,), result[1].targets)
self.assertEqual('foo', result[1].targets[0].name)
def test_parses_multiple_square_bracket_steps(self):
result = jp.parse('$[foo][bar]')
self.assert_types((jp.PChild, jp.PChild, jp.PChild), result)
self.assert_types((jp.PProperty,), result[1].targets)
self.assertEqual('foo', result[1].targets[0].name)
self.assert_types((jp.PProperty,), result[2].targets)
self.assertEqual('bar', result[2].targets[0].name)
def test_parses_mixed_dotted_and_bracketted_child_steps(self):
result = jp.parse('$.foo[bar].weh')
self.assert_child_steps((jp.PRoot, jp.PProperty, jp.PProperty, jp.PProperty), result)
def test_raises_error_for_unclosed_square_bracket(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$[foo')
def test_raises_error_for_child_with_both_dot_and_square_brackets(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.[foo]')
def test_raises_error_for_step_with_both_double_dot_and_square_brackets(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$..[foo]')
def test_raises_error_for_square_bracket_without_target(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$[]')
def test_parses_square_bracketted_root(self):
result = jp.parse('[$]')
self.assert_child_steps((jp.PRoot,),result)
def test_parses_square_bracketted_double_string(self):
result = jp.parse('$["foo"]')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('foo', result[1].targets[0].name)
def test_parses_square_bracketted_single_string(self):
result = jp.parse("$['foo']")
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
self.assertEqual('foo', result[1].targets[0].name)
# recursive step
def test_parses_name_recursive(self):
result = jp.parse('$..foo')
self.assert_types((jp.PChild, jp.PRecursive), result)
self.assert_types((jp.PProperty,), result[1].targets)
self.assertEqual('foo', result[1].targets[0].name)
def test_parses_mixed_child_and_recursive_steps(self):
result = jp.parse('$.foo..bar.weh..blah')
self.assert_types((jp.PChild, jp.PChild, jp.PRecursive, jp.PChild, jp.PRecursive), result)
def test_parses_first_recursive_step_without_root(self):
result = jp.parse('..foo')
self.assert_types((jp.PRecursive,), result)
self.assert_types((jp.PProperty,), result[0].targets)
self.assertEqual('foo', result[0].targets[0].name)
# whitespace
def test_ignores_spaces(self):
result = jp.parse(' $ . foo ')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
def test_ignores_newlines(self):
result = jp.parse('\n\n$\n.\n\nfoo\n\n\n')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
def test_ignores_tabs(self):
result = jp.parse('\t\t$\t.\t\tfoo\t\t\t')
self.assert_child_steps((jp.PRoot, jp.PProperty), result)
# current node symbol
def test_parses_current_node_symbol(self):
result = jp.parse('$.@')
self.assert_child_steps((jp.PRoot, jp.PCurrent), result)
def test_parses_current_node_at_start(self):
result = jp.parse('@.foo')
self.assert_child_steps((jp.PCurrent, jp.PProperty), result)
def test_parses_square_bracketted_current_node_symbol(self):
result = jp.parse('$[@]')
self.assert_child_steps((jp.PRoot, jp.PCurrent), result)
# wildcard symbol
def test_parses_wildcard(self):
result = jp.parse('$.*')
self.assert_child_steps((jp.PRoot, jp.PWildcard), result)
def test_parses_wildcard_at_start(self):
result = jp.parse('*.foo')
self.assert_child_steps((jp.PWildcard, jp.PProperty), result)
def test_parses_square_bracketted_wildcard(self):
result = jp.parse('$[*]')
self.assert_child_steps((jp.PRoot, jp.PWildcard), result)
# multiple targets
def test_parses_two_targets_for_step(self):
result = jp.parse('$.foo,bar')
self.assert_child_steps((jp.PRoot, (jp.PProperty, jp.PProperty)), result)
self.assertEqual('foo', result[1].targets[0].name)
self.assertEqual('bar', result[1].targets[1].name)
def test_parses_more_than_two_targets_for_step(self):
result = jp.parse('$.foo,bar,weh,blah')
self.assert_child_steps((jp.PRoot, (jp.PProperty, jp.PProperty, jp.PProperty, jp.PProperty)), result)
self.assertEqual('foo', result[1].targets[0].name)
self.assertEqual('bar', result[1].targets[1].name)
self.assertEqual('weh', result[1].targets[2].name)
self.assertEqual('blah',result[1].targets[3].name)
def test_parses_mixed_target_types(self):
result = jp.parse('$.foo,"bar",*,@')
self.assert_child_steps((jp.PRoot, (jp.PProperty, jp.PProperty, jp.PWildcard, jp.PCurrent)), result)
self.assertEqual('foo', result[1].targets[0].name)
self.assertEqual('bar', result[1].targets[1].name)
def test_raises_error_for_trailing_comma_on_targets(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.foo,')
def test_parses_multiple_multitarget_steps(self):
result = jp.parse('$.foo,bar.weh,blah')
self.assert_child_steps((jp.PRoot, (jp.PProperty, jp.PProperty), (jp.PProperty, jp.PProperty)), result)
def test_parses_square_bracketted_multiple_targets(self):
result = jp.parse('$[foo,bar]')
self.assert_child_steps((jp.PRoot, (jp.PProperty, jp.PProperty)), result)
self.assertEqual('foo', result[1].targets[0].name)
self.assertEqual('bar', result[1].targets[1].name)
def test_raises_error_for_empty_target_in_target_set(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.foo,,bar')
def test_raises_error_for_child_brackets_inside_target_set(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.foo,[bar]')
# slices
def test_parses_simple_index(self):
result = jp.parse('$.1')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertTrue(hasattr(targ, 'index'))
self.assertFalse(hasattr(targ, 'start'))
self.assertFalse(hasattr(targ, 'end'))
self.assertFalse(hasattr(targ, 'step'))
self.assertEqual(1, targ.index)
def test_parses_negative_index(self):
result = jp.parse('$.-1')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertTrue(hasattr(targ, 'index'))
self.assertEqual(-1, targ.index)
def test_parses_canonical_slice(self):
result = jp.parse('$.1:2:3')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertFalse(hasattr(targ, 'index'))
self.assertTrue(hasattr(targ, 'start'))
self.assertTrue(hasattr(targ, 'end'))
self.assertTrue(hasattr(targ, 'step'))
self.assertEqual(1, targ.start)
self.assertEqual(2, targ.end)
self.assertEqual(3, targ.step)
def test_parses_negatives_in_canonical_slice(self):
result = jp.parse('$.-1:-2:-3')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertEqual(-1, targ.start)
self.assertEqual(-2, targ.end)
self.assertEqual(-3, targ.step)
def test_parses_toend_slice(self):
result = jp.parse('$.1:')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertFalse(hasattr(targ, 'index'))
self.assertTrue(hasattr(targ, 'start'))
self.assertFalse(hasattr(targ, 'end'))
self.assertFalse(hasattr(targ, 'step'))
self.assertEqual(1, targ.start)
def test_parses_fromstart_slice(self):
result = jp.parse('$.:1')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertFalse(hasattr(targ, 'index'))
self.assertFalse(hasattr(targ, 'start'))
self.assertTrue(hasattr(targ, 'end'))
self.assertFalse(hasattr(targ, 'step'))
self.assertEqual(1, targ.end)
def test_parses_allwithstep_slice(self):
result = jp.parse('$.::1')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertFalse(hasattr(targ, 'index'))
self.assertFalse(hasattr(targ, 'start'))
self.assertFalse(hasattr(targ, 'end'))
self.assertTrue(hasattr(targ, 'step'))
self.assertEqual(1, targ.step)
def test_parses_all_slice(self):
result = jp.parse('$.:')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertFalse(hasattr(targ, 'index'))
self.assertFalse(hasattr(targ, 'start'))
self.assertFalse(hasattr(targ, 'end'))
self.assertFalse(hasattr(targ, 'step'))
def test_parses_other_slice_combinations(self):
for sl,ix,st,en,sp in [
# :
# :1
# 1:
('1:2', False,1, 2, False),
('::', False,False,False,False),
# ::1
(':1:', False,False,1, False),
(':1:2',False,False,1, 2 ),
('1::', False,1, False,False),
('1::2',False,1, False,2 ),
('1:2:',False,1, 2, False)
# 1:2:3
]:
with self.subTest(slice=sl):
result = jp.parse('$.{}'.format(sl))
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
for p,v in [('index',ix),('start',st),('end',en),('step',sp)]:
if v is False:
self.assertFalse(hasattr(targ, p))
else:
self.assertEqual(v, getattr(targ, p))
def test_parses_square_bracketted_slice(self):
result = jp.parse('$[1:2]')
self.assert_child_steps((jp.PRoot, jp.PSlice), result)
targ = result[1].targets[0]
self.assertFalse(hasattr(targ, 'index'))
self.assertTrue(hasattr(targ, 'start'))
self.assertTrue(hasattr(targ, 'end'))
self.assertFalse(hasattr(targ, 'step'))
self.assertEqual(1, targ.start)
self.assertEqual(2, targ.end)
# expressions
def test_parses_expression_child_step(self):
result = jp.parse('$.(1+1)')
self.assert_child_steps((jp.PRoot, jp.PExpression), result)
self.assertEqual('1+1', result[1].targets[0].code)
def test_expression_can_contain_other_path_symbols(self):
result = jp.parse('$.($@0f!仮*:[].?,)')
self.assert_child_steps((jp.PRoot, jp.PExpression), result)
self.assertEqual('$@0f!仮*:[].?,', result[1].targets[0].code)
def test_expression_can_contain_escaped_round_brackets(self):
result = jp.parse('$.(\\(1+1\\)*5)')
self.assert_child_steps((jp.PRoot, jp.PExpression), result)
self.assertEqual('(1+1)*5', result[1].targets[0].code)
def test_expression_can_contain_escaped_backslash(self):
result = jp.parse('$.(\\\\)')
self.assert_child_steps((jp.PRoot, jp.PExpression), result)
self.assertEqual('\\', result[1].targets[0].code)
def test_expression_can_contain_escaped_newline(self):
result = jp.parse('$.(\\n)')
self.assert_child_steps((jp.PRoot, jp.PExpression), result)
self.assertEqual('\n', result[1].targets[0].code)
def test_expression_preserves_whitespace(self):
result = jp.parse('$.( 1 + 1 )')
self.assert_child_steps((jp.PRoot, jp.PExpression), result)
self.assertEqual(' 1 + 1 ', result[1].targets[0].code)
def test_raises_error_for_expression_without_closing_bracket(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.(1+1')
def test_raises_error_for_expression_containing_newline(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.(1\n+\n1)')
def test_parses_square_bracketted_expression(self):
result = jp.parse('$[(1+1)]')
self.assert_child_steps((jp.PRoot, jp.PExpression), result)
self.assertEqual('1+1', result[1].targets[0].code)
def test_parses_empty_expression(self):
result = jp.parse('$.()')
self.assert_child_steps((jp.PRoot, jp.PExpression), result)
self.assertEqual('', result[1].targets[0].code)
# filters
def test_parses_filter_child_step(self):
result = jp.parse('$.?(1+1)')
self.assert_child_steps((jp.PRoot, jp.PFilter), result)
self.assertEqual('1+1', result[1].targets[0].code)
def test_filter_can_contain_other_path_symbols(self):
result = jp.parse('$.?($@0f!仮*:[].?,)')
self.assert_child_steps((jp.PRoot, jp.PFilter), result)
self.assertEqual('$@0f!仮*:[].?,', result[1].targets[0].code)
def test_filter_can_contain_escaped_round_brackets(self):
result = jp.parse('$.?(\\(1+1\\)*5)')
self.assert_child_steps((jp.PRoot, jp.PFilter), result)
self.assertEqual('(1+1)*5', result[1].targets[0].code)
def test_filter_can_contain_escaped_backslash(self):
result = jp.parse('$.?(\\\\)')
self.assert_child_steps((jp.PRoot, jp.PFilter), result)
self.assertEqual('\\', result[1].targets[0].code)
def test_filter_can_contain_escaped_newline(self):
result = jp.parse('$.?(\\n)')
self.assert_child_steps((jp.PRoot, jp.PFilter), result)
self.assertEqual('\n', result[1].targets[0].code)
def test_filter_preserves_whitespace(self):
result = jp.parse('$.?( True or False )')
self.assert_child_steps((jp.PRoot, jp.PFilter), result)
self.assertEqual(' True or False ', result[1].targets[0].code)
def test_raises_error_for_filter_without_closing_bracket(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.?(1+1')
def test_raises_error_for_filter_containing_newline(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.?(1\n+\n1)')
def test_parses_square_bracketted_filter(self):
result = jp.parse('$[?(1+1)]')
self.assert_child_steps((jp.PRoot, jp.PFilter), result)
self.assertEqual('1+1', result[1].targets[0].code)
def test_parses_empty_filter(self):
result = jp.parse('$.?()')
self.assert_child_steps((jp.PRoot, jp.PFilter), result)
self.assertEqual('', result[1].targets[0].code)
# general bad input
def test_raises_error_for_invalid_child_target(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$.~')
def test_raises_error_for_invalid_square_bracketted_child_target(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('$[~]')
def test_raises_error_for_invalid_child_target_at_start(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('.~')
def test_raises_error_for_invalid_implicit_child_target(self):
with self.assertRaises(jp.JsonPathSyntaxError):
jp.parse('~')
# helper methods
def assert_types(self, expected, result):
self.assertEqual(expected, tuple(type(s) for s in result))
def assert_child_steps(self, expected, result):
targs = []
for s in result:
self.assertEqual(jp.PChild, type(s))
targs.append(tuple(type(t) for t in s.targets) if len(s.targets) > 1 else type(s.targets[0]))
self.assertEqual(expected, tuple(targs))
class TestEvaluate(unittest.TestCase):
example = {
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95,
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99,
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99,
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99,
},
],
"bicycle": {
"color": "red",
"price": 19.95,
},
}
}
# root & property child steps
def test_evaluates_root_child(self):
result = jp.evaluate({"a":1,"b":[2,3]}, [jp.PChild(targets=[jp.PRoot()])])
self.assertEqual([( {"a":1,"b":[2,3]}, '$' )], result)
def test_evaluates_property_child(self):
result = jp.evaluate({"a":1,"b":[2,3]}, [jp.PChild(targets=[jp.PProperty(name='b')])])
self.assertEqual([( [2,3], '$["b"]' )], result)
def test_evaluates_root_mid_path(self):
result = jp.evaluate({"a":1,"b":[2,3]},
[jp.PChild(targets=[jp.PRoot()]), jp.PChild(targets=[jp.PProperty(name='b')]),
jp.PChild(targets=[jp.PRoot()]), jp.PChild(targets=[jp.PProperty(name='a')])] )
self.assertEqual([( 1, '$["a"]' )], result)
def test_evaluates_nested_child_properties(self):
result = jp.evaluate({"a":{"b":1,"c":2},"d":3},
[jp.PChild(targets=[jp.PProperty(name='a')]), jp.PChild(targets=[jp.PProperty(name='b')])])
self.assertEqual([( 1, '$["a"]["b"]' )], result)
# current node
def test_evaluates_current_child(self):
result = jp.evaluate({"a":{"b":1,"c":2},"d":3},
[jp.PChild(targets=[jp.PProperty(name='a')]), jp.PChild(targets=[jp.PCurrent()]),
jp.PChild(targets=[jp.PProperty(name='c')])] )
self.assertEqual([( 2, '$["a"]["c"]' )], result)
# target sets
def test_evaluates_multipletarget_child(self):
result = jp.evaluate({"a":{"b":1,"c":2},"d":3},
[jp.PChild(targets=[jp.PProperty(name='a')]),
jp.PChild(targets=[jp.PProperty(name='b'),jp.PProperty(name='c')])] )
self.assertEqual([( 1, '$["a"]["b"]' ), ( 2, '$["a"]["c"]' )], result)
def test_evaluates_multipletarget_child_mid_path(self):
result = jp.evaluate({"a":{"b":{"c":1,"d":2},"e":{"c":3,"d":4}},"f":0},
[jp.PChild(targets=[jp.PProperty(name='a')]),
jp.PChild(targets=[jp.PProperty(name='b'),jp.PProperty(name='e')]),
jp.PChild(targets=[jp.PProperty(name='c')])] )
self.assertEqual([( 1, '$["a"]["b"]["c"]' ), ( 3, '$["a"]["e"]["c"]' )], result)
def test_evaluates_nested_multipletarget_child_steps(self):
result = jp.evaluate({"A":{"i":1,"ii":2,"iii":3},
"B":{"i":4,"ii":5,"iii":6},
"C":{"i":7,"ii":8,"iii":9}},
[jp.PChild(targets=[jp.PProperty(name='A'),jp.PProperty(name='C')]),
jp.PChild(targets=[jp.PProperty(name='ii'),jp.PProperty(name='iii')])] )
self.assertEqual([( 2, '$["A"]["ii"]' ), ( 8, '$["C"]["ii"]' ),
( 3, '$["A"]["iii"]' ), ( 9, '$["C"]["iii"]' )], result)
# wildcards
def test_evaluates_wildcard_child_for_dict_in_sort_order(self):
result = jp.evaluate({"a":1,"c":[3,4],"b":2,},
[jp.PChild(targets=[jp.PWildcard()])] )
self.assertEqual([( 1, '$["a"]' ), ( 2, '$["b"]' ), ( [3,4], '$["c"]' )], result)
def test_evaluates_wildcard_child_for_sequence_in_sequence_order(self):
result = jp.evaluate([2,1,[3,4]],
[jp.PChild(targets=[jp.PWildcard()])] )
self.assertEqual([(2, '$[0]'), (1, '$[1]'), ([3,4], '$[2]')], result)
def test_evaluates_wildcard_mid_path(self):
result = jp.evaluate({"a":1,"b":[{"i":1,"ii":2},{"i":3,"ii":4},{"i":5,"ii":6}]},
[jp.PChild(targets=[jp.PProperty(name='b')]),
jp.PChild(targets=[jp.PWildcard()]),
jp.PChild(targets=[jp.PProperty(name='ii')])] )
self.assertEqual([(2, '$["b"][0]["ii"]'), (4, '$["b"][1]["ii"]'),
(6, '$["b"][2]["ii"]')], result)
def test_evaluates_nested_wildcard_steps(self):
result = jp.evaluate({ "i":{"a":[{"a":1,"b":2},{"a":3,"b":4}],
"b":[{"a":5,"b":6},{"a":7,"b":8}]},
"ii":{"a":[{"a":9,"b":1},{"a":2,"b":3}],
"b":[{"a":4,"b":5},{"a":6,"b":7}]} },
[jp.PChild(targets=[jp.PWildcard()]), jp.PChild(targets=[jp.PProperty(name='a')]),
jp.PChild(targets=[jp.PWildcard()]), jp.PChild(targets=[jp.PProperty(name='b')])] )
self.assertEqual([(2, '$["i"]["a"][0]["b"]'), (4, '$["i"]["a"][1]["b"]'),
(1, '$["ii"]["a"][0]["b"]'),(3, '$["ii"]["a"][1]["b"]')], result)
def test_evaluates_multiple_wildcard_targets_by_duplicating(self):
result = jp.evaluate([4,2],
[jp.PChild(targets=[jp.PWildcard(),jp.PWildcard()])] )
self.assertEqual([(4, '$[0]'), (2, '$[1]'), (4, '$[0]'), (2, '$[1]')], result)
# slices
def test_evaluates_simple_index_slice(self):
result = jp.evaluate(["a","b","c","d","e"],
[jp.PChild(targets=[jp.PSlice(index=3)])])
self.assertEqual([("d", '$[3]')], result)
def test_evaluates_slice_with_step(self):
result = jp.evaluate(["a","b","c","d","e","f","g"],
[jp.PChild(targets=[jp.PSlice(start=1,end=5,step=2)])] )
self.assertEqual([('b', '$[1]'), ('d', '$[3]')], result)
def test_evaluates_slice_without_step(self):
result = jp.evaluate(["a","b","c","d","e"],
[jp.PChild(targets=[jp.PSlice(start=1,end=3)])] )
self.assertEqual([('b', '$[1]'), ('c', '$[2]')], result)
def test_evaluates_slice_without_end(self):
result = jp.evaluate(["a","b","c","d"],
[jp.PChild(targets=[jp.PSlice(start=2)])] )
self.assertEqual([('c', '$[2]'), ('d', '$[3]')], result)
def test_evaluates_slice_without_start(self):
result = jp.evaluate(["a","b","c","d"],
[jp.PChild(targets=[jp.PSlice(end=2)])] )
self.assertEqual([('a', '$[0]'), ('b', '$[1]')], result)
def test_evaluates_slice_with_negative_start(self):
result = jp.evaluate(["a","b","c","d"],
[jp.PChild(targets=[jp.PSlice(start=-2)])] )
self.assertEqual([('c', '$[2]'), ('d', '$[3]')], result)
def test_evaluates_slice_with_negative_end(self):
result = jp.evaluate(["a","b","c","d"],
[jp.PChild(targets=[jp.PSlice(end=-1)])] )
self.assertEqual([('a', '$[0]'), ('b', '$[1]'), ('c', '$[2]')], result)
def test_evaluates_slice_with_negative_step(self):
result = jp.evaluate(["a","b","c","d"],
[jp.PChild(targets=[jp.PSlice(step=-2)])] )
self.assertEqual([('d', '$[3]'), ('b', '$[1]')], result)
def test_evaluates_slice_mid_path(self):
result = jp.evaluate({"a":[{"i":1,"ii":2},{"i":3,"ii":4},
{"i":5,"ii":6},{"i":7,"ii":8}]},
[jp.PChild(targets=[jp.PProperty(name='a')]),
jp.PChild(targets=[jp.PSlice(start=1,end=3)]),
jp.PChild(targets=[jp.PProperty(name='ii')])] )
self.assertEqual([(4, '$["a"][1]["ii"]'), (6, '$["a"][2]["ii"]')], result)
def test_evaluates_nested_slice_steps(self):
result = jp.evaluate([{"a":["x","y"],"b":["z","x"]},{"a":["y","z"],"b":["x","y"]},
{"a":["z","x"],"b":["y","z"]},{"a":["x","y"],"b":["z","x"]}],
[jp.PChild(targets=[jp.PSlice(start=1,end=3)]),
jp.PChild(targets=[jp.PProperty(name='a')]),
jp.PChild(targets=[jp.PSlice(index=1)])] )
self.assertEqual([('z', '$[1]["a"][1]'), ('x', '$[2]["a"][1]')], result)
def test_evaluates_multiple_slice_targets(self):
result = jp.evaluate(['a','b','c'],
[jp.PChild(targets=[jp.PSlice(start=1),jp.PSlice(end=-1)])] )
self.assertEqual([('b', '$[1]'), ('c', '$[2]'), ('a', '$[0]'), ('b', '$[1]')], result)
# recursive steps
def test_evaluates_recursive_step_in_top_down_order(self):
result = jp.evaluate({"a":{"a":{"a":1}}},
[jp.PRecursive(targets=[jp.PProperty(name='a')])] )
self.assertEqual([({"a":{"a":1}},'$["a"]'), ({"a":1}, '$["a"]["a"]'),
(1, '$["a"]["a"]["a"]')], result)
def test_evaluates_recursive_step_breadth_first(self):
result = jp.evaluate([[9,8,7],[6,5,4],[3,2,1]],
[jp.PRecursive(targets=[jp.PSlice(start=1)])] )
self.assertEqual([([6,5,4], '$[1]'), ([3,2,1], '$[2]'),
(8, '$[0][1]'), (7, '$[0][2]'),
(5, '$[1][1]'), (4, '$[1][2]'),
(2, '$[2][1]'), (1, '$[2][2]')], result)
def test_evaluates_properties_in_sort_order_for_recursive_step(self):
result = jp.evaluate({"c":{"a":{"a":1},"b":2},"b":[{"a":2},4],"a":0},
[jp.PRecursive(targets=[jp.PProperty(name='a')])] )
self.assertEqual([(0, '$["a"]'), ({"a":1}, '$["c"]["a"]'), (2, '$["b"][0]["a"]'),
(1, '$["c"]["a"]["a"]')], result)
def test_evaluates_recursive_step_with_multiple_targets(self):
result = jp.evaluate({"c":{"a":{"a":1},"b":2},"b":[{"a":2},4],"a":0},
[jp.PRecursive(targets=[jp.PProperty(name='a'),jp.PProperty(name='b')])] )
self.assertEqual([(0, '$["a"]'), ([{"a":2},4], '$["b"]'), ({"a":1}, '$["c"]["a"]'),
(2, '$["c"]["b"]'), (2, '$["b"][0]["a"]'), (1, '$["c"]["a"]["a"]')], result)
def test_evaluates_nested_recursive_steps(self):
result = jp.evaluate({"b":{"b":4,"a":{"b":{"b":2},"a":5}},"a":{"b":3,"a":{"b":1}}},
[jp.PRecursive(targets=[jp.PProperty(name='a')]),
jp.PRecursive(targets=[jp.PProperty(name='b')])])
self.assertEqual([(3, '$["a"]["b"]'), (1, '$["a"]["a"]["b"]'),
({"b":2}, '$["b"]["a"]["b"]'), (1, '$["a"]["a"]["b"]'),
(2, '$["b"]["a"]["b"]["b"]')], result)
# expressions
def test_evaluates_expression_child_for_key(self):
result = jp.evaluate({"bar":1, "foo":2, "weh":3},
[jp.PChild(targets=[jp.PExpression(code='"foo"')])] )
self.assertEqual([(2, '$["foo"]')], result)
def test_evaluates_expression_child_for_index(self):
result = jp.evaluate([1,2,3],
[jp.PChild(targets=[jp.PExpression(code='1')])] )
self.assertEqual([(2, '$[1]')], result)
def test_ignores_non_string_expression_for_key(self):
result = jp.evaluate({"11":1, "101":2, "1001":3},
[jp.PChild(targets=[jp.PExpression(code='101')])] )
self.assertEqual([], result)
def test_ignores_non_numeric_expression_for_index(self):
result = jp.evaluate([1,2,3],
[jp.PChild(targets=[jp.PExpression(code='"2"')])] )
self.assertEqual([], result)
def test_ignores_non_numeric_expression_for_index_even_if_bool(self):
result = jp.evaluate([1,2,3],
[jp.PChild(targets=[jp.PExpression(code='True')])] )
self.assertEqual([], result)
def test_evaluates_operators_in_expression(self):
result = jp.evaluate([1,2,3,4,5],
[jp.PChild(targets=[jp.PExpression(code='2**3/(2+2)')])] )
self.assertEqual([(3, '$[2]')], result)
def test_evaluates_current_node_in_expression(self):
result = jp.evaluate([1,2,3,4,5],
[jp.PChild(targets=[jp.PExpression(code='@[2]+1')])] )
self.assertEqual([(5, '$[4]')], result)
def test_raises_error_for_bad_syntax_in_expression(self):
with self.assertRaises(jp.PythonSyntaxError):
jp.evaluate([1,2,3,4,5],
[jp.PChild(targets=[jp.PExpression(code='^!*&~')])] )
def test_evaluates_expression_with_builtins(self):
result = jp.evaluate([1,2,3,4,5],
[jp.PChild(targets=[jp.PExpression(code='len("foo")')])] )
self.assertEqual([(4, '$[3]')], result)
def test_evaluates_escaped_at_symbol_in_expression_as_plain_at(self):
result = jp.evaluate({"@":1,"~":2},
[jp.PChild(targets=[jp.PExpression(code='"\\@"')])] )
self.assertEqual([(1, '$["@"]')], result)
def test_evaluates_expression_with_actual_backslash_preceeding_current_node(self):
result = jp.evaluate({"\\__current":1,"~":2},
[jp.PChild(targets=[jp.PExpression(code='"\\\\@"')])] )
self.assertEqual([(1, '$["\\\\__current"]')], result)
def test_evaluates_escaped_at_symbol_with_multiple_actual_backslashes_preceeding(self):
result = jp.evaluate({'\\\\@':1,'~':2},
[jp.PChild(targets=[jp.PExpression(code='"\\\\\\\\\\@"')])] )
self.assertEqual([(1, '$["\\\\\\\\@"]')], result)
def test_evaluates_current_node_with_multiple_actual_backslashes_preceeding(self):
result = jp.evaluate({"\\\\__current":1,"~":2},
[jp.PChild(targets=[jp.PExpression(code='"\\\\\\\\@"')])] )
self.assertEqual([(1, '$["\\\\\\\\__current"]')], result)
def test_evaluates_root_node_in_expression(self):
result = jp.evaluate({'a':['i','ii','iii'],'b':1},
[jp.PChild(targets=[jp.PProperty(name='a')]),
jp.PChild(targets=[jp.PExpression(code='$["b"]')])] )
self.assertEqual([('ii', '$["a"][1]')], result)
def test_evaluates_escaped_dollar_symbol_in_expression_as_plain_dollar(self):
result = jp.evaluate({"~":1,"$":2},
[jp.PChild(targets=[jp.PExpression(code='"\\$"')])] )
self.assertEqual([(2, '$["$"]')], result)
def test_evaluates_expression_with_actual_backslash_preceeding_root_node(self):
result = jp.evaluate({'\\__root':1,'~':2},
[jp.PChild(targets=[jp.PExpression(code='"\\\\$"')])] )
self.assertEqual([(1, '$["\\\\__root"]')], result)
def test_evaluates_escaped_dollar_symbol__with_multiple_actual_backslashes_preceeding(self):
result = jp.evaluate({'\\\\$':1,'~':2},
[jp.PChild(targets=[jp.PExpression(code='"\\\\\\\\\\$"')])] )
self.assertEqual([(1, '$["\\\\\\\\$"]')], result)
def test_evaluates_root_node_with_multiple_actual_backslashes_preceeding(self):
result = jp.evaluate({'\\\\__root':1,'~':2},
[jp.PChild(targets=[jp.PExpression(code='"\\\\\\\\$"')])] )
self.assertEqual([(1, '$["\\\\\\\\__root"]')], result)
# filters
def test_evaluates_filter_child_for_dict(self):
result = jp.evaluate({"a":1, "b":2, "c":3},
[jp.PChild(targets=[jp.PFilter(code='True')])] )
self.assertEqual([(1, '$["a"]'), (2, '$["b"]'), (3, '$["c"]')], result)
def test_evaluates_filter_child_for_sequence(self):
result = jp.evaluate(["a","b","c"],
[jp.PChild(targets=[jp.PFilter(code='True')])] )
self.assertEqual([("a", '$[0]'), ("b", '$[1]'), ("c", '$[2]')], result)
def test_evaluates_operators_in_filter(self):
result = jp.evaluate(["a","b","c"],
[jp.PChild(targets=[jp.PFilter(code='1>0 or 0>1')])] )
self.assertEqual([("a", '$[0]'), ("b", '$[1]'), ("c", '$[2]')], result)
def test_evaluates_current_node_in_filter(self):
result = jp.evaluate(["foo","bar","baz"],
[jp.PChild(targets=[jp.PFilter(code='"a" in @')])] )
self.assertEqual([("bar", '$[1]'), ("baz", '$[2]')], result)
def test_evaluates_non_boolean_result_for_filter(self):
result = jp.evaluate([1,6,4,3,8],
[jp.PChild(targets=[jp.PFilter(code='@ % 3')])] )
self.assertEqual([(1, '$[0]'), (4, '$[2]'), (8, '$[4]')], result)
def test_raises_error_for_bad_syntax_in_filter(self):
with self.assertRaises(jp.PythonSyntaxError):
jp.evaluate([1,2,3,4,5],
[jp.PChild(targets=[jp.PExpression(code='^!*&~')])] )
def test_evaluates_filter_with_builtins(self):
result = jp.evaluate([1,2,3],
[jp.PChild(targets=[jp.PFilter(code='len("foo") > 2')])] )
self.assertEqual([(1, '$[0]'), (2, '$[1]'), (3, '$[2]')], result)
def test_evaluates_root_node_in_filter(self):
result = jp.evaluate({"a":2, "b":3, "c":1},
[jp.PChild(targets=[jp.PFilter(code='@ >= $["a"]')])] )
self.assertEqual([(2, '$["a"]'), (3, '$["b"]')], result)
# failed steps
def test_ignores_missing_property(self):
result = jp.evaluate([{'b':1},{'a':2},{'a':3,'b':4}],
[jp.PChild(targets=[jp.PWildcard()]),
jp.PChild(targets=[jp.PProperty(name='b')])] )
self.assertEqual([(1, '$[0]["b"]'), (4, '$[2]["b"]')], result)
def test_ignores_missing_index(self):
result = jp.evaluate({'a':['i','ii'], 'b':['iv','v','vi'], 'c':['vii','viii','ix']},
[jp.PChild(targets=[jp.PWildcard()]),
jp.PChild(targets=[jp.PSlice(index=2)])] )
self.assertEqual([('vi', '$["b"][2]'), ('ix', '$["c"][2]')], result)
def test_ignores_property_on_non_dict(self):
result = jp.evaluate([1,'a',{'b':4},[2,3]],
[jp.PChild(targets=[jp.PWildcard()]),
jp.PChild(targets=[jp.PProperty(name='b')])] )
self.assertEqual([(4, '$[2]["b"]')], result)
def test_ignores_index_on_non_sequence(self):
result = jp.evaluate([1,'a',{'b':4},[2,3]],
[jp.PChild(targets=[jp.PWildcard()]),
jp.PChild(targets=[jp.PSlice(index=1)])] )
self.assertEqual([(3, '$[3][1]')], result)
def test_applies_partial_slice_to_short_sequence(self):
result = jp.evaluate(['a','b','c','d'],
[jp.PChild(targets=[jp.PSlice(start=1, end=10)])] )
self.assertEqual([('b', '$[1]'), ('c', '$[2]'), ('d', '$[3]')], result)
def test_ignores_non_syntax_error_in_expression(self):
result = jp.evaluate(['a','b','c'],
[jp.PChild(targets=[jp.PExpression(code='len("a") > foo')])] )
self.assertEqual([], result)
def test_ignores_non_syntax_error_in_filter(self):
result = jp.evaluate(['ay','bee','eff'],
[jp.PChild(targets=[jp.PFilter(code='@[2] == "e"')])] )
self.assertEqual([('bee', '$[1]')], result)
# spec examples
def test_example_book_store_authors(self):
result = jp.evaluate(self.example,
[jp.PChild(targets=[jp.PRoot()]),
jp.PChild(targets=[jp.PProperty(name='store')]),
jp.PChild(targets=[jp.PProperty(name='book')]),
jp.PChild(targets=[jp.PWildcard()]),