test_userstring.py 1.44 KB
Newer Older
1 2
# UserString is a wrapper around the native builtin string type.
# UserString instances should behave similar to builtin string objects.
3

4
import string
5
import unittest
6
from test import support, string_tests
7

8
from collections import UserString
9

10 11 12
class UserStringTest(
    string_tests.CommonTest,
    string_tests.MixinStrUnicodeUserStringTest,
13
    unittest.TestCase
14 15 16 17 18 19 20
    ):

    type2test = UserString

    # Overwrite the three testing methods, because UserString
    # can't cope with arguments propagated to UserString
    # (and we don't test with subclasses)
21
    def checkequal(self, result, object, methodname, *args, **kwargs):
22 23 24
        result = self.fixtype(result)
        object = self.fixtype(object)
        # we don't fix the arguments, because UserString can't cope with it
25
        realresult = getattr(object, methodname)(*args, **kwargs)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
        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)

45

46
if __name__ == "__main__":
47
    unittest.main()