Skip to content

Commit 0832828

Browse files
ShaharNavehyouknowone
authored andcommitted
Update test_unpack.py from 3.14.3
1 parent 79453c3 commit 0832828

1 file changed

Lines changed: 59 additions & 7 deletions

File tree

Lib/test/test_unpack.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
>>> a == 4 and b == 5 and c == 6
1919
True
2020
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+
2128
Unpack implied tuple
2229
2330
>>> a, b, c = 7, 8, 9
@@ -63,17 +70,17 @@
6370
6471
Unpacking tuple of wrong size
6572
66-
>>> a, b = t
73+
>>> a, b = t # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE
6774
Traceback (most recent call last):
6875
...
69-
ValueError: too many values to unpack (expected 2)
76+
ValueError: too many values to unpack (expected 2, got 3)
7077
7178
Unpacking tuple of wrong size
7279
73-
>>> a, b = l
80+
>>> a, b = l # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE
7481
Traceback (most recent call last):
7582
...
76-
ValueError: too many values to unpack (expected 2)
83+
ValueError: too many values to unpack (expected 2, got 3)
7784
7885
Unpacking sequence too short
7986
@@ -137,17 +144,62 @@
137144
138145
Unpacking to an empty iterable should raise ValueError
139146
140-
>>> () = [42]
147+
>>> () = [42] # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE
141148
Traceback (most recent call last):
142149
...
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
144154
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)
145196
"""
146197

147198
__test__ = {'doctests' : doctests}
148199

149200
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
151203
return tests
152204

153205

0 commit comments

Comments
 (0)