Skip to content

Commit dcd8f52

Browse files
committed
tests/basics: Add tests for raising ValueError when range() gets 0 step.
1 parent de9b536 commit dcd8f52

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tests/basics/builtin_range.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
print(range(1, 4)[:-1])
3535
print(range(7, -2, -4)[:])
3636

37+
# zero step
38+
try:
39+
range(1, 2, 0)
40+
except ValueError:
41+
print("ValueError")
42+
3743
# bad unary op
3844
try:
3945
-range(1)

tests/basics/for_range.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
for x in range(1, *(6, 2)):
77
print(x)
88

9+
# zero step
10+
try:
11+
for x in range(1, 2, 0):
12+
pass
13+
except ValueError:
14+
print('ValueError')
15+
916
# apply args using **
1017
try:
1118
for x in range(**{'end':1}):

0 commit comments

Comments
 (0)