summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--tests/basics/fun_error.py45
-rw-r--r--tests/basics/fun_error2.py14
-rw-r--r--tests/basics/op_error.py99
-rw-r--r--tests/basics/op_error_intbig.py5
-rw-r--r--tests/basics/op_error_memoryview.py15
5 files changed, 114 insertions, 64 deletions
diff --git a/tests/basics/fun_error.py b/tests/basics/fun_error.py
index 367fe0b7fa..3e79c727b3 100644
--- a/tests/basics/fun_error.py
+++ b/tests/basics/fun_error.py
@@ -1,31 +1,44 @@
# test errors from bad function calls
-def test_exc(code, exc):
- try:
- exec(code)
- print("no exception")
- except exc:
- print("right exception")
- except:
- print("wrong exception")
-
# function doesn't take keyword args
-test_exc("[].append(x=1)", TypeError)
+try:
+ [].append(x=1)
+except TypeError:
+ print('TypeError')
# function with variable number of positional args given too few
-test_exc("round()", TypeError)
+try:
+ round()
+except TypeError:
+ print('TypeError')
# function with variable number of positional args given too many
-test_exc("round(1, 2, 3)", TypeError)
+try:
+ round(1, 2, 3)
+except TypeError:
+ print('TypeError')
# function with fixed number of positional args given wrong number
-test_exc("[].append(1, 2)", TypeError)
+try:
+ [].append(1, 2)
+except TypeError:
+ print('TypeError')
# function with keyword args given extra positional args
-test_exc("[].sort(1)", TypeError)
+try:
+ [].sort(1)
+except TypeError:
+ print('TypeError')
# function with keyword args given extra keyword args
-test_exc("[].sort(noexist=1)", TypeError)
+try:
+ [].sort(noexist=1)
+except TypeError:
+ print('TypeError')
# kw given for positional, but a different positional is missing
-test_exc("def f(x, y): pass\nf(x=1)", TypeError)
+try:
+ def f(x, y): pass
+ f(x=1)
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/fun_error2.py b/tests/basics/fun_error2.py
index 2a00396e65..39fd0af144 100644
--- a/tests/basics/fun_error2.py
+++ b/tests/basics/fun_error2.py
@@ -5,14 +5,8 @@ except:
print("SKIP")
raise SystemExit
-def test_exc(code, exc):
- try:
- exec(code)
- print("no exception")
- except exc:
- print("right exception")
- except:
- print("wrong exception")
-
# function with keyword args not given a specific keyword arg
-test_exc("enumerate()", TypeError)
+try:
+ enumerate()
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/op_error.py b/tests/basics/op_error.py
index b30b5f0a35..7b4f896e14 100644
--- a/tests/basics/op_error.py
+++ b/tests/basics/op_error.py
@@ -1,44 +1,89 @@
# test errors from bad operations (unary, binary, etc)
-def test_exc(code, exc):
- try:
- exec(code)
- print("no exception")
- except exc:
- print("right exception")
- except:
- print("wrong exception")
-
# unsupported unary operators
-test_exc("~None", TypeError)
-test_exc("~''", TypeError)
-test_exc("~[]", TypeError)
-test_exc("~bytearray()", TypeError)
+try:
+ ~None
+except TypeError:
+ print('TypeError')
+try:
+ ~''
+except TypeError:
+ print('TypeError')
+try:
+ ~[]
+except TypeError:
+ print('TypeError')
+try:
+ ~bytearray()
+except TypeError:
+ print('TypeError')
# unsupported binary operators
-test_exc("False in True", TypeError)
-test_exc("1 * {}", TypeError)
-test_exc("1 in 1", TypeError)
-test_exc("bytearray() // 2", TypeError)
+try:
+ False in True
+except TypeError:
+ print('TypeError')
+try:
+ 1 * {}
+except TypeError:
+ print('TypeError')
+try:
+ 1 in 1
+except TypeError:
+ print('TypeError')
+try:
+ bytearray() // 2
+except TypeError:
+ print('TypeError')
# object with buffer protocol needed on rhs
-test_exc("bytearray(1) + 1", TypeError)
+try:
+ bytearray(1) + 1
+except TypeError:
+ print('TypeError')
# unsupported subscription
-test_exc("1[0]", TypeError)
-test_exc("1[0] = 1", TypeError)
-test_exc("''['']", TypeError)
-test_exc("'a'[0] = 1", TypeError)
-test_exc("del 1[0]", TypeError)
+try:
+ 1[0]
+except TypeError:
+ print('TypeError')
+try:
+ 1[0] = 1
+except TypeError:
+ print('TypeError')
+try:
+ ''['']
+except TypeError:
+ print('TypeError')
+try:
+ 'a'[0] = 1
+except TypeError:
+ print('TypeError')
+try:
+ del 1[0]
+except TypeError:
+ print('TypeError')
# not callable
-test_exc("1()", TypeError)
+try:
+ 1()
+except TypeError:
+ print('TypeError')
# not an iterator
-test_exc("next(1)", TypeError)
+try:
+ next(1)
+except TypeError:
+ print('TypeError')
# must be an exception type
-test_exc("raise 1", TypeError)
+try:
+ raise 1
+except TypeError:
+ print('TypeError')
# no such name in import
-test_exc("from sys import youcannotimportmebecauseidontexist", ImportError)
+try:
+ from sys import youcannotimportmebecauseidontexist
+except ImportError:
+ print('ImportError')
diff --git a/tests/basics/op_error_intbig.py b/tests/basics/op_error_intbig.py
index 432c05a9fe..7def75b0c6 100644
--- a/tests/basics/op_error_intbig.py
+++ b/tests/basics/op_error_intbig.py
@@ -10,4 +10,7 @@ def test_exc(code, exc):
print("wrong exception")
# object with buffer protocol needed on rhs
-test_exc("(1 << 70) in 1", TypeError)
+try:
+ (1 << 70) in 1
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/op_error_memoryview.py b/tests/basics/op_error_memoryview.py
index 8d4403f777..233f7f9ab7 100644
--- a/tests/basics/op_error_memoryview.py
+++ b/tests/basics/op_error_memoryview.py
@@ -5,14 +5,9 @@ except:
print("SKIP")
raise SystemExit
-def test_exc(code, exc):
- try:
- exec(code)
- print("no exception")
- except exc:
- print("right exception")
- except:
- print("wrong exception")
-
# unsupported binary operators
-test_exc("m = memoryview(bytearray())\nm += bytearray()", TypeError)
+try:
+ m = memoryview(bytearray())
+ m += bytearray()
+except TypeError:
+ print('TypeError')