Skip to content

Commit 2d6a1af

Browse files
committed
Fix/mark itertools tests.
1 parent 611b4b4 commit 2d6a1af

File tree

4 files changed

+126
-25
lines changed

4 files changed

+126
-25
lines changed

Lib/test/test_itertools.py

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def expand(it, i=0):
120120
c = expand(compare[took:])
121121
self.assertEqual(a, c);
122122

123+
# TODO: RUSTPYTHON
124+
@unittest.expectedFailure
123125
def test_accumulate(self):
124126
self.assertEqual(list(accumulate(range(10))), # one positional arg
125127
[0, 1, 3, 6, 10, 15, 21, 28, 36, 45])
@@ -177,6 +179,8 @@ def test_chain_from_iterable(self):
177179
self.assertEqual(take(4, chain.from_iterable(['abc', 'def'])), list('abcd'))
178180
self.assertRaises(TypeError, list, chain.from_iterable([2, 3]))
179181

182+
# TODO: RUSTPYTHON
183+
@unittest.expectedFailure
180184
def test_chain_reducible(self):
181185
for oper in [copy.deepcopy] + picklecopiers:
182186
it = chain('abc', 'def')
@@ -190,6 +194,8 @@ def test_chain_reducible(self):
190194
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
191195
self.pickletest(proto, chain('abc', 'def'), compare=list('abcdef'))
192196

197+
# TODO: RUSTPYTHON
198+
@unittest.expectedFailure
193199
def test_chain_setstate(self):
194200
self.assertRaises(TypeError, chain().__setstate__, ())
195201
self.assertRaises(TypeError, chain().__setstate__, [])
@@ -203,6 +209,8 @@ def test_chain_setstate(self):
203209
it.__setstate__((iter(['abc', 'def']), iter(['ghi'])))
204210
self.assertEqual(list(it), ['ghi', 'a', 'b', 'c', 'd', 'e', 'f'])
205211

212+
# TODO: RUSTPYTHON
213+
@unittest.expectedFailure
206214
def test_combinations(self):
207215
self.assertRaises(TypeError, combinations, 'abc') # missing r argument
208216
self.assertRaises(TypeError, combinations, 'abc', 2, 1) # too many arguments
@@ -294,6 +302,8 @@ def test_combinations_tuple_reuse(self):
294302
self.assertEqual(len(set(map(id, combinations('abcde', 3)))), 1)
295303
self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3))))), 1)
296304

305+
# TODO: RUSTPYTHON
306+
@unittest.expectedFailure
297307
def test_combinations_with_replacement(self):
298308
cwr = combinations_with_replacement
299309
self.assertRaises(TypeError, cwr, 'abc') # missing r argument
@@ -382,6 +392,8 @@ def test_combinations_with_replacement_tuple_reuse(self):
382392
self.assertEqual(len(set(map(id, cwr('abcde', 3)))), 1)
383393
self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3))))), 1)
384394

395+
# TODO: RUSTPYTHON - panics with 'index out of bounds: the len is 0 but the index is 18446744073709551615'
396+
@unittest.skip("panics")
385397
def test_permutations(self):
386398
self.assertRaises(TypeError, permutations) # too few arguments
387399
self.assertRaises(TypeError, permutations, 'abc', 2, 1) # too many arguments
@@ -455,6 +467,8 @@ def test_permutations_tuple_reuse(self):
455467
self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1)
456468
self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3))))), 1)
457469

470+
# TODO: RUSTPYTHON - panics with 'index out of bounds: the len is 0 but the index is 18446744073709551615'
471+
@unittest.skip("panics")
458472
def test_combinatorics(self):
459473
# Test relationships between product(), permutations(),
460474
# combinations() and combinations_with_replacement().
@@ -488,6 +502,8 @@ def test_combinatorics(self):
488502
self.assertEqual(comb, list(filter(set(perm).__contains__, cwr))) # comb: cwr that is a perm
489503
self.assertEqual(comb, sorted(set(cwr) & set(perm))) # comb: both a cwr and a perm
490504

505+
# TODO: RUSTPYTHON
506+
@unittest.expectedFailure
491507
def test_compress(self):
492508
self.assertEqual(list(compress(data='ABCDEF', selectors=[1,0,1,0,1,1])), list('ACEF'))
493509
self.assertEqual(list(compress('ABCDEF', [1,0,1,0,1,1])), list('ACEF'))
@@ -521,7 +537,8 @@ def test_compress(self):
521537
next(testIntermediate)
522538
self.assertEqual(list(op(testIntermediate)), list(result2))
523539

524-
540+
# TODO: RUSTPYTHON
541+
@unittest.expectedFailure
525542
def test_count(self):
526543
self.assertEqual(lzip('abc',count()), [('a', 0), ('b', 1), ('c', 2)])
527544
self.assertEqual(lzip('abc',count(3)), [('a', 3), ('b', 4), ('c', 5)])
@@ -570,6 +587,8 @@ def test_count(self):
570587
#check proper internal error handling for large "step' sizes
571588
count(1, maxsize+5); sys.exc_info()
572589

590+
# TODO: RUSTPYTHON
591+
@unittest.expectedFailure
573592
def test_count_with_stride(self):
574593
self.assertEqual(lzip('abc',count(2,3)), [('a', 2), ('b', 5), ('c', 8)])
575594
self.assertEqual(lzip('abc',count(start=2,step=3)),
@@ -625,6 +644,8 @@ def test_count_with_stride(self):
625644
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
626645
self.pickletest(proto, count(i, j))
627646

647+
# TODO: RUSTPYTHON
648+
@unittest.expectedFailure
628649
def test_cycle(self):
629650
self.assertEqual(take(10, cycle('abc')), list('abcabcabca'))
630651
self.assertEqual(list(cycle('')), [])
@@ -667,6 +688,8 @@ def test_cycle(self):
667688
d = pickle.loads(p) # rebuild the cycle object
668689
self.assertEqual(take(20, d), list('cdeabcdeabcdeabcdeab'))
669690

691+
# TODO: RUSTPYTHON
692+
@unittest.expectedFailure
670693
def test_cycle_setstate(self):
671694
# Verify both modes for restoring state
672695

@@ -703,6 +726,8 @@ def test_cycle_setstate(self):
703726
self.assertRaises(TypeError, cycle('').__setstate__, ())
704727
self.assertRaises(TypeError, cycle('').__setstate__, ([],))
705728

729+
# TODO: RUSTPYTHON
730+
@unittest.expectedFailure
706731
def test_groupby(self):
707732
# Check whether it accepts arguments correctly
708733
self.assertEqual([], list(groupby([])))
@@ -833,6 +858,8 @@ def keyfunc(obj):
833858
keyfunc.skip = 1
834859
self.assertRaises(ExpectedError, gulp, [None, None], keyfunc)
835860

861+
# TODO: RUSTPYTHON
862+
@unittest.expectedFailure
836863
def test_filter(self):
837864
self.assertEqual(list(filter(isEven, range(6))), [0,2,4])
838865
self.assertEqual(list(filter(None, [0,1,0,2,0])), [1,2])
@@ -860,6 +887,8 @@ def test_filter(self):
860887
c = filter(isEven, range(6))
861888
self.pickletest(proto, c)
862889

890+
# TODO: RUSTPYTHON
891+
@unittest.expectedFailure
863892
def test_filterfalse(self):
864893
self.assertEqual(list(filterfalse(isEven, range(6))), [1,3,5])
865894
self.assertEqual(list(filterfalse(None, [0,1,0,2,0])), [0,0,0])
@@ -965,6 +994,8 @@ def test_zip_longest_tuple_reuse(self):
965994
ids = list(map(id, list(zip_longest('abc', 'def'))))
966995
self.assertEqual(len(dict.fromkeys(ids)), len(ids))
967996

997+
# TODO: RUSTPYTHON
998+
@unittest.expectedFailure
968999
def test_zip_longest_pickling(self):
9691000
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
9701001
self.pickletest(proto, zip_longest("abc", "def"))
@@ -1024,6 +1055,8 @@ def run(r1, r2):
10241055
self.assertEqual(next(it), (1, 2))
10251056
self.assertRaises(RuntimeError, next, it)
10261057

1058+
# TODO: RUSTPYTHON - panics with 'index out of bounds: the len is 0 but the index is 18446744073709551615'
1059+
@unittest.skip("panics")
10271060
def test_product(self):
10281061
for args, result in [
10291062
([], [()]), # zero iterables
@@ -1092,6 +1125,8 @@ def test_product_tuple_reuse(self):
10921125
self.assertEqual(len(set(map(id, product('abc', 'def')))), 1)
10931126
self.assertNotEqual(len(set(map(id, list(product('abc', 'def'))))), 1)
10941127

1128+
# TODO: RUSTPYTHON - panics with 'index out of bounds: the len is 0 but the index is 18446744073709551615'
1129+
@unittest.skip("panics")
10951130
def test_product_pickling(self):
10961131
# check copy, deepcopy, pickle
10971132
for args, result in [
@@ -1107,6 +1142,8 @@ def test_product_pickling(self):
11071142
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
11081143
self.pickletest(proto, product(*args))
11091144

1145+
# TODO: RUSTPYTHON
1146+
@unittest.expectedFailure
11101147
def test_product_issue_25021(self):
11111148
# test that indices are properly clamped to the length of the tuples
11121149
p = product((1, 2),(3,))
@@ -1117,6 +1154,8 @@ def test_product_issue_25021(self):
11171154
p.__setstate__((0, 0, 0x1000)) # will access tuple element 1 if not clamped
11181155
self.assertRaises(StopIteration, next, p)
11191156

1157+
# TODO: RUSTPYTHON
1158+
@unittest.expectedFailure
11201159
def test_repeat(self):
11211160
self.assertEqual(list(repeat(object='a', times=3)), ['a', 'a', 'a'])
11221161
self.assertEqual(lzip(range(3),repeat('a')),
@@ -1143,12 +1182,16 @@ def test_repeat(self):
11431182
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
11441183
self.pickletest(proto, repeat(object='a', times=10))
11451184

1185+
# TODO: RUSTPYTHON
1186+
@unittest.expectedFailure
11461187
def test_repeat_with_negative_times(self):
11471188
self.assertEqual(repr(repeat('a', -1)), "repeat('a', 0)")
11481189
self.assertEqual(repr(repeat('a', -2)), "repeat('a', 0)")
11491190
self.assertEqual(repr(repeat('a', times=-1)), "repeat('a', 0)")
11501191
self.assertEqual(repr(repeat('a', times=-2)), "repeat('a', 0)")
11511192

1193+
# TODO: RUSTPYTHON
1194+
@unittest.expectedFailure
11521195
def test_map(self):
11531196
self.assertEqual(list(map(operator.pow, range(3), range(1,7))),
11541197
[0**1, 1**2, 2**3])
@@ -1179,6 +1222,8 @@ def test_map(self):
11791222
c = map(tupleize, 'abc', count())
11801223
self.pickletest(proto, c)
11811224

1225+
# TODO: RUSTPYTHON
1226+
@unittest.expectedFailure
11821227
def test_starmap(self):
11831228
self.assertEqual(list(starmap(operator.pow, zip(range(3), range(1,7)))),
11841229
[0**1, 1**2, 2**3])
@@ -1206,6 +1251,8 @@ def test_starmap(self):
12061251
c = starmap(operator.pow, zip(range(3), range(1,7)))
12071252
self.pickletest(proto, c)
12081253

1254+
# TODO: RUSTPYTHON
1255+
@unittest.expectedFailure
12091256
def test_islice(self):
12101257
for args in [ # islice(args) should agree with range(args)
12111258
(10, 20, 3),
@@ -1300,6 +1347,8 @@ def __index__(self):
13001347
self.assertEqual(list(islice(range(100), IntLike(10), IntLike(50), IntLike(5))),
13011348
list(range(10,50,5)))
13021349

1350+
# TODO: RUSTPYTHON
1351+
@unittest.expectedFailure
13031352
def test_takewhile(self):
13041353
data = [1, 3, 5, 20, 2, 4, 6, 8]
13051354
self.assertEqual(list(takewhile(underten, data)), [1, 3, 5])
@@ -1320,6 +1369,8 @@ def test_takewhile(self):
13201369
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
13211370
self.pickletest(proto, takewhile(underten, data))
13221371

1372+
# TODO: RUSTPYTHON
1373+
@unittest.expectedFailure
13231374
def test_dropwhile(self):
13241375
data = [1, 3, 5, 20, 2, 4, 6, 8]
13251376
self.assertEqual(list(dropwhile(underten, data)), [20, 2, 4, 6, 8])
@@ -1337,6 +1388,8 @@ def test_dropwhile(self):
13371388
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
13381389
self.pickletest(proto, dropwhile(underten, data))
13391390

1391+
# TODO: RUSTPYTHON
1392+
@unittest.expectedFailure
13401393
def test_tee(self):
13411394
n = 200
13421395

@@ -1486,6 +1539,8 @@ def test_tee(self):
14861539
self.pickletest(proto, b, compare=ans)
14871540

14881541
# Issue 13454: Crash when deleting backward iterator from tee()
1542+
# TODO: RUSTPYTHON
1543+
@unittest.skip("hangs")
14891544
def test_tee_del_backward(self):
14901545
forward, backward = tee(repeat(None, 20000000))
14911546
try:
@@ -1495,6 +1550,8 @@ def test_tee_del_backward(self):
14951550
del forward, backward
14961551
raise
14971552

1553+
# TODO: RUSTPYTHON
1554+
@unittest.expectedFailure
14981555
def test_tee_reenter(self):
14991556
class I:
15001557
first = True
@@ -1510,6 +1567,8 @@ def __next__(self):
15101567
with self.assertRaisesRegex(RuntimeError, "tee"):
15111568
next(a)
15121569

1570+
# TODO: RUSTPYTHON - hangs
1571+
@unittest.skip("hangs")
15131572
def test_tee_concurrent(self):
15141573
start = threading.Event()
15151574
finish = threading.Event()
@@ -1559,6 +1618,8 @@ class TestExamples(unittest.TestCase):
15591618
def test_accumulate(self):
15601619
self.assertEqual(list(accumulate([1,2,3,4,5])), [1, 3, 6, 10, 15])
15611620

1621+
# TODO: RUSTPYTHON
1622+
@unittest.expectedFailure
15621623
def test_accumulate_reducible(self):
15631624
# check copy, deepcopy, pickle
15641625
data = [1, 2, 3, 4, 5]
@@ -1574,6 +1635,8 @@ def test_accumulate_reducible(self):
15741635
self.assertEqual(list(copy.deepcopy(it)), accumulated[1:])
15751636
self.assertEqual(list(copy.copy(it)), accumulated[1:])
15761637

1638+
# TODO: RUSTPYTHON
1639+
@unittest.expectedFailure
15771640
def test_accumulate_reducible_none(self):
15781641
# Issue #25718: total is None
15791642
it = accumulate([None, None, None], operator.is_)
@@ -1627,6 +1690,8 @@ def test_filterfalse(self):
16271690
def test_map(self):
16281691
self.assertEqual(list(map(pow, (2,3,10), (5,2,3))), [32, 9, 1000])
16291692

1693+
# TODO: RUSTPYTHON
1694+
@unittest.expectedFailure
16301695
def test_islice(self):
16311696
self.assertEqual(list(islice('ABCDEFG', 2)), list('AB'))
16321697
self.assertEqual(list(islice('ABCDEFG', 2, 4)), list('CD'))
@@ -1885,7 +1950,6 @@ def L(seqn):
18851950

18861951

18871952
class TestVariousIteratorArgs(unittest.TestCase):
1888-
18891953
def test_accumulate(self):
18901954
s = [1,2,3,4,5]
18911955
r = [1,3,6,10,15]
@@ -2041,11 +2105,15 @@ def test_tee(self):
20412105

20422106
class LengthTransparency(unittest.TestCase):
20432107

2108+
# TODO: RUSTPYTHON
2109+
@unittest.expectedFailure
20442110
def test_repeat(self):
20452111
self.assertEqual(operator.length_hint(repeat(None, 50)), 50)
20462112
self.assertEqual(operator.length_hint(repeat(None, 0)), 0)
20472113
self.assertEqual(operator.length_hint(repeat(None), 12), 12)
20482114

2115+
# TODO: RUSTPYTHON
2116+
@unittest.expectedFailure
20492117
def test_repeat_with_negative_times(self):
20502118
self.assertEqual(operator.length_hint(repeat(None, -1)), 0)
20512119
self.assertEqual(operator.length_hint(repeat(None, -2)), 0)
@@ -2145,6 +2213,8 @@ def __eq__(self, other):
21452213

21462214

21472215
class SubclassWithKwargsTest(unittest.TestCase):
2216+
# TODO: RUSTPYTHON
2217+
@unittest.expectedFailure
21482218
def test_keywords_in_subclass(self):
21492219
# count is not subclassable...
21502220
for cls in (repeat, zip, filter, filterfalse, chain, map,
@@ -2530,8 +2600,9 @@ def test_main(verbose=None):
25302600
counts[i] = sys.gettotalrefcount()
25312601
print(counts)
25322602

2603+
# TODO: RUSTPYTHON this hangs or is very slow
25332604
# doctest the examples in the library reference
2534-
support.run_doctest(sys.modules[__name__], verbose)
2605+
# support.run_doctest(sys.modules[__name__], verbose)
25352606

25362607
if __name__ == "__main__":
25372608
test_main(verbose=True)

vm/src/obj/objiter.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ use crate::vm::VirtualMachine;
2323
pub fn get_iter(vm: &VirtualMachine, iter_target: &PyObjectRef) -> PyResult {
2424
if let Some(method_or_err) = vm.get_method(iter_target.clone(), "__iter__") {
2525
let method = method_or_err?;
26-
vm.invoke(&method, vec![])
26+
let iter = vm.invoke(&method, vec![])?;
27+
if iter.has_class_attr("__next__") {
28+
Ok(iter)
29+
} else {
30+
Err(vm.new_type_error(format!(
31+
"iter() returned non-iterator of type '{}'",
32+
iter.lease_class().name
33+
)))
34+
}
2735
} else {
2836
vm.get_method_or_type_error(iter_target.clone(), "__getitem__", || {
2937
format!(

vm/src/pyobject.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,10 @@ pub trait TypeProtocol {
915915
fn get_class_attr(&self, attr_name: &str) -> Option<PyObjectRef> {
916916
self.lease_class().get_attr(attr_name)
917917
}
918+
919+
fn has_class_attr(&self, attr_name: &str) -> bool {
920+
self.lease_class().has_attr(attr_name)
921+
}
918922
}
919923

920924
impl TypeProtocol for PyObjectRef {

0 commit comments

Comments
 (0)