diff options
author | Walter Dörwald <walter@livinglogic.de> | 2003-02-21 12:53:50 +0000 |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2003-02-21 12:53:50 +0000 |
commit | deb27a216f1fb339f7d47f1f9df02d448f895ee6 (patch) | |
tree | d64db0220809b67a9a44ec7e56ce7261cf21b160 /Lib/test/test_userstring.py | |
parent | 4adbc861dede3730f3f09418b8bf32acb2259fac (diff) | |
download | cpython-deb27a216f1fb339f7d47f1f9df02d448f895ee6.tar.gz |
Port all string tests to PyUnit and share as much tests
between str, unicode, UserString and the string module
as possible. This increases code coverage in stringobject.c
from 83% to 86% and should help keep the string classes
in sync in the future. From SF patch #662807
Diffstat (limited to 'Lib/test/test_userstring.py')
-rwxr-xr-x | Lib/test/test_userstring.py | 85 |
1 files changed, 46 insertions, 39 deletions
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py index 67fbb5c00e..a821456476 100755 --- a/Lib/test/test_userstring.py +++ b/Lib/test/test_userstring.py @@ -1,45 +1,52 @@ #!/usr/bin/env python -import sys -from test.test_support import verbose -from test import string_tests # UserString is a wrapper around the native builtin string type. # UserString instances should behave similar to builtin string objects. -# The test cases were in part derived from 'test_string.py'. + +import unittest +from test import test_support, string_tests + from UserString import UserString +class UserStringTest( + string_tests.CommonTest, + string_tests.MixinStrUnicodeUserStringTest, + string_tests.MixinStrStringUserStringTest, + string_tests.MixinStrUserStringTest + ): + + type2test = UserString + + # Overwrite the three testing methods, because UserString + # can't cope with arguments propagated to UserString + # (and we don't test with subclasses) + def checkequal(self, result, object, methodname, *args): + result = self.fixtype(result) + object = self.fixtype(object) + # we don't fix the arguments, because UserString can't cope with it + realresult = getattr(object, methodname)(*args) + self.assertEqual( + result, + realresult + ) + + def checkraises(self, exc, object, methodname, *args): + object = self.fixtype(object) + # we don't fix the arguments, because UserString can't cope with it + self.assertRaises( + exc, + getattr(object, methodname), + *args + ) + + def checkcall(self, object, methodname, *args): + object = self.fixtype(object) + # we don't fix the arguments, because UserString can't cope with it + getattr(object, methodname)(*args) + +def test_main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(UserStringTest)) + test_support.run_suite(suite) + if __name__ == "__main__": - verbose = '-v' in sys.argv - -tested_methods = {} - -def test(methodname, input, output, *args): - global tested_methods - tested_methods[methodname] = 1 - if verbose: - print '%r.%s(%s)' % (input, methodname, ", ".join(map(repr, args))), - u = UserString(input) - objects = [input, u, UserString(u)] - res = [""] * 3 - for i in range(3): - object = objects[i] - try: - f = getattr(object, methodname) - except AttributeError: - f = None - res[i] = AttributeError - else: - try: - res[i] = apply(f, args) - except: - res[i] = sys.exc_type - if res[0] == res[1] == res[2] == output: - if verbose: - print 'yes' - else: - if verbose: - print 'no' - print (methodname, input, output, args, res[0], res[1], res[2]) - -string_tests.run_method_tests(test) -string_tests.run_contains_tests(test) -string_tests.run_inplace_tests(UserString) + test_main() |