summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-01-26 10:09:17 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-01-26 10:09:17 (GMT)
commit2bef58577f1caa293a4843f4bdf245407825a61a (patch)
treeeab5b67eba2ad44a2e183962cfce9527cdfc8fcb /Lib/test
parent21d7533c4c13489b4b3baae59f9e25cd038fb16b (diff)
downloadcpython-2bef58577f1caa293a4843f4bdf245407825a61a.zip
cpython-2bef58577f1caa293a4843f4bdf245407825a61a.tar.gz
cpython-2bef58577f1caa293a4843f4bdf245407825a61a.tar.bz2
Issue #18518: timeit now rejects statements which can't be compiled outside
a function or a loop (e.g. "return" or "break").
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_timeit.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_timeit.py b/Lib/test/test_timeit.py
index 625fb8d..09e76e0 100644
--- a/Lib/test/test_timeit.py
+++ b/Lib/test/test_timeit.py
@@ -73,9 +73,21 @@ class TestTimeit(unittest.TestCase):
def test_timer_invalid_stmt(self):
self.assertRaises(ValueError, timeit.Timer, stmt=None)
+ self.assertRaises(SyntaxError, timeit.Timer, stmt='return')
+ self.assertRaises(SyntaxError, timeit.Timer, stmt='yield')
+ self.assertRaises(SyntaxError, timeit.Timer, stmt='yield from ()')
+ self.assertRaises(SyntaxError, timeit.Timer, stmt='break')
+ self.assertRaises(SyntaxError, timeit.Timer, stmt='continue')
+ self.assertRaises(SyntaxError, timeit.Timer, stmt='from timeit import *')
def test_timer_invalid_setup(self):
self.assertRaises(ValueError, timeit.Timer, setup=None)
+ self.assertRaises(SyntaxError, timeit.Timer, setup='return')
+ self.assertRaises(SyntaxError, timeit.Timer, setup='yield')
+ self.assertRaises(SyntaxError, timeit.Timer, setup='yield from ()')
+ self.assertRaises(SyntaxError, timeit.Timer, setup='break')
+ self.assertRaises(SyntaxError, timeit.Timer, setup='continue')
+ self.assertRaises(SyntaxError, timeit.Timer, setup='from timeit import *')
fake_setup = "import timeit; timeit._fake_timer.setup()"
fake_stmt = "import timeit; timeit._fake_timer.inc()"