Skip to content

Commit 8f0147c

Browse files
dpgeorgejepler
authored andcommitted
tests: Modify tests that print repr of an exception with 1 arg.
In Python 3.7 the behaviour of repr() of an exception with one argument changed: it no longer prints a trailing comma in the argument list. See https://bugs.python.org/issue30399 This patch modifies tests that rely on this behaviour to not rely on it. And the python34.py test is updated to include a test for this behaviour with a .exp file.
1 parent 4c4f81f commit 8f0147c

File tree

8 files changed

+12
-8
lines changed

8 files changed

+12
-8
lines changed

tests/basics/dict1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
try:
2828
{}[0]
2929
except KeyError as er:
30-
print('KeyError', er, repr(er), er.args)
30+
print('KeyError', er, er.args)
3131

3232
# unsupported unary op
3333
try:

tests/basics/exception1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
print(repr(IndexError()))
22
print(str(IndexError()))
33

4-
print(repr(IndexError("foo")))
54
print(str(IndexError("foo")))
65

76
a = IndexError(1, "test", [100, 200])

tests/basics/generator_return.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def gen():
77
try:
88
print(next(g))
99
except StopIteration as e:
10-
print(repr(e))
10+
print(type(e), e.args)

tests/basics/python34.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# tests that differ when running under Python 3.4 vs 3.5/3.6
1+
# tests that differ when running under Python 3.4 vs 3.5/3.6/3.7
22

33
try:
44
exec
@@ -36,3 +36,7 @@ def test_syntax(code):
3636
import sys
3737
print(sys.version[:3])
3838
print(sys.version_info[0], sys.version_info[1])
39+
40+
# from basics/exception1.py
41+
# in 3.7 no comma is printed if there is only 1 arg (in 3.4-3.6 one is printed)
42+
print(repr(IndexError("foo")))

tests/basics/python34.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ SyntaxError
1111
SyntaxError
1212
3.4
1313
3 4
14+
IndexError('foo',)

tests/basics/subclass_native3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class MyExc(Exception):
77
print(e.args)
88

99
try:
10-
raise MyExc("Some error")
10+
raise MyExc("Some error", 1)
1111
except MyExc as e:
1212
print("Caught exception:", repr(e))
1313

1414
try:
15-
raise MyExc("Some error2")
15+
raise MyExc("Some error2", 2)
1616
except Exception as e:
1717
print("Caught exception:", repr(e))
1818

tests/basics/try_as_var.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
try:
22
raise ValueError(534)
33
except ValueError as e:
4-
print(repr(e))
4+
print(type(e), e.args)
55

66
# Var bound in except block is automatically deleted
77
try:

tests/misc/sys_exc_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def f():
99
print(sys.exc_info()[0:2])
1010

1111
try:
12-
1/0
12+
raise ValueError('value', 123)
1313
except:
1414
print(sys.exc_info()[0:2])
1515
f()

0 commit comments

Comments
 (0)