From dcd8f52766784c8a32f9472e1d5b5bfd61324242 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 5 Apr 2017 10:52:29 +1000 Subject: [PATCH] tests/basics: Add tests for raising ValueError when range() gets 0 step. --- tests/basics/builtin_range.py | 6 ++++++ tests/basics/for_range.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/tests/basics/builtin_range.py b/tests/basics/builtin_range.py index 7c3e5beeff..6371ab56cb 100644 --- a/tests/basics/builtin_range.py +++ b/tests/basics/builtin_range.py @@ -34,6 +34,12 @@ print(range(1, 4)[1:]) print(range(1, 4)[:-1]) print(range(7, -2, -4)[:]) +# zero step +try: + range(1, 2, 0) +except ValueError: + print("ValueError") + # bad unary op try: -range(1) diff --git a/tests/basics/for_range.py b/tests/basics/for_range.py index 58a8f7caa7..fc736277d3 100644 --- a/tests/basics/for_range.py +++ b/tests/basics/for_range.py @@ -6,6 +6,13 @@ for x in range(*(1, 3)): for x in range(1, *(6, 2)): print(x) +# zero step +try: + for x in range(1, 2, 0): + pass +except ValueError: + print('ValueError') + # apply args using ** try: for x in range(**{'end':1}):