|
18 | 18 | >>> a == 4 and b == 5 and c == 6 |
19 | 19 | True |
20 | 20 |
|
| 21 | +Unpack dict |
| 22 | +
|
| 23 | + >>> d = {4: 'four', 5: 'five', 6: 'six'} |
| 24 | + >>> a, b, c = d |
| 25 | + >>> a == 4 and b == 5 and c == 6 |
| 26 | + True |
| 27 | +
|
21 | 28 | Unpack implied tuple |
22 | 29 |
|
23 | 30 | >>> a, b, c = 7, 8, 9 |
|
63 | 70 |
|
64 | 71 | Unpacking tuple of wrong size |
65 | 72 |
|
66 | | - >>> a, b = t |
| 73 | + >>> a, b = t # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE |
67 | 74 | Traceback (most recent call last): |
68 | 75 | ... |
69 | | - ValueError: too many values to unpack (expected 2) |
| 76 | + ValueError: too many values to unpack (expected 2, got 3) |
70 | 77 |
|
71 | 78 | Unpacking tuple of wrong size |
72 | 79 |
|
73 | | - >>> a, b = l |
| 80 | + >>> a, b = l # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE |
74 | 81 | Traceback (most recent call last): |
75 | 82 | ... |
76 | | - ValueError: too many values to unpack (expected 2) |
| 83 | + ValueError: too many values to unpack (expected 2, got 3) |
77 | 84 |
|
78 | 85 | Unpacking sequence too short |
79 | 86 |
|
|
137 | 144 |
|
138 | 145 | Unpacking to an empty iterable should raise ValueError |
139 | 146 |
|
140 | | - >>> () = [42] |
| 147 | + >>> () = [42] # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE |
141 | 148 | Traceback (most recent call last): |
142 | 149 | ... |
143 | | - ValueError: too many values to unpack (expected 0) |
| 150 | + ValueError: too many values to unpack (expected 0, got 1) |
| 151 | +
|
| 152 | +Unpacking a larger iterable should raise ValuleError, but it |
| 153 | +should not entirely consume the iterable |
144 | 154 |
|
| 155 | + >>> it = iter(range(100)) |
| 156 | + >>> x, y, z = it |
| 157 | + Traceback (most recent call last): |
| 158 | + ... |
| 159 | + ValueError: too many values to unpack (expected 3) |
| 160 | + >>> next(it) # TODO: RUSTPYTHON; Raise `StopIteration` # doctest: +SKIP |
| 161 | + 4 |
| 162 | +
|
| 163 | +Unpacking unbalanced dict |
| 164 | +
|
| 165 | + >>> d = {4: 'four', 5: 'five', 6: 'six', 7: 'seven'} |
| 166 | + >>> a, b, c = d # TODO: RUSTPYTHON; # doctest: +EXPECTED_FAILURE |
| 167 | + Traceback (most recent call last): |
| 168 | + ... |
| 169 | + ValueError: too many values to unpack (expected 3, got 4) |
| 170 | +
|
| 171 | +Ensure that custom `__len__()` is NOT called when showing the error message |
| 172 | +
|
| 173 | + >>> class LengthTooLong: |
| 174 | + ... def __len__(self): |
| 175 | + ... return 5 |
| 176 | + ... def __getitem__(self, i): |
| 177 | + ... return i*2 |
| 178 | + ... |
| 179 | + >>> x, y, z = LengthTooLong() # TODO: RUSTPYTHON; Hangs # doctest: +SKIP |
| 180 | + Traceback (most recent call last): |
| 181 | + ... |
| 182 | + ValueError: too many values to unpack (expected 3) |
| 183 | +
|
| 184 | +For evil cases like these as well, no actual count to be shown |
| 185 | +
|
| 186 | + >>> class BadLength: |
| 187 | + ... def __len__(self): |
| 188 | + ... return 1 |
| 189 | + ... def __getitem__(self, i): |
| 190 | + ... return i*2 |
| 191 | + ... |
| 192 | + >>> x, y, z = BadLength() # TODO: RUSTPYTHON; Hangs # doctest: +SKIP |
| 193 | + Traceback (most recent call last): |
| 194 | + ... |
| 195 | + ValueError: too many values to unpack (expected 3) |
145 | 196 | """ |
146 | 197 |
|
147 | 198 | __test__ = {'doctests' : doctests} |
148 | 199 |
|
149 | 200 | def load_tests(loader, tests, pattern): |
150 | | - tests.addTest(doctest.DocTestSuite()) |
| 201 | + from test.support.rustpython import DocTestChecker # TODO: RUSTPYTHON |
| 202 | + tests.addTest(doctest.DocTestSuite(checker=DocTestChecker())) # XXX: RUSTPYTHON |
151 | 203 | return tests |
152 | 204 |
|
153 | 205 |
|
|
0 commit comments