-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsubscript_node_test.py
More file actions
52 lines (38 loc) · 1.86 KB
/
subscript_node_test.py
File metadata and controls
52 lines (38 loc) · 1.86 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Test the subscript object."""
from unittest import TestCase
from jsonpath2.node import MatchData
from jsonpath2.nodes.subscript import SubscriptNode
from jsonpath2.nodes.terminal import TerminalNode
from jsonpath2.subscript import Subscript
class TestSubscriptNode(TestCase):
"""Test the subscript base class."""
def test_badsubscript1(self):
"""Test subscript that does not provide terminal or other subscript."""
class BadSubscript1(Subscript):
"""Subscript that does not provide terminal or other subscript."""
def __jsonpath__(self):
"""Empty."""
return []
def match(self, root_value, current_value):
"""One."""
yield MatchData(None, root_value, current_value)
self.assertEqual("", BadSubscript1().tojsonpath())
with self.assertRaises(ValueError):
# NOTE Use 'list' to force the computation to occur, raising any exceptions.
list(SubscriptNode(TerminalNode(), [BadSubscript1()]).match(None, None))
def test_badsubscript2(self):
"""Test subscript that provides other subscript but not subscripted-terminal."""
class BadSubscript2(Subscript):
"""Subscript that provides other subscript but not subscripted-terminal."""
def __jsonpath__(self):
"""Empty."""
return []
def match(self, root_value, current_value):
"""One."""
yield MatchData(SubscriptNode(None), root_value, current_value)
self.assertEqual("", BadSubscript2().tojsonpath())
with self.assertRaises(ValueError):
# NOTE Use 'list' to force the computation to occur, raising any exceptions.
list(SubscriptNode(TerminalNode(), [BadSubscript2()]).match(None, None))