Skip to content

Commit 3add4d7

Browse files
committed
Raise statement normalization in Lib/test/.
1 parent e0281ca commit 3add4d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+218
-218
lines changed

Lib/test/leakers/test_gestalt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22

33
if sys.platform != 'darwin':
4-
raise ValueError, "This test only leaks on Mac OS X"
4+
raise ValueError("This test only leaks on Mac OS X")
55

66
def leak():
77
# taken from platform._mac_ver_lookup()

Lib/test/pickletester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ def __reduce_ex__(self, proto):
868868
self._proto = proto
869869
return REX_two, ()
870870
def __reduce__(self):
871-
raise TestFailed, "This __reduce__ shouldn't be called"
871+
raise TestFailed("This __reduce__ shouldn't be called")
872872

873873
class REX_four(object):
874874
_proto = None

Lib/test/test_binop.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ def __init__(self, num=0, den=1):
3535
3636
The arguments must be ints or longs, and default to (0, 1)."""
3737
if not isint(num):
38-
raise TypeError, "Rat numerator must be int or long (%r)" % num
38+
raise TypeError("Rat numerator must be int or long (%r)" % num)
3939
if not isint(den):
40-
raise TypeError, "Rat denominator must be int or long (%r)" % den
40+
raise TypeError("Rat denominator must be int or long (%r)" % den)
4141
# But the zero is always on
4242
if den == 0:
43-
raise ZeroDivisionError, "zero denominator"
43+
raise ZeroDivisionError("zero denominator")
4444
g = gcd(den, num)
4545
self.__num = int(num//g)
4646
self.__den = int(den//g)
@@ -73,15 +73,15 @@ def __int__(self):
7373
try:
7474
return int(self.__num)
7575
except OverflowError:
76-
raise OverflowError, ("%s too large to convert to int" %
76+
raise OverflowError("%s too large to convert to int" %
7777
repr(self))
78-
raise ValueError, "can't convert %s to int" % repr(self)
78+
raise ValueError("can't convert %s to int" % repr(self))
7979

8080
def __long__(self):
8181
"""Convert a Rat to an long; self.den must be 1."""
8282
if self.__den == 1:
8383
return int(self.__num)
84-
raise ValueError, "can't convert %s to long" % repr(self)
84+
raise ValueError("can't convert %s to long" % repr(self))
8585

8686
def __add__(self, other):
8787
"""Add two Rats, or a Rat and a number."""

Lib/test/test_capi.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ def test_main():
1212
test = getattr(_testcapi, name)
1313
if test_support.verbose:
1414
print("internal", name)
15-
try:
16-
test()
17-
except _testcapi.error:
18-
raise test_support.TestFailed, sys.exc_info()[1]
15+
test()
1916

2017
# some extra thread-state tests driven via _testcapi
2118
def TestThreadState():
@@ -35,8 +32,8 @@ def callback():
3532
time.sleep(1)
3633
# Check our main thread is in the list exactly 3 times.
3734
if idents.count(thread.get_ident()) != 3:
38-
raise test_support.TestFailed, \
39-
"Couldn't find main thread correctly in the list"
35+
raise test_support.TestFailed(
36+
"Couldn't find main thread correctly in the list")
4037

4138
try:
4239
_testcapi._test_thread_state

Lib/test/test_cgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def do_test(buf, method):
4747
env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
4848
env['CONTENT_LENGTH'] = str(len(buf))
4949
else:
50-
raise ValueError, "unknown method: %s" % method
50+
raise ValueError("unknown method: %s" % method)
5151
try:
5252
return cgi.parse(fp, env, strict_parsing=1)
5353
except Exception as err:

Lib/test/test_contains.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __getitem__(self, n):
1717

1818
def check(ok, *args):
1919
if not ok:
20-
raise TestFailed, " ".join(map(str, args))
20+
raise TestFailed(" ".join(map(str, args)))
2121

2222
a = base_set(1)
2323
b = set(1)
@@ -95,7 +95,7 @@ class Deviant2:
9595

9696
def __cmp__(self, other):
9797
if other == 4:
98-
raise RuntimeError, "gotcha"
98+
raise RuntimeError("gotcha")
9999

100100
try:
101101
check(Deviant2() not in a, "oops")

Lib/test/test_copy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class C(object):
5151
def __reduce_ex__(self, proto):
5252
return ""
5353
def __reduce__(self):
54-
raise test_support.TestFailed, "shouldn't call this"
54+
raise test_support.TestFailed("shouldn't call this")
5555
x = C()
5656
y = copy.copy(x)
5757
self.assert_(y is x)
@@ -68,7 +68,7 @@ def test_copy_cant(self):
6868
class C(object):
6969
def __getattribute__(self, name):
7070
if name.startswith("__reduce"):
71-
raise AttributeError, name
71+
raise AttributeError(name)
7272
return object.__getattribute__(self, name)
7373
x = C()
7474
self.assertRaises(copy.Error, copy.copy, x)
@@ -224,7 +224,7 @@ class C(object):
224224
def __reduce_ex__(self, proto):
225225
return ""
226226
def __reduce__(self):
227-
raise test_support.TestFailed, "shouldn't call this"
227+
raise test_support.TestFailed("shouldn't call this")
228228
x = C()
229229
y = copy.deepcopy(x)
230230
self.assert_(y is x)
@@ -241,7 +241,7 @@ def test_deepcopy_cant(self):
241241
class C(object):
242242
def __getattribute__(self, name):
243243
if name.startswith("__reduce"):
244-
raise AttributeError, name
244+
raise AttributeError(name)
245245
return object.__getattribute__(self, name)
246246
x = C()
247247
self.assertRaises(copy.Error, copy.deepcopy, x)
@@ -565,7 +565,7 @@ class C(tuple):
565565
def test_getstate_exc(self):
566566
class EvilState(object):
567567
def __getstate__(self):
568-
raise ValueError, "ain't got no stickin' state"
568+
raise ValueError("ain't got no stickin' state")
569569
self.assertRaises(ValueError, copy.copy, EvilState())
570570

571571
def test_copy_function(self):

Lib/test/test_curses.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# XXX: if newterm was supported we could use it instead of initscr and not exit
2323
term = os.environ.get('TERM')
2424
if not term or term == 'unknown':
25-
raise TestSkipped, "$TERM=%r, calling initscr() may cause exit" % term
25+
raise TestSkipped("$TERM=%r, calling initscr() may cause exit" % term)
2626

2727
if sys.platform == "cygwin":
2828
raise TestSkipped("cygwin's curses mostly just hangs")
@@ -72,7 +72,7 @@ def window_funcs(stdscr):
7272
except TypeError:
7373
pass
7474
else:
75-
raise RuntimeError, "Expected win.border() to raise TypeError"
75+
raise RuntimeError("Expected win.border() to raise TypeError")
7676

7777
stdscr.clearok(1)
7878

@@ -243,7 +243,7 @@ def test_userptr_without_set(stdscr):
243243
# try to access userptr() before calling set_userptr() -- segfaults
244244
try:
245245
p.userptr()
246-
raise RuntimeError, 'userptr should fail since not set'
246+
raise RuntimeError('userptr should fail since not set')
247247
except curses.panel.error:
248248
pass
249249

@@ -253,7 +253,7 @@ def test_resize_term(stdscr):
253253
curses.resizeterm(lines - 1, cols + 1)
254254

255255
if curses.LINES != lines - 1 or curses.COLS != cols + 1:
256-
raise RuntimeError, "Expected resizeterm to update LINES and COLS"
256+
raise RuntimeError("Expected resizeterm to update LINES and COLS")
257257

258258
def main(stdscr):
259259
curses.savetty()

Lib/test/test_dbm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def cleanup():
2121
# if we can't delete the file because of permissions,
2222
# nothing will work, so skip the test
2323
if errno == 1:
24-
raise TestSkipped, 'unable to remove: ' + filename + suffix
24+
raise TestSkipped('unable to remove: ' + filename + suffix)
2525

2626
def test_keys():
2727
d = dbm.open(filename, 'c')

0 commit comments

Comments
 (0)