mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
gh-81005: Refactor str tests to reflect that str and unicode are merged in Python 3 (#13172)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
parent
76170f5458
commit
ddb1485953
5 changed files with 31 additions and 39 deletions
|
@ -8,18 +8,12 @@ from test.support import import_helper
|
|||
from collections import UserList
|
||||
import random
|
||||
|
||||
|
||||
class Sequence:
|
||||
def __init__(self, seq='wxyz'): self.seq = seq
|
||||
def __len__(self): return len(self.seq)
|
||||
def __getitem__(self, i): return self.seq[i]
|
||||
|
||||
class BadSeq1(Sequence):
|
||||
def __init__(self): self.seq = [7, 'hello', 123]
|
||||
def __str__(self): return '{0} {1} {2}'.format(*self.seq)
|
||||
|
||||
class BadSeq2(Sequence):
|
||||
def __init__(self): self.seq = ['a', 'b', 'c']
|
||||
def __len__(self): return 8
|
||||
|
||||
class BaseTest:
|
||||
# These tests are for buffers of values (bytes) and not
|
||||
|
@ -27,7 +21,7 @@ class BaseTest:
|
|||
# and various string implementations
|
||||
|
||||
# The type to be tested
|
||||
# Change in subclasses to change the behaviour of fixtesttype()
|
||||
# Change in subclasses to change the behaviour of fixtype()
|
||||
type2test = None
|
||||
|
||||
# Whether the "contained items" of the container are integers in
|
||||
|
@ -36,7 +30,7 @@ class BaseTest:
|
|||
contains_bytes = False
|
||||
|
||||
# All tests pass their arguments to the testing methods
|
||||
# as str objects. fixtesttype() can be used to propagate
|
||||
# as str objects. fixtype() can be used to propagate
|
||||
# these arguments to the appropriate type
|
||||
def fixtype(self, obj):
|
||||
if isinstance(obj, str):
|
||||
|
@ -1096,7 +1090,7 @@ class BaseTest:
|
|||
self.checkraises(TypeError, 'abc', 'splitlines', 42, 42)
|
||||
|
||||
|
||||
class CommonTest(BaseTest):
|
||||
class StringLikeTest(BaseTest):
|
||||
# This testcase contains tests that can be used in all
|
||||
# stringlike classes. Currently this is str and UserString.
|
||||
|
||||
|
@ -1127,11 +1121,6 @@ class CommonTest(BaseTest):
|
|||
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')
|
||||
|
@ -1313,8 +1302,11 @@ class MixinStrUnicodeUserStringTest:
|
|||
self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
|
||||
('a' * i,) * i)
|
||||
|
||||
#self.checkequal(str(BadSeq1()), ' ', 'join', BadSeq1())
|
||||
self.checkequal('a b c', ' ', 'join', BadSeq2())
|
||||
class LiesAboutLengthSeq(Sequence):
|
||||
def __init__(self): self.seq = ['a', 'b', 'c']
|
||||
def __len__(self): return 8
|
||||
|
||||
self.checkequal('a b c', ' ', 'join', LiesAboutLengthSeq())
|
||||
|
||||
self.checkraises(TypeError, ' ', 'join')
|
||||
self.checkraises(TypeError, ' ', 'join', None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue