Commit 619939b3 authored by Tim Peters's avatar Tim Peters

test_bug1001011(): Verify that

    s.join([t]) is t

for (s, t) in (str, str), (unicode, unicode), and (str, unicode).
For (unicode, str), verify that it's *not* t (the result is promoted
to unicode instead).  Also verify that when t is a subclass of str or
unicode that "the right thing" happens.
parent 8dfe87af
...@@ -699,14 +699,13 @@ class MixinStrUserStringTest: ...@@ -699,14 +699,13 @@ class MixinStrUserStringTest:
class MixinStrUnicodeTest: class MixinStrUnicodeTest:
# Additional tests that only work with # Additional tests that only work with str and unicode.
# str and unicode
def test_bug1001011(self): def test_bug1001011(self):
# Make sure join returns a NEW object for single item sequences # Make sure join returns a NEW object for single item sequences
# involving a subclass # involving a subclass.
# Make sure that it is of the appropriate type # Make sure that it is of the appropriate type.
# Check the optimisation still occurs for standard objects # Check the optimisation still occurs for standard objects.
t = self.type2test t = self.type2test
class subclass(t): class subclass(t):
pass pass
...@@ -714,3 +713,32 @@ class MixinStrUnicodeTest: ...@@ -714,3 +713,32 @@ class MixinStrUnicodeTest:
s2 = t().join([s1]) s2 = t().join([s1])
self.assert_(s1 is not s2) self.assert_(s1 is not s2)
self.assert_(type(s2) is t) self.assert_(type(s2) is t)
s1 = t("abcd")
s2 = t().join([s1])
self.assert_(s1 is s2)
# Should also test mixed-type join.
if t is unicode:
s1 = subclass("abcd")
s2 = "".join([s1])
self.assert_(s1 is not s2)
self.assert_(type(s2) is t)
s1 = t("abcd")
s2 = "".join([s1])
self.assert_(s1 is s2)
elif t is str:
s1 = subclass("abcd")
s2 = u"".join([s1])
self.assert_(s1 is not s2)
self.assert_(type(s2) is unicode) # promotes!
s1 = t("abcd")
s2 = u"".join([s1])
self.assert_(s1 is not s2)
self.assert_(type(s2) is unicode) # promotes!
else:
self.fail("unexpected type for MixinStrUnicodeTest %r" % t)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment