Skip to content

Commit a885d26

Browse files
committed
Add unittest for issue #25
1 parent 04548ca commit a885d26

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

tests/test_json_with_lists.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# This file is subject to the terms and conditions defined in the
33
# file 'LICENSE', which is part of this source code package.
44
#
5-
from typing import List
5+
import json
6+
from typing import List, Optional
67

78
from tests.base_test import BaseTestCase
89
from python_easy_json import JSONObject
@@ -34,3 +35,30 @@ def test_data_with_lists(self):
3435
for i in obj.integer_list:
3536
self.assertIsInstance(i, int)
3637
self.assertIn(i, [1, 2, 3])
38+
39+
def test_nested_lists(self):
40+
""" User supplied unittest for issue #25 """
41+
class RR(JSONObject):
42+
values: Optional[list[int]] # here list is okay
43+
44+
class P(JSONObject):
45+
R: List[RR] # here list cannot be used
46+
47+
class Q(JSONObject):
48+
W: List[P] # and here too
49+
50+
class P2(JSONObject):
51+
R: List[RR] # here list cannot be used
52+
53+
class Q2(JSONObject):
54+
W: List[P] # and here too
55+
56+
data = json.loads('{"W": [{"R": [{"values": [1, 2, 3]}]}]}')
57+
# OK
58+
x = Q(data)
59+
self.assertIsInstance(x, Q)
60+
61+
# list() takes no keyword arguments
62+
data = json.loads('{"W": [{"R": [{"values": [1, 2, 3]}]}]}')
63+
x2 = Q2(data)
64+
self.assertIsInstance(x2, Q2)

0 commit comments

Comments
 (0)