We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent de5b1c4 commit 2f2a843Copy full SHA for 2f2a843
1 file changed
tests/snippets/iterable.py
@@ -0,0 +1,32 @@
1
+from testutils import assert_raises
2
+
3
+def test_container(x):
4
+ assert 3 in x
5
+ assert 4 not in x
6
+ assert list(x) == list(iter(x))
7
+ assert list(x) == [0, 1, 2, 3]
8
+ assert [*x] == [0, 1, 2, 3]
9
+ lst = []
10
+ lst.extend(x)
11
+ assert lst == [0, 1, 2, 3]
12
13
+class C:
14
+ def __iter__(self):
15
+ return iter([0, 1, 2, 3])
16
+test_container(C())
17
18
19
+ def __getitem__(self, x):
20
+ return (0, 1, 2, 3)[x] # raises IndexError on x==4
21
22
23
24
25
+ if x > 3:
26
+ raise StopIteration
27
+ return x
28
29
30
+class C: pass
31
+assert_raises(TypeError, lambda: 5 in C())
32
+assert_raises(TypeError, lambda: iter(C))
0 commit comments