diff options
author | Guido van Rossum <guido@python.org> | 2007-05-17 18:20:34 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-17 18:20:34 (GMT) |
commit | ebe3e16600ddbc19aa7444ec773e2e0786b8a3cf (patch) | |
tree | 1189de0bc8de926ef5b1baa2f646cbd1674b8bab /Lib/test | |
parent | e35553e24c6b90db9ab22298cef663192972bbab (diff) | |
download | cpython-ebe3e16600ddbc19aa7444ec773e2e0786b8a3cf.zip cpython-ebe3e16600ddbc19aa7444ec773e2e0786b8a3cf.tar.gz cpython-ebe3e16600ddbc19aa7444ec773e2e0786b8a3cf.tar.bz2 |
Merged revisions 55342-55406 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r55360 | guido.van.rossum | 2007-05-15 14:57:59 -0700 (Tue, 15 May 2007) | 2 lines
obcheckin.
........
r55361 | guido.van.rossum | 2007-05-15 14:59:18 -0700 (Tue, 15 May 2007) | 2 lines
Get rid of strop module.
........
r55367 | brett.cannon | 2007-05-15 21:06:28 -0700 (Tue, 15 May 2007) | 2 lines
Remove the 'pure' module.
........
r55369 | brett.cannon | 2007-05-15 21:07:31 -0700 (Tue, 15 May 2007) | 2 lines
Remove the lib-old directory (already empty).
........
r55370 | neal.norwitz | 2007-05-15 21:30:40 -0700 (Tue, 15 May 2007) | 1 line
Get rid of a bunch more references to strop
........
r55374 | brett.cannon | 2007-05-15 21:39:00 -0700 (Tue, 15 May 2007) | 2 lines
Complete the removal of IRIX-specific modules.
........
r55379 | brett.cannon | 2007-05-15 22:31:54 -0700 (Tue, 15 May 2007) | 2 lines
Update removed IRIX modules based on what is gone from removing plat-irix6.
........
r55388 | brett.cannon | 2007-05-16 14:34:52 -0700 (Wed, 16 May 2007) | 2 lines
Clean up the docstring for the compiler resource.
........
r55406 | brett.cannon | 2007-05-17 11:05:37 -0700 (Thu, 17 May 2007) | 2 lines
Remove BaseException.message (deprecated in Python 2.6).
........
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/regrtest.py | 8 | ||||
-rw-r--r-- | Lib/test/test_exceptions.py | 107 | ||||
-rw-r--r-- | Lib/test/test_pep352.py | 71 | ||||
-rw-r--r-- | Lib/test/test_strop.py | 24 |
4 files changed, 71 insertions, 139 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 6e52021..1cd553c 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -107,11 +107,8 @@ resources to test. Currently only the following are defined: decimal - Test the decimal module against a large suite that verifies compliance with standards. - compiler - Test the compiler package by compiling all the source - in the standard library and test suite. This takes - a long time. Enabling this resource also allows - test_tokenize to verify round-trip lexing on every - file in the test library. + compiler - Allow test_tokenize to verify round-trip lexing on + every file in the test library. subprocess Run all tests for the subprocess module. @@ -987,7 +984,6 @@ _expectations = { test_poll test_pty test_pwd - test_strop test_sqlite test_startfile test_sunaudiodev diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index b1d6790..64b13b7 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -11,7 +11,6 @@ except ImportError: from test.test_support import (TESTFN, unlink, run_unittest, guard_warnings_filter) -from test.test_pep352 import ignore_message_warning # XXX This is not really enough, each *operation* should be tested! @@ -205,115 +204,113 @@ class ExceptionTests(unittest.TestCase): # test that exception attributes are happy exceptionList = [ - (BaseException, (), {'message' : '', 'args' : ()}), - (BaseException, (1, ), {'message' : 1, 'args' : (1,)}), + (BaseException, (), {'args' : ()}), + (BaseException, (1, ), {'args' : (1,)}), (BaseException, ('foo',), - {'message' : 'foo', 'args' : ('foo',)}), + {'args' : ('foo',)}), (BaseException, ('foo', 1), - {'message' : '', 'args' : ('foo', 1)}), + {'args' : ('foo', 1)}), (SystemExit, ('foo',), - {'message' : 'foo', 'args' : ('foo',), 'code' : 'foo'}), + {'args' : ('foo',), 'code' : 'foo'}), (IOError, ('foo',), - {'message' : 'foo', 'args' : ('foo',), 'filename' : None, + {'args' : ('foo',), 'filename' : None, 'errno' : None, 'strerror' : None}), (IOError, ('foo', 'bar'), - {'message' : '', 'args' : ('foo', 'bar'), 'filename' : None, + {'args' : ('foo', 'bar'), 'filename' : None, 'errno' : 'foo', 'strerror' : 'bar'}), (IOError, ('foo', 'bar', 'baz'), - {'message' : '', 'args' : ('foo', 'bar'), 'filename' : 'baz', + {'args' : ('foo', 'bar'), 'filename' : 'baz', 'errno' : 'foo', 'strerror' : 'bar'}), (IOError, ('foo', 'bar', 'baz', 'quux'), - {'message' : '', 'args' : ('foo', 'bar', 'baz', 'quux')}), + {'args' : ('foo', 'bar', 'baz', 'quux')}), (EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'), - {'message' : '', 'args' : ('errnoStr', 'strErrorStr'), + {'args' : ('errnoStr', 'strErrorStr'), 'strerror' : 'strErrorStr', 'errno' : 'errnoStr', 'filename' : 'filenameStr'}), (EnvironmentError, (1, 'strErrorStr', 'filenameStr'), - {'message' : '', 'args' : (1, 'strErrorStr'), 'errno' : 1, + {'args' : (1, 'strErrorStr'), 'errno' : 1, 'strerror' : 'strErrorStr', 'filename' : 'filenameStr'}), - (SyntaxError, (), {'message' : '', 'msg' : None, 'text' : None, + (SyntaxError, (), {'msg' : None, 'text' : None, 'filename' : None, 'lineno' : None, 'offset' : None, 'print_file_and_line' : None}), (SyntaxError, ('msgStr',), - {'message' : 'msgStr', 'args' : ('msgStr',), 'text' : None, + {'args' : ('msgStr',), 'text' : None, 'print_file_and_line' : None, 'msg' : 'msgStr', 'filename' : None, 'lineno' : None, 'offset' : None}), (SyntaxError, ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr', 'textStr')), - {'message' : '', 'offset' : 'offsetStr', 'text' : 'textStr', + {'offset' : 'offsetStr', 'text' : 'textStr', 'args' : ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr', 'textStr')), 'print_file_and_line' : None, 'msg' : 'msgStr', 'filename' : 'filenameStr', 'lineno' : 'linenoStr'}), (SyntaxError, ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr', 'textStr', 'print_file_and_lineStr'), - {'message' : '', 'text' : None, + {'text' : None, 'args' : ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr', 'textStr', 'print_file_and_lineStr'), 'print_file_and_line' : None, 'msg' : 'msgStr', 'filename' : None, 'lineno' : None, 'offset' : None}), - (UnicodeError, (), {'message' : '', 'args' : (),}), + (UnicodeError, (), {'args' : (),}), (UnicodeEncodeError, (str8('ascii'), 'a', 0, 1, str8('ordinal not in range')), - {'message' : '', 'args' : ('ascii', 'a', 0, 1, + {'args' : ('ascii', 'a', 0, 1, 'ordinal not in range'), 'encoding' : 'ascii', 'object' : 'a', 'start' : 0, 'reason' : 'ordinal not in range'}), (UnicodeDecodeError, (str8('ascii'), b'\xff', 0, 1, str8('ordinal not in range')), - {'message' : '', 'args' : ('ascii', b'\xff', 0, 1, + {'args' : ('ascii', b'\xff', 0, 1, 'ordinal not in range'), 'encoding' : 'ascii', 'object' : b'\xff', 'start' : 0, 'reason' : 'ordinal not in range'}), (UnicodeTranslateError, ("\u3042", 0, 1, str8("ouch")), - {'message' : '', 'args' : ('\u3042', 0, 1, 'ouch'), + {'args' : ('\u3042', 0, 1, 'ouch'), 'object' : '\u3042', 'reason' : 'ouch', 'start' : 0, 'end' : 1}), ] try: exceptionList.append( (WindowsError, (1, 'strErrorStr', 'filenameStr'), - {'message' : '', 'args' : (1, 'strErrorStr'), + {'args' : (1, 'strErrorStr'), 'strerror' : 'strErrorStr', 'winerror' : 1, 'errno' : 22, 'filename' : 'filenameStr'}) ) except NameError: pass - with guard_warnings_filter(): - ignore_message_warning() - for exc, args, expected in exceptionList: - try: - e = exc(*args) - except: - print("\nexc=%r, args=%r" % (exc, args)) - raise - else: - # Verify module name - self.assertEquals(type(e).__module__, '__builtin__') - # Verify no ref leaks in Exc_str() - s = str(e) - for checkArgName in expected: - value = getattr(e, checkArgName) - self.assertEquals(repr(value), - repr(expected[checkArgName]), - '%r.%s == %r, expected %r' % ( - e, checkArgName, - value, expected[checkArgName])) - - # test for pickling support - for p in pickle, cPickle: - if p is None: - continue # cPickle not found -- skip it - for protocol in range(p.HIGHEST_PROTOCOL + 1): - s = p.dumps(e, protocol) - new = p.loads(s) - for checkArgName in expected: - got = repr(getattr(new, checkArgName)) - want = repr(expected[checkArgName]) - self.assertEquals(got, want, - 'pickled "%r", attribute "%s' % - (e, checkArgName)) + for exc, args, expected in exceptionList: + try: + e = exc(*args) + except: + print("\nexc=%r, args=%r" % (exc, args)) + raise + else: + # Verify module name + self.assertEquals(type(e).__module__, '__builtin__') + # Verify no ref leaks in Exc_str() + s = str(e) + for checkArgName in expected: + value = getattr(e, checkArgName) + self.assertEquals(repr(value), + repr(expected[checkArgName]), + '%r.%s == %r, expected %r' % ( + e, checkArgName, + value, expected[checkArgName])) + + # test for pickling support + for p in pickle, cPickle: + if p is None: + continue # cPickle not found -- skip it + for protocol in range(p.HIGHEST_PROTOCOL + 1): + s = p.dumps(e, protocol) + new = p.loads(s) + for checkArgName in expected: + got = repr(getattr(new, checkArgName)) + want = repr(expected[checkArgName]) + self.assertEquals(got, want, + 'pickled "%r", attribute "%s' % + (e, checkArgName)) def testKeywordArgs(self): # test that builtin exception don't take keyword args, diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py index b372ce9..90766ba 100644 --- a/Lib/test/test_pep352.py +++ b/Lib/test/test_pep352.py @@ -5,12 +5,6 @@ from test.test_support import run_unittest, guard_warnings_filter import os from platform import system as platform_system -def ignore_message_warning(): - """Ignore the DeprecationWarning for BaseException.message.""" - warnings.resetwarnings() - warnings.filterwarnings("ignore", "BaseException.message", - DeprecationWarning) - class ExceptionClassTests(unittest.TestCase): @@ -21,12 +15,10 @@ class ExceptionClassTests(unittest.TestCase): self.failUnless(issubclass(Exception, object)) def verify_instance_interface(self, ins): - with guard_warnings_filter(): - ignore_message_warning() - for attr in ("args", "message", "__str__", "__repr__"): - self.failUnless(hasattr(ins, attr), - "%s missing %s attribute" % - (ins.__class__.__name__, attr)) + for attr in ("args", "__str__", "__repr__"): + self.failUnless(hasattr(ins, attr), + "%s missing %s attribute" % + (ins.__class__.__name__, attr)) def test_inheritance(self): # Make sure the inheritance hierarchy matches the documentation @@ -89,7 +81,7 @@ class ExceptionClassTests(unittest.TestCase): inheritance_tree.close() self.failUnlessEqual(len(exc_set), 0, "%s not accounted for" % exc_set) - interface_tests = ("length", "args", "message", "str", "repr") + interface_tests = ("length", "args", "str", "repr") def interface_test_driver(self, results): for test_name, (given, expected) in zip(self.interface_tests, results): @@ -100,57 +92,28 @@ class ExceptionClassTests(unittest.TestCase): # Make sure interface works properly when given a single argument arg = "spam" exc = Exception(arg) - with guard_warnings_filter(): - ignore_message_warning() - results = ([len(exc.args), 1], [exc.args[0], arg], - [exc.message, arg], - [str(exc), str(arg)], - [repr(exc), exc.__class__.__name__ + repr(exc.args)]) - self.interface_test_driver(results) + results = ([len(exc.args), 1], [exc.args[0], arg], + [str(exc), str(arg)], + [repr(exc), exc.__class__.__name__ + repr(exc.args)]) + self.interface_test_driver(results) def test_interface_multi_arg(self): # Make sure interface correct when multiple arguments given arg_count = 3 args = tuple(range(arg_count)) exc = Exception(*args) - with guard_warnings_filter(): - ignore_message_warning() - results = ([len(exc.args), arg_count], [exc.args, args], - [exc.message, ''], [str(exc), str(args)], - [repr(exc), exc.__class__.__name__ + repr(exc.args)]) - self.interface_test_driver(results) + results = ([len(exc.args), arg_count], [exc.args, args], + [str(exc), str(args)], + [repr(exc), exc.__class__.__name__ + repr(exc.args)]) + self.interface_test_driver(results) def test_interface_no_arg(self): # Make sure that with no args that interface is correct exc = Exception() - with guard_warnings_filter(): - ignore_message_warning() - results = ([len(exc.args), 0], [exc.args, tuple()], - [exc.message, ''], - [str(exc), ''], - [repr(exc), exc.__class__.__name__ + '()']) - self.interface_test_driver(results) - - def test_message_deprecation(self): - # As of Python 2.6, BaseException.message is deprecated. - with guard_warnings_filter(): - warnings.resetwarnings() - warnings.filterwarnings('error') - - try: - BaseException().message - except DeprecationWarning: - pass - else: - self.fail("BaseException.message not deprecated") - - exc = BaseException() - try: - exc.message = '' - except DeprecationWarning: - pass - else: - self.fail("BaseException.message assignment not deprecated") + results = ([len(exc.args), 0], [exc.args, tuple()], + [str(exc), ''], + [repr(exc), exc.__class__.__name__ + '()']) + self.interface_test_driver(results) class UsageTests(unittest.TestCase): diff --git a/Lib/test/test_strop.py b/Lib/test/test_strop.py deleted file mode 100644 index 491d223..0000000 --- a/Lib/test/test_strop.py +++ /dev/null @@ -1,24 +0,0 @@ -import warnings -warnings.filterwarnings("ignore", "strop functions are obsolete;", - DeprecationWarning, - r'test.test_strop|unittest') -import strop -import unittest -from test import test_support - - -class StropFunctionTestCase(unittest.TestCase): - - def test_maketrans(self): - self.assert_(strop.maketrans("abc", "xyz") == transtable) - self.assertRaises(ValueError, strop.maketrans, "abc", "xyzq") - - -transtable = b'\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377' - - -def test_main(): - test_support.run_unittest(StropFunctionTestCase) - -if __name__ == "__main__": - test_main() |