|
2 | 2 | # This file is subject to the terms and conditions defined in the |
3 | 3 | # file 'LICENSE', which is part of this source code package. |
4 | 4 | # |
5 | | -from typing import List |
| 5 | +import json |
| 6 | +from typing import List, Optional |
6 | 7 |
|
7 | 8 | from tests.base_test import BaseTestCase |
8 | 9 | from python_easy_json import JSONObject |
@@ -34,3 +35,30 @@ def test_data_with_lists(self): |
34 | 35 | for i in obj.integer_list: |
35 | 36 | self.assertIsInstance(i, int) |
36 | 37 | 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