[Python-checkins] python/dist/src/Lib/test string_tests.py, 1.40,
1.41
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Fri Aug 27 07:36:10 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16557/Lib/test
Modified Files:
string_tests.py
Log Message:
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.
Index: string_tests.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/string_tests.py,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- string_tests.py 26 Aug 2004 16:53:04 -0000 1.40
+++ string_tests.py 27 Aug 2004 05:36:07 -0000 1.41
@@ -699,14 +699,13 @@
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 @@
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)
More information about the Python-checkins
mailing list