diff options
author | Collin Winter <collinw@gmail.com> | 2007-08-29 23:37:32 (GMT) |
---|---|---|
committer | Collin Winter <collinw@gmail.com> | 2007-08-29 23:37:32 (GMT) |
commit | 3add4d78ff9f5de02e2c0de09efe9a9b5317539f (patch) | |
tree | c61c6a122b33537814bcc643300f10759fa81010 | |
parent | e0281cab810c30a23cf2490704e0f85aa4751e83 (diff) | |
download | cpython-3add4d78ff9f5de02e2c0de09efe9a9b5317539f.zip cpython-3add4d78ff9f5de02e2c0de09efe9a9b5317539f.tar.gz cpython-3add4d78ff9f5de02e2c0de09efe9a9b5317539f.tar.bz2 |
Raise statement normalization in Lib/test/.
47 files changed, 218 insertions, 218 deletions
diff --git a/Lib/test/leakers/test_gestalt.py b/Lib/test/leakers/test_gestalt.py index 46bfcc8..e0081c1 100644 --- a/Lib/test/leakers/test_gestalt.py +++ b/Lib/test/leakers/test_gestalt.py @@ -1,7 +1,7 @@ import sys if sys.platform != 'darwin': - raise ValueError, "This test only leaks on Mac OS X" + raise ValueError("This test only leaks on Mac OS X") def leak(): # taken from platform._mac_ver_lookup() diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index bc360b8..0b1cf5a 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -868,7 +868,7 @@ class REX_three(object): self._proto = proto return REX_two, () def __reduce__(self): - raise TestFailed, "This __reduce__ shouldn't be called" + raise TestFailed("This __reduce__ shouldn't be called") class REX_four(object): _proto = None diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py index 5aeb118..f0433fb 100644 --- a/Lib/test/test_binop.py +++ b/Lib/test/test_binop.py @@ -35,12 +35,12 @@ class Rat(object): The arguments must be ints or longs, and default to (0, 1).""" if not isint(num): - raise TypeError, "Rat numerator must be int or long (%r)" % num + raise TypeError("Rat numerator must be int or long (%r)" % num) if not isint(den): - raise TypeError, "Rat denominator must be int or long (%r)" % den + raise TypeError("Rat denominator must be int or long (%r)" % den) # But the zero is always on if den == 0: - raise ZeroDivisionError, "zero denominator" + raise ZeroDivisionError("zero denominator") g = gcd(den, num) self.__num = int(num//g) self.__den = int(den//g) @@ -73,15 +73,15 @@ class Rat(object): try: return int(self.__num) except OverflowError: - raise OverflowError, ("%s too large to convert to int" % + raise OverflowError("%s too large to convert to int" % repr(self)) - raise ValueError, "can't convert %s to int" % repr(self) + raise ValueError("can't convert %s to int" % repr(self)) def __long__(self): """Convert a Rat to an long; self.den must be 1.""" if self.__den == 1: return int(self.__num) - raise ValueError, "can't convert %s to long" % repr(self) + raise ValueError("can't convert %s to long" % repr(self)) def __add__(self, other): """Add two Rats, or a Rat and a number.""" diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 074f581..107d4b4 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -12,10 +12,7 @@ def test_main(): test = getattr(_testcapi, name) if test_support.verbose: print("internal", name) - try: - test() - except _testcapi.error: - raise test_support.TestFailed, sys.exc_info()[1] + test() # some extra thread-state tests driven via _testcapi def TestThreadState(): @@ -35,8 +32,8 @@ def test_main(): time.sleep(1) # Check our main thread is in the list exactly 3 times. if idents.count(thread.get_ident()) != 3: - raise test_support.TestFailed, \ - "Couldn't find main thread correctly in the list" + raise test_support.TestFailed( + "Couldn't find main thread correctly in the list") try: _testcapi._test_thread_state diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index 439982b..b1102cf 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -47,7 +47,7 @@ def do_test(buf, method): env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded' env['CONTENT_LENGTH'] = str(len(buf)) else: - raise ValueError, "unknown method: %s" % method + raise ValueError("unknown method: %s" % method) try: return cgi.parse(fp, env, strict_parsing=1) except Exception as err: diff --git a/Lib/test/test_contains.py b/Lib/test/test_contains.py index 7cae480..b55057d 100644 --- a/Lib/test/test_contains.py +++ b/Lib/test/test_contains.py @@ -17,7 +17,7 @@ class seq(base_set): def check(ok, *args): if not ok: - raise TestFailed, " ".join(map(str, args)) + raise TestFailed(" ".join(map(str, args))) a = base_set(1) b = set(1) @@ -95,7 +95,7 @@ class Deviant2: def __cmp__(self, other): if other == 4: - raise RuntimeError, "gotcha" + raise RuntimeError("gotcha") try: check(Deviant2() not in a, "oops") diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index dfdea84..cf94593 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -51,7 +51,7 @@ class TestCopy(unittest.TestCase): def __reduce_ex__(self, proto): return "" def __reduce__(self): - raise test_support.TestFailed, "shouldn't call this" + raise test_support.TestFailed("shouldn't call this") x = C() y = copy.copy(x) self.assert_(y is x) @@ -68,7 +68,7 @@ class TestCopy(unittest.TestCase): class C(object): def __getattribute__(self, name): if name.startswith("__reduce"): - raise AttributeError, name + raise AttributeError(name) return object.__getattribute__(self, name) x = C() self.assertRaises(copy.Error, copy.copy, x) @@ -224,7 +224,7 @@ class TestCopy(unittest.TestCase): def __reduce_ex__(self, proto): return "" def __reduce__(self): - raise test_support.TestFailed, "shouldn't call this" + raise test_support.TestFailed("shouldn't call this") x = C() y = copy.deepcopy(x) self.assert_(y is x) @@ -241,7 +241,7 @@ class TestCopy(unittest.TestCase): class C(object): def __getattribute__(self, name): if name.startswith("__reduce"): - raise AttributeError, name + raise AttributeError(name) return object.__getattribute__(self, name) x = C() self.assertRaises(copy.Error, copy.deepcopy, x) @@ -565,7 +565,7 @@ class TestCopy(unittest.TestCase): def test_getstate_exc(self): class EvilState(object): def __getstate__(self): - raise ValueError, "ain't got no stickin' state" + raise ValueError("ain't got no stickin' state") self.assertRaises(ValueError, copy.copy, EvilState()) def test_copy_function(self): diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index ee679e7..64d6536 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -22,7 +22,7 @@ requires('curses') # XXX: if newterm was supported we could use it instead of initscr and not exit term = os.environ.get('TERM') if not term or term == 'unknown': - raise TestSkipped, "$TERM=%r, calling initscr() may cause exit" % term + raise TestSkipped("$TERM=%r, calling initscr() may cause exit" % term) if sys.platform == "cygwin": raise TestSkipped("cygwin's curses mostly just hangs") @@ -72,7 +72,7 @@ def window_funcs(stdscr): except TypeError: pass else: - raise RuntimeError, "Expected win.border() to raise TypeError" + raise RuntimeError("Expected win.border() to raise TypeError") stdscr.clearok(1) @@ -243,7 +243,7 @@ def test_userptr_without_set(stdscr): # try to access userptr() before calling set_userptr() -- segfaults try: p.userptr() - raise RuntimeError, 'userptr should fail since not set' + raise RuntimeError('userptr should fail since not set') except curses.panel.error: pass @@ -253,7 +253,7 @@ def test_resize_term(stdscr): curses.resizeterm(lines - 1, cols + 1) if curses.LINES != lines - 1 or curses.COLS != cols + 1: - raise RuntimeError, "Expected resizeterm to update LINES and COLS" + raise RuntimeError("Expected resizeterm to update LINES and COLS") def main(stdscr): curses.savetty() diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py index 88b0bf6..806125f 100755 --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -21,7 +21,7 @@ def cleanup(): # if we can't delete the file because of permissions, # nothing will work, so skip the test if errno == 1: - raise TestSkipped, 'unable to remove: ' + filename + suffix + raise TestSkipped('unable to remove: ' + filename + suffix) def test_keys(): d = dbm.open(filename, 'c') diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 74b4081..69400ee 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -12,7 +12,7 @@ warnings.filterwarnings("ignore", def veris(a, b): if a is not b: - raise TestFailed, "%r is %r" % (a, b) + raise TestFailed("%r is %r" % (a, b)) def testunop(a, res, expr="len(a)", meth="__len__"): if verbose: print("checking", expr) @@ -430,7 +430,7 @@ def ints(): except TypeError: pass else: - raise TestFailed, "NotImplemented should have caused TypeError" + raise TestFailed("NotImplemented should have caused TypeError") def longs(): if verbose: print("Testing long operations...") @@ -775,7 +775,7 @@ def metaclass(): c = C() try: c() except TypeError: pass - else: raise TestFailed, "calling object w/o call method should raise TypeError" + else: raise TestFailed("calling object w/o call method should raise TypeError") # Testing code to find most derived baseclass class A(type): @@ -897,13 +897,13 @@ def diamond(): except TypeError: pass else: - raise TestFailed, "expected MRO order disagreement (F)" + raise TestFailed("expected MRO order disagreement (F)") try: class G(E, D): pass except TypeError: pass else: - raise TestFailed, "expected MRO order disagreement (G)" + raise TestFailed("expected MRO order disagreement (G)") # see thread python-dev/2002-October/029035.html @@ -965,10 +965,10 @@ def mro_disagreement(): callable(*args) except exc as msg: if not str(msg).startswith(expected): - raise TestFailed, "Message %r, expected %r" % (str(msg), - expected) + raise TestFailed("Message %r, expected %r" % (str(msg), + expected)) else: - raise TestFailed, "Expected %s" % exc + raise TestFailed("Expected %s" % exc) class A(object): pass class B(A): pass class C(object): pass @@ -1062,7 +1062,7 @@ def slots(): except AttributeError: pass else: - raise TestFailed, "Double underscored names not mangled" + raise TestFailed("Double underscored names not mangled") # Make sure slot names are proper identifiers try: @@ -1071,35 +1071,35 @@ def slots(): except TypeError: pass else: - raise TestFailed, "[None] slots not caught" + raise TestFailed("[None] slots not caught") try: class C(object): __slots__ = ["foo bar"] except TypeError: pass else: - raise TestFailed, "['foo bar'] slots not caught" + raise TestFailed("['foo bar'] slots not caught") try: class C(object): __slots__ = ["foo\0bar"] except TypeError: pass else: - raise TestFailed, "['foo\\0bar'] slots not caught" + raise TestFailed("['foo\\0bar'] slots not caught") try: class C(object): __slots__ = ["1"] except TypeError: pass else: - raise TestFailed, "['1'] slots not caught" + raise TestFailed("['1'] slots not caught") try: class C(object): __slots__ = [""] except TypeError: pass else: - raise TestFailed, "[''] slots not caught" + raise TestFailed("[''] slots not caught") class C(object): __slots__ = ["a", "a_b", "_a", "A0123456789Z"] # XXX(nnorwitz): was there supposed to be something tested @@ -1135,7 +1135,7 @@ def slots(): except (TypeError, UnicodeEncodeError): pass else: - raise TestFailed, "[unichr(128)] slots not caught" + raise TestFailed("[unichr(128)] slots not caught") # Test leaks class Counted(object): @@ -1232,7 +1232,7 @@ def slotspecials(): except AttributeError: pass else: - raise TestFailed, "shouldn't be allowed to set a.foo" + raise TestFailed("shouldn't be allowed to set a.foo") class C1(W, D): __slots__ = [] @@ -1434,7 +1434,7 @@ def classmethods(): except TypeError: pass else: - raise TestFailed, "classmethod should check for callability" + raise TestFailed("classmethod should check for callability") # Verify that classmethod() doesn't allow keyword args try: @@ -1442,7 +1442,7 @@ def classmethods(): except TypeError: pass else: - raise TestFailed, "classmethod shouldn't accept keyword args" + raise TestFailed("classmethod shouldn't accept keyword args") def classmethods_in_c(): if verbose: print("Testing C-based class methods...") @@ -1595,7 +1595,7 @@ def altmro(): except TypeError: pass else: - raise TestFailed, "devious mro() return not caught" + raise TestFailed("devious mro() return not caught") try: class _metaclass(type): @@ -1606,7 +1606,7 @@ def altmro(): except TypeError: pass else: - raise TestFailed, "non-class mro() return not caught" + raise TestFailed("non-class mro() return not caught") try: class _metaclass(type): @@ -1617,7 +1617,7 @@ def altmro(): except TypeError: pass else: - raise TestFailed, "non-sequence mro() return not caught" + raise TestFailed("non-sequence mro() return not caught") def overloading(): @@ -1956,7 +1956,7 @@ def properties(): except ZeroDivisionError: pass else: - raise TestFailed, "expected ZeroDivisionError from bad property" + raise TestFailed("expected ZeroDivisionError from bad property") class E(object): def getter(self): @@ -2037,28 +2037,28 @@ def supers(): except TypeError: pass else: - raise TestFailed, "shouldn't allow super(D, 42)" + raise TestFailed("shouldn't allow super(D, 42)") try: super(D, C()) except TypeError: pass else: - raise TestFailed, "shouldn't allow super(D, C())" + raise TestFailed("shouldn't allow super(D, C())") try: super(D).__get__(12) except TypeError: pass else: - raise TestFailed, "shouldn't allow super(D).__get__(12)" + raise TestFailed("shouldn't allow super(D).__get__(12)") try: super(D).__get__(C()) except TypeError: pass else: - raise TestFailed, "shouldn't allow super(D).__get__(C())" + raise TestFailed("shouldn't allow super(D).__get__(C())") # Make sure data descriptors can be overridden and accessed via super # (new feature in Python 2.3) @@ -2094,7 +2094,7 @@ def supers(): except TypeError: pass else: - raise TestFailed, "super shouldn't accept keyword args" + raise TestFailed("super shouldn't accept keyword args") def inherits(): if verbose: print("Testing inheritance from basic types...") @@ -2573,7 +2573,7 @@ def rich_comparisons(): def __init__(self, value): self.value = int(value) def __cmp__(self, other): - raise TestFailed, "shouldn't call __cmp__" + raise TestFailed("shouldn't call __cmp__") def __eq__(self, other): if isinstance(other, C): return self.value == other.value @@ -2652,13 +2652,13 @@ def setclass(): except TypeError: pass else: - raise TestFailed, "shouldn't allow %r.__class__ = %r" % (x, C) + raise TestFailed("shouldn't allow %r.__class__ = %r" % (x, C)) try: delattr(x, "__class__") except TypeError: pass else: - raise TestFailed, "shouldn't allow del %r.__class__" % x + raise TestFailed("shouldn't allow del %r.__class__" % x) cant(C(), list) cant(list(), C) cant(C(), 1) @@ -2726,7 +2726,7 @@ def setdict(): except (AttributeError, TypeError): pass else: - raise TestFailed, "shouldn't allow %r.__dict__ = %r" % (x, dict) + raise TestFailed("shouldn't allow %r.__dict__ = %r" % (x, dict)) cant(a, None) cant(a, []) cant(a, 1) @@ -2744,14 +2744,14 @@ def setdict(): except (AttributeError, TypeError): pass else: - raise TestFailed, "shouldn't allow del %r.__dict__" % x + raise TestFailed("shouldn't allow del %r.__dict__" % x) dict_descr = Base.__dict__["__dict__"] try: dict_descr.__set__(x, {}) except (AttributeError, TypeError): pass else: - raise TestFailed, "dict_descr allowed access to %r's dict" % x + raise TestFailed("dict_descr allowed access to %r's dict" % x) # Classes don't allow __dict__ assignment and have readonly dicts class Meta1(type, Base): @@ -2770,7 +2770,7 @@ def setdict(): except TypeError: pass else: - raise TestFailed, "%r's __dict__ can be modified" % cls + raise TestFailed("%r's __dict__ can be modified" % cls) # Modules also disallow __dict__ assignment class Module1(types.ModuleType, Base): @@ -2796,7 +2796,7 @@ def setdict(): except (TypeError, AttributeError): pass else: - raise TestFaied, "%r's __dict__ can be deleted" % e + raise TestFaied("%r's __dict__ can be deleted" % e) def pickles(): @@ -2931,13 +2931,13 @@ def pickleslots(): except TypeError: pass else: - raise TestFailed, "should fail: pickle C instance - %s" % base + raise TestFailed("should fail: pickle C instance - %s" % base) try: pickle.dumps(C(), 0) except TypeError: pass else: - raise TestFailed, "should fail: pickle D instance - %s" % base + raise TestFailed("should fail: pickle D instance - %s" % base) # Give C a nice generic __getstate__ and __setstate__ class C(base): __slots__ = ['a'] @@ -3073,7 +3073,7 @@ def subclasspropagation(): def __getattr__(self, name): if name in ("spam", "foo", "bar"): return "hello" - raise AttributeError, name + raise AttributeError(name) B.__getattr__ = __getattr__ vereq(d.spam, "hello") vereq(d.foo, 24) @@ -3089,7 +3089,7 @@ def subclasspropagation(): except AttributeError: pass else: - raise TestFailed, "d.foo should be undefined now" + raise TestFailed("d.foo should be undefined now") # Test a nasty bug in recurse_down_subclasses() import gc @@ -3200,7 +3200,7 @@ def delhook(): d = D() try: del d[0] except TypeError: pass - else: raise TestFailed, "invalid del() didn't raise TypeError" + else: raise TestFailed("invalid del() didn't raise TypeError") def hashinherit(): if verbose: print("Testing hash of mutable subclasses...") @@ -3213,7 +3213,7 @@ def hashinherit(): except TypeError: pass else: - raise TestFailed, "hash() of dict subclass should fail" + raise TestFailed("hash() of dict subclass should fail") class mylist(list): pass @@ -3223,48 +3223,48 @@ def hashinherit(): except TypeError: pass else: - raise TestFailed, "hash() of list subclass should fail" + raise TestFailed("hash() of list subclass should fail") def strops(): try: 'a' + 5 except TypeError: pass - else: raise TestFailed, "'' + 5 doesn't raise TypeError" + else: raise TestFailed("'' + 5 doesn't raise TypeError") try: ''.split('') except ValueError: pass - else: raise TestFailed, "''.split('') doesn't raise ValueError" + else: raise TestFailed("''.split('') doesn't raise ValueError") try: ''.join([0]) except TypeError: pass - else: raise TestFailed, "''.join([0]) doesn't raise TypeError" + else: raise TestFailed("''.join([0]) doesn't raise TypeError") try: ''.rindex('5') except ValueError: pass - else: raise TestFailed, "''.rindex('5') doesn't raise ValueError" + else: raise TestFailed("''.rindex('5') doesn't raise ValueError") try: '%(n)s' % None except TypeError: pass - else: raise TestFailed, "'%(n)s' % None doesn't raise TypeError" + else: raise TestFailed("'%(n)s' % None doesn't raise TypeError") try: '%(n' % {} except ValueError: pass - else: raise TestFailed, "'%(n' % {} '' doesn't raise ValueError" + else: raise TestFailed("'%(n' % {} '' doesn't raise ValueError") try: '%*s' % ('abc') except TypeError: pass - else: raise TestFailed, "'%*s' % ('abc') doesn't raise TypeError" + else: raise TestFailed("'%*s' % ('abc') doesn't raise TypeError") try: '%*.*s' % ('abc', 5) except TypeError: pass - else: raise TestFailed, "'%*.*s' % ('abc', 5) doesn't raise TypeError" + else: raise TestFailed("'%*.*s' % ('abc', 5) doesn't raise TypeError") try: '%s' % (1, 2) except TypeError: pass - else: raise TestFailed, "'%s' % (1, 2) doesn't raise TypeError" + else: raise TestFailed("'%s' % (1, 2) doesn't raise TypeError") try: '%' % None except ValueError: pass - else: raise TestFailed, "'%' % None doesn't raise ValueError" + else: raise TestFailed("'%' % None doesn't raise ValueError") vereq('534253'.isdigit(), 1) vereq('534253x'.isdigit(), 0) @@ -3595,14 +3595,14 @@ def test_mutable_bases(): except TypeError: pass else: - raise TestFailed, "shouldn't turn list subclass into dict subclass" + raise TestFailed("shouldn't turn list subclass into dict subclass") try: list.__bases__ = (dict,) except TypeError: pass else: - raise TestFailed, "shouldn't be able to assign to list.__bases__" + raise TestFailed("shouldn't be able to assign to list.__bases__") try: D.__bases__ = (C2, list) @@ -3616,15 +3616,15 @@ def test_mutable_bases(): except TypeError: pass else: - raise TestFailed, "shouldn't be able to delete .__bases__" + raise TestFailed("shouldn't be able to delete .__bases__") try: D.__bases__ = () except TypeError as msg: if str(msg) == "a new-style class can't have only classic bases": - raise TestFailed, "wrong error message for .__bases__ = ()" + raise TestFailed("wrong error message for .__bases__ = ()") else: - raise TestFailed, "shouldn't be able to set .__bases__ to ()" + raise TestFailed("shouldn't be able to set .__bases__ to ()") try: D.__bases__ = (D,) @@ -3632,21 +3632,21 @@ def test_mutable_bases(): pass else: # actually, we'll have crashed by here... - raise TestFailed, "shouldn't be able to create inheritance cycles" + raise TestFailed("shouldn't be able to create inheritance cycles") try: D.__bases__ = (C, C) except TypeError: pass else: - raise TestFailed, "didn't detect repeated base classes" + raise TestFailed("didn't detect repeated base classes") try: D.__bases__ = (E,) except TypeError: pass else: - raise TestFailed, "shouldn't be able to create inheritance cycles" + raise TestFailed("shouldn't be able to create inheritance cycles") def test_mutable_bases_with_failing_mro(): if verbose: @@ -3657,7 +3657,7 @@ def test_mutable_bases_with_failing_mro(): return super(WorkOnce, self).__new__(WorkOnce, name, bases, ns) def mro(self): if self.flag > 0: - raise RuntimeError, "bozo" + raise RuntimeError("bozo") else: self.flag += 1 return type.mro(self) @@ -3701,7 +3701,7 @@ def test_mutable_bases_with_failing_mro(): vereq(E.__mro__, E_mro_before) vereq(D.__mro__, D_mro_before) else: - raise TestFailed, "exception not propagated" + raise TestFailed("exception not propagated") def test_mutable_bases_catch_mro_conflict(): if verbose: @@ -3726,7 +3726,7 @@ def test_mutable_bases_catch_mro_conflict(): except TypeError: pass else: - raise TestFailed, "didn't catch MRO conflict" + raise TestFailed("didn't catch MRO conflict") def mutable_names(): if verbose: @@ -3828,25 +3828,25 @@ def meth_class_get(): except TypeError: pass else: - raise TestFailed, "shouldn't have allowed descr.__get__(None, None)" + raise TestFailed("shouldn't have allowed descr.__get__(None, None)") try: descr.__get__(42) except TypeError: pass else: - raise TestFailed, "shouldn't have allowed descr.__get__(42)" + raise TestFailed("shouldn't have allowed descr.__get__(42)") try: descr.__get__(None, 42) except TypeError: pass else: - raise TestFailed, "shouldn't have allowed descr.__get__(None, 42)" + raise TestFailed("shouldn't have allowed descr.__get__(None, 42)") try: descr.__get__(None, int) except TypeError: pass else: - raise TestFailed, "shouldn't have allowed descr.__get__(None, int)" + raise TestFailed("shouldn't have allowed descr.__get__(None, int)") def isinst_isclass(): if verbose: @@ -3920,13 +3920,13 @@ def carloverre(): except TypeError: pass else: - raise TestFailed, "Carlo Verre __setattr__ suceeded!" + raise TestFailed("Carlo Verre __setattr__ suceeded!") try: object.__delattr__(str, "lower") except TypeError: pass else: - raise TestFailed, "Carlo Verre __delattr__ succeeded!" + raise TestFailed("Carlo Verre __delattr__ succeeded!") def weakref_segfault(): # SF 742911 @@ -4012,7 +4012,7 @@ def test_init(): except TypeError: pass else: - raise TestFailed, "did not test __init__() for None return" + raise TestFailed("did not test __init__() for None return") def methodwrapper(): # <type 'method-wrapper'> did not support any reflection before 2.5 diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py index d2f9720..8080e41 100644 --- a/Lib/test/test_descrtut.py +++ b/Lib/test/test_descrtut.py @@ -313,7 +313,7 @@ Attributes defined by get/set methods ... ... def __set__(self, inst, value): ... if self.__set is None: - ... raise AttributeError, "this attribute is read-only" + ... raise AttributeError("this attribute is read-only") ... return self.__set(inst, value) Now let's define a class with an attribute x defined by a pair of methods, diff --git a/Lib/test/test_dl.py b/Lib/test/test_dl.py index ba5d8bd..606da46 100755 --- a/Lib/test/test_dl.py +++ b/Lib/test/test_dl.py @@ -31,4 +31,4 @@ for s, func in sharedlibs: print('worked!') break else: - raise TestSkipped, 'Could not open any shared libraries' + raise TestSkipped('Could not open any shared libraries') diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 718f7b2..ab0e1d0 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -811,7 +811,7 @@ Exception messages may contain newlines: >>> def f(x): ... r''' - ... >>> raise ValueError, 'multi\nline\nmessage' + ... >>> raise ValueError('multi\nline\nmessage') ... Traceback (most recent call last): ... ValueError: multi ... line @@ -826,7 +826,7 @@ message is raised, then it is reported as a failure: >>> def f(x): ... r''' - ... >>> raise ValueError, 'message' + ... >>> raise ValueError('message') ... Traceback (most recent call last): ... ValueError: wrong message ... ''' @@ -836,7 +836,7 @@ message is raised, then it is reported as a failure: ********************************************************************** File ..., line 3, in f Failed example: - raise ValueError, 'message' + raise ValueError('message') Expected: Traceback (most recent call last): ValueError: wrong message @@ -851,7 +851,7 @@ detail: >>> def f(x): ... r''' - ... >>> raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + ... >>> raise ValueError('message') #doctest: +IGNORE_EXCEPTION_DETAIL ... Traceback (most recent call last): ... ValueError: wrong message ... ''' @@ -863,7 +863,7 @@ But IGNORE_EXCEPTION_DETAIL does not allow a mismatch in the exception type: >>> def f(x): ... r''' - ... >>> raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + ... >>> raise ValueError('message') #doctest: +IGNORE_EXCEPTION_DETAIL ... Traceback (most recent call last): ... TypeError: wrong type ... ''' @@ -873,7 +873,7 @@ But IGNORE_EXCEPTION_DETAIL does not allow a mismatch in the exception type: ********************************************************************** File ..., line 3, in f Failed example: - raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + raise ValueError('message') #doctest: +IGNORE_EXCEPTION_DETAIL Expected: Traceback (most recent call last): TypeError: wrong type diff --git a/Lib/test/test_exception_variations.py b/Lib/test/test_exception_variations.py index 8fe75e8..5bcb8fc 100644 --- a/Lib/test/test_exception_variations.py +++ b/Lib/test/test_exception_variations.py @@ -9,7 +9,7 @@ class ExceptionTestCase(unittest.TestCase): hit_finally = False try: - raise Exception, 'nyaa!' + raise Exception('nyaa!') except: hit_except = True else: @@ -44,7 +44,7 @@ class ExceptionTestCase(unittest.TestCase): hit_finally = False try: - raise Exception, 'yarr!' + raise Exception('yarr!') except: hit_except = True finally: @@ -71,7 +71,7 @@ class ExceptionTestCase(unittest.TestCase): hit_except = False try: - raise Exception, 'ahoy!' + raise Exception('ahoy!') except: hit_except = True @@ -92,7 +92,7 @@ class ExceptionTestCase(unittest.TestCase): hit_else = False try: - raise Exception, 'foo!' + raise Exception('foo!') except: hit_except = True else: @@ -132,7 +132,7 @@ class ExceptionTestCase(unittest.TestCase): try: try: - raise Exception, 'inner exception' + raise Exception('inner exception') except: hit_inner_except = True finally: @@ -159,7 +159,7 @@ class ExceptionTestCase(unittest.TestCase): else: hit_inner_else = True - raise Exception, 'outer exception' + raise Exception('outer exception') except: hit_except = True else: diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py index 40ebad0..56a207a 100644 --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -90,7 +90,7 @@ class Nothing: if i < 3: return i else: - raise IndexError, i + raise IndexError(i) g(*Nothing()) class Nothing: @@ -253,7 +253,7 @@ try: except TypeError: pass else: - raise TestFailed, 'expected TypeError; no exception raised' + raise TestFailed('expected TypeError; no exception raised') a, b, d, e, v, k = 'A', 'B', 'D', 'E', 'V', 'K' funcs = [] diff --git a/Lib/test/test_fork1.py b/Lib/test/test_fork1.py index e64e398..221a14d 100644 --- a/Lib/test/test_fork1.py +++ b/Lib/test/test_fork1.py @@ -9,7 +9,7 @@ from test.test_support import TestSkipped, run_unittest, reap_children try: os.fork except AttributeError: - raise TestSkipped, "os.fork not defined -- skipping test_fork1" + raise TestSkipped("os.fork not defined -- skipping test_fork1") class ForkTest(ForkWait): def wait_impl(self, cpid): diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index ade3132..4c3d36e 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -216,7 +216,7 @@ def test_exc(formatstr, args, exception, excmsg): print('Unexpected exception') raise else: - raise TestFailed, 'did not get expected exception: %s' % excmsg + raise TestFailed('did not get expected exception: %s' % excmsg) test_exc('abc %a', 1, ValueError, "unsupported format character 'a' (0x61) at index 5") @@ -241,4 +241,4 @@ if maxsize == 2**31-1: except MemoryError: pass else: - raise TestFailed, '"%*d"%(maxsize, -127) should fail' + raise TestFailed('"%*d"%(maxsize, -127) should fail') diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index 528ca18..66ba9cb 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -17,40 +17,40 @@ verify(verify.__module__ == "test.test_support") try: b.publish except AttributeError: pass -else: raise TestFailed, 'expected AttributeError' +else: raise TestFailed('expected AttributeError') if b.__dict__ != {}: - raise TestFailed, 'expected unassigned func.__dict__ to be {}' + raise TestFailed('expected unassigned func.__dict__ to be {}') b.publish = 1 if b.publish != 1: - raise TestFailed, 'function attribute not set to expected value' + raise TestFailed('function attribute not set to expected value') docstring = 'its docstring' b.__doc__ = docstring if b.__doc__ != docstring: - raise TestFailed, 'problem with setting __doc__ attribute' + raise TestFailed('problem with setting __doc__ attribute') if 'publish' not in dir(b): - raise TestFailed, 'attribute not in dir()' + raise TestFailed('attribute not in dir()') try: del b.__dict__ except TypeError: pass -else: raise TestFailed, 'del func.__dict__ expected TypeError' +else: raise TestFailed('del func.__dict__ expected TypeError') b.publish = 1 try: b.__dict__ = None except TypeError: pass -else: raise TestFailed, 'func.__dict__ = None expected TypeError' +else: raise TestFailed('func.__dict__ = None expected TypeError') d = {'hello': 'world'} b.__dict__ = d if b.__dict__ is not d: - raise TestFailed, 'func.__dict__ assignment to dictionary failed' + raise TestFailed('func.__dict__ assignment to dictionary failed') if b.hello != 'world': - raise TestFailed, 'attribute after func.__dict__ assignment failed' + raise TestFailed('attribute after func.__dict__ assignment failed') f1 = F() f2 = F() @@ -58,45 +58,45 @@ f2 = F() try: F.a.publish except AttributeError: pass -else: raise TestFailed, 'expected AttributeError' +else: raise TestFailed('expected AttributeError') try: f1.a.publish except AttributeError: pass -else: raise TestFailed, 'expected AttributeError' +else: raise TestFailed('expected AttributeError') # In Python 2.1 beta 1, we disallowed setting attributes on unbound methods # (it was already disallowed on bound methods). See the PEP for details. try: F.a.publish = 1 except (AttributeError, TypeError): pass -else: raise TestFailed, 'expected AttributeError or TypeError' +else: raise TestFailed('expected AttributeError or TypeError') # But setting it explicitly on the underlying function object is okay. F.a.im_func.publish = 1 if F.a.publish != 1: - raise TestFailed, 'unbound method attribute not set to expected value' + raise TestFailed('unbound method attribute not set to expected value') if f1.a.publish != 1: - raise TestFailed, 'bound method attribute access did not work' + raise TestFailed('bound method attribute access did not work') if f2.a.publish != 1: - raise TestFailed, 'bound method attribute access did not work' + raise TestFailed('bound method attribute access did not work') if 'publish' not in dir(F.a): - raise TestFailed, 'attribute not in dir()' + raise TestFailed('attribute not in dir()') try: f1.a.publish = 0 except (AttributeError, TypeError): pass -else: raise TestFailed, 'expected AttributeError or TypeError' +else: raise TestFailed('expected AttributeError or TypeError') # See the comment above about the change in semantics for Python 2.1b1 try: F.a.myclass = F except (AttributeError, TypeError): pass -else: raise TestFailed, 'expected AttributeError or TypeError' +else: raise TestFailed('expected AttributeError or TypeError') F.a.im_func.myclass = F @@ -107,18 +107,18 @@ F.a.myclass if f1.a.myclass is not f2.a.myclass or \ f1.a.myclass is not F.a.myclass: - raise TestFailed, 'attributes were not the same' + raise TestFailed('attributes were not the same') # try setting __dict__ try: F.a.__dict__ = (1, 2, 3) except (AttributeError, TypeError): pass -else: raise TestFailed, 'expected TypeError or AttributeError' +else: raise TestFailed('expected TypeError or AttributeError') F.a.im_func.__dict__ = {'one': 11, 'two': 22, 'three': 33} if f1.a.two != 22: - raise TestFailed, 'setting __dict__' + raise TestFailed('setting __dict__') from UserDict import UserDict d = UserDict({'four': 44, 'five': 55}) @@ -225,13 +225,13 @@ def cantset(obj, name, value, exception=(AttributeError, TypeError)): except exception: pass else: - raise TestFailed, "shouldn't be able to set %s to %r" % (name, value) + raise TestFailed("shouldn't be able to set %s to %r" % (name, value)) try: delattr(obj, name) except (AttributeError, TypeError): pass else: - raise TestFailed, "shouldn't be able to del %s" % name + raise TestFailed("shouldn't be able to del %s" % name) def test_func_closure(): a = 12 @@ -298,7 +298,7 @@ def test_func_defaults(): except TypeError: pass else: - raise TestFailed, "shouldn't be allowed to call g() w/o defaults" + raise TestFailed("shouldn't be allowed to call g() w/o defaults") def test_func_dict(): def f(): pass diff --git a/Lib/test/test_gdbm.py b/Lib/test/test_gdbm.py index c76b95b..ee68277 100755 --- a/Lib/test/test_gdbm.py +++ b/Lib/test/test_gdbm.py @@ -24,7 +24,7 @@ try: except error: pass else: - raise TestFailed, "expected gdbm.error accessing closed database" + raise TestFailed("expected gdbm.error accessing closed database") g = gdbm.open(filename, 'r') g.close() g = gdbm.open(filename, 'w') @@ -37,7 +37,7 @@ try: except error: pass else: - raise TestFailed, "expected gdbm.error when passing invalid open flags" + raise TestFailed("expected gdbm.error when passing invalid open flags") try: import os diff --git a/Lib/test/test_importhooks.py b/Lib/test/test_importhooks.py index 18f3fc4..3108bd6 100644 --- a/Lib/test/test_importhooks.py +++ b/Lib/test/test_importhooks.py @@ -105,7 +105,7 @@ class ImportBlocker: return self return None def load_module(self, fullname): - raise ImportError, "I dare you" + raise ImportError("I dare you") class ImpWrapper: diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py index b92c50a..07a3bf2 100644 --- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -825,7 +825,7 @@ class TestCase(unittest.TestCase): i = state[0] state[0] = i+1 if i == 10: - raise AssertionError, "shouldn't have gotten this far" + raise AssertionError("shouldn't have gotten this far") return i b = iter(spam, 5) self.assertEqual(list(b), list(range(5))) diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index a0933fe..a54a833 100644 --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -44,8 +44,8 @@ else: except (IOError, OverflowError): f.close() os.unlink(test_support.TESTFN) - raise test_support.TestSkipped, \ - "filesystem does not have largefile support" + raise test_support.TestSkipped( + "filesystem does not have largefile support") else: f.close() @@ -56,8 +56,8 @@ def expect(got_this, expect_this): if got_this != expect_this: if test_support.verbose: print('no') - raise test_support.TestFailed, 'got %r, but expected %r' %\ - (got_this, expect_this) + raise test_support.TestFailed('got %r, but expected %r' + % (got_this, expect_this)) else: if test_support.verbose: print('yes') diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py index 2dd6510..1bfb3b3 100644 --- a/Lib/test/test_locale.py +++ b/Lib/test/test_locale.py @@ -3,7 +3,8 @@ import locale import sys if sys.platform == 'darwin': - raise TestSkipped("Locale support on MacOSX is minimal and cannot be tested") + raise TestSkipped( + "Locale support on MacOSX is minimal and cannot be tested") oldlocale = locale.setlocale(locale.LC_NUMERIC) if sys.platform.startswith("win"): @@ -18,20 +19,22 @@ for tloc in tlocs: except locale.Error: continue else: - raise ImportError, "test locale not supported (tried %s)"%(', '.join(tlocs)) + raise ImportError( + "test locale not supported (tried %s)" % (', '.join(tlocs))) def testformat(formatstr, value, grouping = 0, output=None, func=locale.format): if verbose: if output: - print("%s %% %s =? %s ..." %\ - (repr(formatstr), repr(value), repr(output)), end=' ') + print("%s %% %s =? %s ..." % + (repr(formatstr), repr(value), repr(output)), end=' ') else: - print("%s %% %s works? ..." % (repr(formatstr), repr(value)), end=' ') + print("%s %% %s works? ..." % (repr(formatstr), repr(value)), + end=' ') result = func(formatstr, value, grouping = grouping) if output and result != output: if verbose: print('no') - print("%s %% %s == %s != %s" %\ + print("%s %% %s == %s != %s" % (repr(formatstr), repr(value), repr(result), repr(output))) else: if verbose: diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 1073cdd..127cf84 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -595,7 +595,7 @@ def test_main_inner(): else: break else: - raise ImportError, "Could not find unused port" + raise ImportError("Could not find unused port") #Set up a handler such that all events are sent via a socket to the log diff --git a/Lib/test/test_openpty.py b/Lib/test/test_openpty.py index cc9e907..f935496 100644 --- a/Lib/test/test_openpty.py +++ b/Lib/test/test_openpty.py @@ -4,7 +4,7 @@ import os, unittest from test.test_support import run_unittest, TestSkipped if not hasattr(os, "openpty"): - raise TestSkipped, "No openpty() available." + raise TestSkipped("No openpty() available.") class OpenptyTest(unittest.TestCase): diff --git a/Lib/test/test_pep277.py b/Lib/test/test_pep277.py index 5574c7d..794de0d 100644 --- a/Lib/test/test_pep277.py +++ b/Lib/test/test_pep277.py @@ -3,7 +3,7 @@ import sys, os, unittest from test import test_support if not os.path.supports_unicode_filenames: - raise test_support.TestSkipped, "test works only on NT+" + raise test_support.TestSkipped("test works only on NT+") filenames = [ 'abc', diff --git a/Lib/test/test_pkgimport.py b/Lib/test/test_pkgimport.py index 574d1db..316ea83 100644 --- a/Lib/test/test_pkgimport.py +++ b/Lib/test/test_pkgimport.py @@ -51,7 +51,7 @@ class TestImport(unittest.TestCase): self.rewrite_file('for') try: __import__(self.module_name) except SyntaxError: pass - else: raise RuntimeError, 'Failed to induce SyntaxError' + else: raise RuntimeError('Failed to induce SyntaxError') self.assert_(self.module_name not in sys.modules and not hasattr(sys.modules[self.package_name], 'foo')) @@ -65,7 +65,7 @@ class TestImport(unittest.TestCase): try: __import__(self.module_name) except NameError: pass - else: raise RuntimeError, 'Failed to induce NameError.' + else: raise RuntimeError('Failed to induce NameError.') # ...now change the module so that the NameError doesn't # happen diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py index 4801640..a6110e6 100644 --- a/Lib/test/test_poll.py +++ b/Lib/test/test_poll.py @@ -6,7 +6,7 @@ from test.test_support import TestSkipped, TESTFN, run_unittest try: select.poll except AttributeError: - raise TestSkipped, "select.poll not defined -- skipping test_poll" + raise TestSkipped("select.poll not defined -- skipping test_poll") def find_ready_matching(ready, flag): @@ -47,14 +47,14 @@ class PollTests(unittest.TestCase): ready = p.poll() ready_writers = find_ready_matching(ready, select.POLLOUT) if not ready_writers: - raise RuntimeError, "no pipes ready for writing" + raise RuntimeError("no pipes ready for writing") wr = random.choice(ready_writers) os.write(wr, MSG) ready = p.poll() ready_readers = find_ready_matching(ready, select.POLLIN) if not ready_readers: - raise RuntimeError, "no pipes ready for reading" + raise RuntimeError("no pipes ready for reading") rd = random.choice(ready_readers) buf = os.read(rd, MSG_LEN) self.assertEqual(len(buf), MSG_LEN) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 7207de5..22ec748 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -5,7 +5,7 @@ from test import test_support try: import posix except ImportError: - raise test_support.TestSkipped, "posix is not available" + raise test_support.TestSkipped("posix is not available") import time import os diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index bfabc2a..e2058ab 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -69,7 +69,7 @@ class PtyTest(unittest.TestCase): debug("Got slave_fd '%d'" % slave_fd) except OSError: # " An optional feature could not be imported " ... ? - raise TestSkipped, "Pseudo-terminals (seemingly) not functional." + raise TestSkipped("Pseudo-terminals (seemingly) not functional.") self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty') diff --git a/Lib/test/test_queue.py b/Lib/test/test_queue.py index bfa5596..0b2f31a 100644 --- a/Lib/test/test_queue.py +++ b/Lib/test/test_queue.py @@ -87,17 +87,17 @@ class FailingQueue(Queue.Queue): def _put(self, item): if self.fail_next_put: self.fail_next_put = False - raise FailingQueueException, "You Lose" + raise FailingQueueException("You Lose") return Queue.Queue._put(self, item) def _get(self): if self.fail_next_get: self.fail_next_get = False - raise FailingQueueException, "You Lose" + raise FailingQueueException("You Lose") return Queue.Queue._get(self) def FailingQueueTest(q): if not q.empty(): - raise RuntimeError, "Call this function with an empty queue" + raise RuntimeError("Call this function with an empty queue") for i in range(QUEUE_SIZE-1): q.put(i) # Test a failing non-blocking put. @@ -178,7 +178,7 @@ def FailingQueueTest(q): def SimpleQueueTest(q): if not q.empty(): - raise RuntimeError, "Call this function with an empty queue" + raise RuntimeError("Call this function with an empty queue") # I guess we better check things actually queue correctly a little :) q.put(111) q.put(222) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index f166188..3b1f7c6 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -612,7 +612,7 @@ def run_re_tests(): elif len(t) == 3: pattern, s, outcome = t else: - raise ValueError, ('Test tuples should have 3 or 5 fields', t) + raise ValueError('Test tuples should have 3 or 5 fields', t) try: obj = re.compile(pattern) diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py index 180440e..efe6923 100644 --- a/Lib/test/test_richcmp.py +++ b/Lib/test/test_richcmp.py @@ -29,7 +29,7 @@ class Number: return self.x >= other def __cmp__(self, other): - raise test_support.TestFailed, "Number.__cmp__() should not be called" + raise test_support.TestFailed("Number.__cmp__() should not be called") def __repr__(self): return "Number(%r)" % (self.x, ) @@ -49,13 +49,13 @@ class Vector: self.data[i] = v def __hash__(self): - raise TypeError, "Vectors cannot be hashed" + raise TypeError("Vectors cannot be hashed") def __bool__(self): - raise TypeError, "Vectors cannot be used in Boolean contexts" + raise TypeError("Vectors cannot be used in Boolean contexts") def __cmp__(self, other): - raise test_support.TestFailed, "Vector.__cmp__() should not be called" + raise test_support.TestFailed("Vector.__cmp__() should not be called") def __repr__(self): return "Vector(%r)" % (self.data, ) @@ -82,7 +82,7 @@ class Vector: if isinstance(other, Vector): other = other.data if len(self.data) != len(other): - raise ValueError, "Cannot compare vectors of different length" + raise ValueError("Cannot compare vectors of different length") return other opmap = { @@ -196,10 +196,10 @@ class MiscTest(unittest.TestCase): def __lt__(self, other): return 0 def __gt__(self, other): return 0 def __eq__(self, other): return 0 - def __le__(self, other): raise TestFailed, "This shouldn't happen" - def __ge__(self, other): raise TestFailed, "This shouldn't happen" - def __ne__(self, other): raise TestFailed, "This shouldn't happen" - def __cmp__(self, other): raise RuntimeError, "expected" + def __le__(self, other): raise TestFailed("This shouldn't happen") + def __ge__(self, other): raise TestFailed("This shouldn't happen") + def __ne__(self, other): raise TestFailed("This shouldn't happen") + def __cmp__(self, other): raise RuntimeError("expected") a = Misb() b = Misb() self.assertEqual(a<b, 0) diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 567053b..22f254a 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -177,7 +177,7 @@ class ScopeTests(unittest.TestCase): if x >= 0: return fact(x) else: - raise ValueError, "x must be >= 0" + raise ValueError("x must be >= 0") self.assertEqual(f(6), 720) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index e955bff..36f148e 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -125,7 +125,7 @@ class ThreadableTest: self.client_ready.set() self.clientSetUp() if not hasattr(test_func, '__call__'): - raise TypeError, "test_func must be a callable function" + raise TypeError("test_func must be a callable function") try: test_func() except Exception as strerror: @@ -133,7 +133,7 @@ class ThreadableTest: self.clientTearDown() def clientSetUp(self): - raise NotImplementedError, "clientSetUp must be implemented." + raise NotImplementedError("clientSetUp must be implemented.") def clientTearDown(self): self.done.set() diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index 0abd7ba..3e0c7a4 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -45,7 +45,7 @@ def receive(sock, n, timeout=20): if sock in r: return sock.recv(n) else: - raise RuntimeError, "timed out on %r" % (sock,) + raise RuntimeError("timed out on %r" % (sock,)) def testdgram(proto, addr): s = socket.socket(proto, socket.SOCK_DGRAM) diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index d3b7857..c7019a4 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -36,8 +36,8 @@ def simple_err(func, *args): except struct.error: pass else: - raise TestFailed, "%s%s did not raise struct.error" % ( - func.__name__, args) + raise TestFailed("%s%s did not raise struct.error" % ( + func.__name__, args)) def any_err(func, *args): try: @@ -45,8 +45,8 @@ def any_err(func, *args): except (struct.error, TypeError): pass else: - raise TestFailed, "%s%s did not raise error" % ( - func.__name__, args) + raise TestFailed("%s%s did not raise error" % ( + func.__name__, args)) def with_warning_restore(func): def _with_warning_restore(*args, **kw): @@ -70,11 +70,11 @@ def deprecated_err(func, *args): pass except DeprecationWarning: if not PY_STRUCT_OVERFLOW_MASKING: - raise TestFailed, "%s%s expected to raise struct.error" % ( - func.__name__, args) + raise TestFailed("%s%s expected to raise struct.error" % ( + func.__name__, args)) else: - raise TestFailed, "%s%s did not raise error" % ( - func.__name__, args) + raise TestFailed("%s%s did not raise error" % ( + func.__name__, args)) deprecated_err = with_warning_restore(deprecated_err) @@ -82,15 +82,15 @@ simple_err(struct.calcsize, 'Z') sz = struct.calcsize('i') if sz * 3 != struct.calcsize('iii'): - raise TestFailed, 'inconsistent sizes' + raise TestFailed('inconsistent sizes') fmt = 'cbxxxxxxhhhhiillffdt' fmt3 = '3c3b18x12h6i6l6f3d3t' sz = struct.calcsize(fmt) sz3 = struct.calcsize(fmt3) if sz * 3 != sz3: - raise TestFailed, 'inconsistent sizes (3*%r -> 3*%d = %d, %r -> %d)' % ( - fmt, sz, 3*sz, fmt3, sz3) + raise TestFailed('inconsistent sizes (3*%r -> 3*%d = %d, %r -> %d)' % ( + fmt, sz, 3*sz, fmt3, sz3)) simple_err(struct.pack, 'iii', 3) simple_err(struct.pack, 'i', 3, 3, 3) @@ -121,8 +121,8 @@ for prefix in ('', '@', '<', '>', '=', '!'): int(100 * fp) != int(100 * f) or int(100 * dp) != int(100 * d) or tp != t): # ^^^ calculate only to two decimal places - raise TestFailed, "unpack/pack not transitive (%s, %s)" % ( - str(format), str((cp, bp, hp, ip, lp, fp, dp, tp))) + raise TestFailed("unpack/pack not transitive (%s, %s)" % ( + str(format), str((cp, bp, hp, ip, lp, fp, dp, tp)))) # Test some of the new features in detail @@ -176,16 +176,16 @@ for fmt, arg, big, lil, asy in tests: ('='+fmt, ISBIGENDIAN and big or lil)]: res = struct.pack(xfmt, arg) if res != exp: - raise TestFailed, "pack(%r, %r) -> %r # expected %r" % ( - fmt, arg, res, exp) + raise TestFailed("pack(%r, %r) -> %r # expected %r" % ( + fmt, arg, res, exp)) n = struct.calcsize(xfmt) if n != len(res): - raise TestFailed, "calcsize(%r) -> %d # expected %d" % ( - xfmt, n, len(res)) + raise TestFailed("calcsize(%r) -> %d # expected %d" % ( + xfmt, n, len(res))) rev = struct.unpack(xfmt, res)[0] if rev != arg and not asy: - raise TestFailed, "unpack(%r, %r) -> (%r,) # expected (%r,)" % ( - fmt, res, rev, arg) + raise TestFailed("unpack(%r, %r) -> (%r,) # expected (%r,)" % ( + fmt, res, rev, arg)) ########################################################################### # Simple native q/Q tests. diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index 5705798..577d4cb 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -108,7 +108,7 @@ def task2(ident): print('\n*** Barrier Test ***') if done.acquire(0): - raise ValueError, "'done' should have remained acquired" + raise ValueError("'done' should have remained acquired") bar = barrier(numtasks) running = numtasks for i in range(numtasks): @@ -119,11 +119,11 @@ print('all tasks done') # not all platforms support changing thread stack size print('\n*** Changing thread stack size ***') if thread.stack_size() != 0: - raise ValueError, "initial stack_size not 0" + raise ValueError("initial stack_size not 0") thread.stack_size(0) if thread.stack_size() != 0: - raise ValueError, "stack_size not reset to default" + raise ValueError("stack_size not reset to default") from os import name as os_name if os_name in ("nt", "os2", "posix"): @@ -143,7 +143,7 @@ if os_name in ("nt", "os2", "posix"): for tss in (262144, 0x100000, 0): thread.stack_size(tss) if failed(thread.stack_size(), tss): - raise ValueError, fail_msg % tss + raise ValueError(fail_msg % tss) print('successfully set stack_size(%d)' % tss) for tss in (262144, 0x100000): diff --git a/Lib/test/test_threadsignals.py b/Lib/test/test_threadsignals.py index 9f076ef..2f014e1 100644 --- a/Lib/test/test_threadsignals.py +++ b/Lib/test/test_threadsignals.py @@ -8,7 +8,7 @@ import sys from test.test_support import run_unittest, TestSkipped if sys.platform[:3] in ('win', 'os2'): - raise TestSkipped, "Can't test signal on %s" % sys.platform + raise TestSkipped("Can't test signal on %s" % sys.platform) process_pid = os.getpid() signalled_all=thread.allocate_lock() diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py index 05e6e9e..f67da77 100644 --- a/Lib/test/test_trace.py +++ b/Lib/test/test_trace.py @@ -314,7 +314,7 @@ class RaisingTraceFuncTestCase(unittest.TestCase): def g(frame, why, extra): if (why == 'line' and frame.f_lineno == f.__code__.co_firstlineno + 2): - raise RuntimeError, "i am crashing" + raise RuntimeError("i am crashing") return g sys.settrace(g) @@ -558,7 +558,7 @@ def no_jump_without_trace_function(): raise else: # Something's wrong - the expected exception wasn't raised. - raise RuntimeError, "Trace-function-less jump failed to fail" + raise RuntimeError("Trace-function-less jump failed to fail") class JumpTestCase(unittest.TestCase): diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 84d7290..36ea067 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -15,7 +15,7 @@ class TracebackCases(unittest.TestCase): except exc as value: return traceback.format_exception_only(exc, value) else: - raise ValueError, "call did not raise exception" + raise ValueError("call did not raise exception") def syntax_error_with_caret(self): compile("def fact(x):\n\treturn x!\n", "?", "exec") diff --git a/Lib/test/test_unicode_file.py b/Lib/test/test_unicode_file.py index efa4ad1..ef118df 100644 --- a/Lib/test/test_unicode_file.py +++ b/Lib/test/test_unicode_file.py @@ -25,7 +25,7 @@ if TESTFN_ENCODED.decode(TESTFN_ENCODING) != TESTFN_UNICODE: TESTFN_ENCODED = TESTFN_UNICODE.encode(TESTFN_ENCODING) if '?' in TESTFN_ENCODED: # MBCS will not report the error properly - raise UnicodeError, "mbcs encoding problem" + raise UnicodeError("mbcs encoding problem") except (UnicodeError, TypeError): raise TestSkipped("Cannot find a suitable filename") diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_univnewlines.py index 4ca1a27..22fd266 100644 --- a/Lib/test/test_univnewlines.py +++ b/Lib/test/test_univnewlines.py @@ -5,8 +5,8 @@ import sys from test import test_support if not hasattr(sys.stdin, 'newlines'): - raise test_support.TestSkipped, \ - "This Python does not have universal newline support" + raise test_support.TestSkipped( + "This Python does not have universal newline support") FATX = 'x' * (2**14) diff --git a/Lib/test/test_wait3.py b/Lib/test/test_wait3.py index 9de64b2..3adbec4 100644 --- a/Lib/test/test_wait3.py +++ b/Lib/test/test_wait3.py @@ -9,12 +9,12 @@ from test.test_support import TestSkipped, run_unittest, reap_children try: os.fork except AttributeError: - raise TestSkipped, "os.fork not defined -- skipping test_wait3" + raise TestSkipped("os.fork not defined -- skipping test_wait3") try: os.wait3 except AttributeError: - raise TestSkipped, "os.wait3 not defined -- skipping test_wait3" + raise TestSkipped("os.wait3 not defined -- skipping test_wait3") class Wait3Test(ForkWait): def wait_impl(self, cpid): diff --git a/Lib/test/test_wait4.py b/Lib/test/test_wait4.py index 9f7fc14..c85944d 100644 --- a/Lib/test/test_wait4.py +++ b/Lib/test/test_wait4.py @@ -9,12 +9,12 @@ from test.test_support import TestSkipped, run_unittest, reap_children try: os.fork except AttributeError: - raise TestSkipped, "os.fork not defined -- skipping test_wait4" + raise TestSkipped("os.fork not defined -- skipping test_wait4") try: os.wait4 except AttributeError: - raise TestSkipped, "os.wait4 not defined -- skipping test_wait4" + raise TestSkipped("os.wait4 not defined -- skipping test_wait4") class Wait4Test(ForkWait): def wait_impl(self, cpid): diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py index 85f5566..271f0a8 100644 --- a/Lib/test/test_wave.py +++ b/Lib/test/test_wave.py @@ -4,7 +4,7 @@ import wave def check(t, msg=None): if not t: - raise TestFailed, msg + raise TestFailed(msg) nchannels = 2 sampwidth = 2 diff --git a/Lib/test/time_hashlib.py b/Lib/test/time_hashlib.py index df12f83..d939463 100644 --- a/Lib/test/time_hashlib.py +++ b/Lib/test/time_hashlib.py @@ -6,7 +6,7 @@ import hashlib def creatorFunc(): - raise RuntimeError, "eek, creatorFunc not overridden" + raise RuntimeError("eek, creatorFunc not overridden") def test_scaled_msg(scale, name): iterations = 106201/scale * 20 |