diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -682,21 +682,6 @@ class BaseTest: self.checkraises(OverflowError, A2_16, "replace", "A", A2_16) self.checkraises(OverflowError, A2_16, "replace", "AA", A2_16+A2_16) - - -class CommonTest(BaseTest): - # This testcase contains tests that can be used in all - # stringlike classes. Currently this is str and UserString. - - def test_hash(self): - # SF bug 1054139: += optimization was not invalidating cached hash value - a = self.type2test('DNSSEC') - b = self.type2test('') - for c in a: - b += c - hash(b) - self.assertEqual(hash(a), hash(b)) - def test_capitalize(self): self.checkequal(' hello ', ' hello ', 'capitalize') self.checkequal('Hello ', 'Hello ','capitalize') @@ -704,23 +689,6 @@ class CommonTest(BaseTest): self.checkequal('Aaaa', 'aaaa', 'capitalize') self.checkequal('Aaaa', 'AaAa', 'capitalize') - # check that titlecased chars are lowered correctly - # \u1ffc is the titlecased char - self.checkequal('\u03a9\u0399\u1ff3\u1ff3\u1ff3', - '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize') - # check with cased non-letter chars - self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', - '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize') - self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', - '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize') - self.checkequal('\u2160\u2171\u2172', - '\u2160\u2161\u2162', 'capitalize') - self.checkequal('\u2160\u2171\u2172', - '\u2170\u2171\u2172', 'capitalize') - # check with Ll chars with no upper - nothing changes here - self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7', - '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize') - self.checkraises(TypeError, 'hello', 'capitalize', 42) def test_additional_split(self): @@ -854,10 +822,6 @@ class CommonTest(BaseTest): self.checkraises(TypeError, '123', 'zfill') -class MixinStrUnicodeUserStringTest: - # additional tests that only work for - # stringlike objects, i.e. str, UserString - def test_islower(self): self.checkequal(False, '', 'islower') self.checkequal(True, 'a', 'islower') @@ -960,6 +924,43 @@ class MixinStrUnicodeUserStringTest: self.checkraises(TypeError, 'abc', 'splitlines', 42, 42) + +class CommonTest(BaseTest): + # This testcase contains tests that can be used in all + # stringlike classes. Currently this is str and UserString. + + def test_hash(self): + # SF bug 1054139: += optimization was not invalidating cached hash value + a = self.type2test('DNSSEC') + b = self.type2test('') + for c in a: + b += c + hash(b) + self.assertEqual(hash(a), hash(b)) + + def test_capitalize_nonascii(self): + # check that titlecased chars are lowered correctly + # \u1ffc is the titlecased char + self.checkequal('\u03a9\u0399\u1ff3\u1ff3\u1ff3', + '\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize') + # check with cased non-letter chars + self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', + '\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize') + self.checkequal('\u24c5\u24e8\u24e3\u24d7\u24de\u24dd', + '\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize') + self.checkequal('\u2160\u2171\u2172', + '\u2160\u2161\u2162', 'capitalize') + self.checkequal('\u2160\u2171\u2172', + '\u2170\u2171\u2172', 'capitalize') + # check with Ll chars with no upper - nothing changes here + self.checkequal('\u019b\u1d00\u1d86\u0221\u1fb7', + '\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize') + + +class MixinStrUnicodeUserStringTest: + # additional tests that only work for + # stringlike objects, i.e. str, UserString + def test_startswith(self): self.checkequal(True, 'hello', 'startswith', 'he') self.checkequal(True, 'hello', 'startswith', 'hello') diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -1,8 +1,7 @@ """Unit tests for the bytes and bytearray types. -XXX This is a mess. Common tests should be moved to buffer_tests.py, -which itself ought to be unified with string_tests.py (and the latter -should be modernized). +XXX This is a mess. Common tests should be unified with string_tests.py (and +the latter should be modernized). """ import os @@ -16,7 +15,6 @@ import unittest import test.support import test.string_tests -import test.buffer_tests from test.support import bigaddrspacetest, MAX_Py_ssize_t @@ -1569,8 +1567,7 @@ class AssortedBytesTest(unittest.TestCas # the rest that make sense (the code can be cleaned up to use modern # unittest methods at the same time). -class BytearrayPEP3137Test(unittest.TestCase, - test.buffer_tests.MixinBytesBufferCommonTests): +class BytearrayPEP3137Test(unittest.TestCase): def marshal(self, x): return bytearray(x) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -415,7 +415,7 @@ class UnicodeTest(string_tests.CommonTes left + delim * 2 + right, 'rsplit', delim *2) def test_partition(self): - string_tests.MixinStrUnicodeUserStringTest.test_partition(self) + super().test_partition() # test mixed kinds self.checkequal(('ABCDEFGH', '', ''), 'ABCDEFGH', 'partition', '\u4200') for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'): @@ -432,7 +432,7 @@ class UnicodeTest(string_tests.CommonTes left + delim * 2 + right, 'partition', delim * 2) def test_rpartition(self): - string_tests.MixinStrUnicodeUserStringTest.test_rpartition(self) + super().test_rpartition() # test mixed kinds self.checkequal(('', '', 'ABCDEFGH'), 'ABCDEFGH', 'rpartition', '\u4200') for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'): @@ -449,7 +449,7 @@ class UnicodeTest(string_tests.CommonTes left + delim * 2 + right, 'rpartition', delim * 2) def test_join(self): - string_tests.MixinStrUnicodeUserStringTest.test_join(self) + super().test_join() class MyWrapper: def __init__(self, sval): self.sval = sval @@ -565,7 +565,7 @@ class UnicodeTest(string_tests.CommonTes self.assertTrue('\ud800\udc02' < '\ud84d\udc56') def test_islower(self): - string_tests.MixinStrUnicodeUserStringTest.test_islower(self) + super().test_islower() self.checkequalnofix(False, '\u1FFc', 'islower') self.assertFalse('\u2167'.islower()) self.assertTrue('\u2177'.islower()) @@ -580,7 +580,7 @@ class UnicodeTest(string_tests.CommonTes self.assertFalse('\U0001F46F'.islower()) def test_isupper(self): - string_tests.MixinStrUnicodeUserStringTest.test_isupper(self) + super().test_isupper() if not sys.platform.startswith('java'): self.checkequalnofix(False, '\u1FFc', 'isupper') self.assertTrue('\u2167'.isupper()) @@ -596,7 +596,7 @@ class UnicodeTest(string_tests.CommonTes self.assertFalse('\U0001F46F'.isupper()) def test_istitle(self): - string_tests.MixinStrUnicodeUserStringTest.test_istitle(self) + super().test_istitle() self.checkequalnofix(True, '\u1FFc', 'istitle') self.checkequalnofix(True, 'Greek \u1FFcitlecases ...', 'istitle') @@ -608,7 +608,7 @@ class UnicodeTest(string_tests.CommonTes self.assertFalse(ch.istitle(), '{!a} is not title'.format(ch)) def test_isspace(self): - string_tests.MixinStrUnicodeUserStringTest.test_isspace(self) + super().test_isspace() self.checkequalnofix(True, '\u2000', 'isspace') self.checkequalnofix(True, '\u200a', 'isspace') self.checkequalnofix(False, '\u2014', 'isspace') @@ -618,13 +618,13 @@ class UnicodeTest(string_tests.CommonTes self.assertFalse(ch.isspace(), '{!a} is not space.'.format(ch)) def test_isalnum(self): - string_tests.MixinStrUnicodeUserStringTest.test_isalnum(self) + super().test_isalnum() for ch in ['\U00010401', '\U00010427', '\U00010429', '\U0001044E', '\U0001D7F6', '\U00011066', '\U000104A0', '\U0001F107']: self.assertTrue(ch.isalnum(), '{!a} is alnum.'.format(ch)) def test_isalpha(self): - string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self) + super().test_isalpha() self.checkequalnofix(True, '\u1FFc', 'isalpha') # non-BMP, cased self.assertTrue('\U00010401'.isalpha()) @@ -654,7 +654,7 @@ class UnicodeTest(string_tests.CommonTes self.assertTrue(ch.isdecimal(), '{!a} is decimal.'.format(ch)) def test_isdigit(self): - string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self) + super().test_isdigit() self.checkequalnofix(True, '\u2460', 'isdigit') self.checkequalnofix(False, '\xbc', 'isdigit') self.checkequalnofix(True, '\u0660', 'isdigit') @@ -807,7 +807,7 @@ class UnicodeTest(string_tests.CommonTes self.assertEqual('A\u0345\u03a3'.capitalize(), 'A\u0345\u03c2') def test_title(self): - string_tests.MixinStrUnicodeUserStringTest.test_title(self) + super().test_title() self.assertEqual('\U0001044F'.title(), '\U00010427') self.assertEqual('\U0001044F\U0001044F'.title(), '\U00010427\U0001044F') @@ -1298,7 +1298,7 @@ class UnicodeTest(string_tests.CommonTes self.assertEqual('{f:{}}{}{g}'.format(2, 4, f=1, g='g'), ' 14g') def test_formatting(self): - string_tests.MixinStrUnicodeUserStringTest.test_formatting(self) + super().test_formatting() # Testing Unicode formatting strings... self.assertEqual("%s, %s" % ("abc", "abc"), 'abc, abc') self.assertEqual("%s, %s, %i, %f, %5.2f" % ("abc", "abc", 1, 2, 3), 'abc, abc, 1, 2.000000, 3.00')