summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-08-27 05:36:07 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-08-27 05:36:07 (GMT)
commit108f13751999f63c20fa9067f3fc0feb6a87718e (patch)
tree141841ac135b6be661c7d316f2fee21f158d5e2c
parent894c512c2ff6c2ec511716e58d8c4d9ff7e8c137 (diff)
downloadcpython-108f13751999f63c20fa9067f3fc0feb6a87718e.zip
cpython-108f13751999f63c20fa9067f3fc0feb6a87718e.tar.gz
cpython-108f13751999f63c20fa9067f3fc0feb6a87718e.tar.bz2
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.
-rw-r--r--Lib/test/string_tests.py38
1 files changed, 33 insertions, 5 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 9cf6b9e1c..4335965 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -699,14 +699,13 @@ class MixinStrUserStringTest:
class MixinStrUnicodeTest:
- # Additional tests that only work with
- # str and unicode
+ # Additional tests that only work with str and unicode.
def test_bug1001011(self):
# Make sure join returns a NEW object for single item sequences
- # involving a subclass
- # Make sure that it is of the appropriate type
- # Check the optimisation still occurs for standard objects
+ # involving a subclass.
+ # Make sure that it is of the appropriate type.
+ # Check the optimisation still occurs for standard objects.
t = self.type2test
class subclass(t):
pass
@@ -714,3 +713,32 @@ class MixinStrUnicodeTest:
s2 = t().join([s1])
self.assert_(s1 is not s2)
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)