OLD | NEW |
1 """ | 1 """ |
2 Common tests shared by test_str, test_unicode, test_userstring and test_string. | 2 Common tests shared by test_str, test_unicode, test_userstring and test_string. |
3 """ | 3 """ |
4 | 4 |
5 import unittest, string, sys, struct | 5 import unittest, string, sys, struct |
6 from test import support | 6 from test import support |
7 from collections import UserList | 7 from collections import UserList |
8 | 8 |
9 class Sequence: | 9 class Sequence: |
10 def __init__(self, seq='wxyz'): self.seq = seq | 10 def __init__(self, seq='wxyz'): self.seq = seq |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 # this doesn't happen with subclasses | 60 # this doesn't happen with subclasses |
61 if obj is realresult: | 61 if obj is realresult: |
62 try: | 62 try: |
63 class subtype(self.__class__.type2test): | 63 class subtype(self.__class__.type2test): |
64 pass | 64 pass |
65 except TypeError: | 65 except TypeError: |
66 pass # Skip this if we can't subclass | 66 pass # Skip this if we can't subclass |
67 else: | 67 else: |
68 obj = subtype(obj) | 68 obj = subtype(obj) |
69 realresult = getattr(obj, methodname)(*args) | 69 realresult = getattr(obj, methodname)(*args) |
70 self.assert_(obj is not realresult) | 70 self.assertIsNot(obj, realresult) |
71 | 71 |
72 # check that obj.method(*args) raises exc | 72 # check that obj.method(*args) raises exc |
73 def checkraises(self, exc, obj, methodname, *args): | 73 def checkraises(self, exc, obj, methodname, *args): |
74 obj = self.fixtype(obj) | 74 obj = self.fixtype(obj) |
75 args = self.fixtype(args) | 75 args = self.fixtype(args) |
76 self.assertRaises( | 76 self.assertRaises( |
77 exc, | 77 exc, |
78 getattr(obj, methodname), | 78 getattr(obj, methodname), |
79 *args | 79 *args |
80 ) | 80 ) |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 def test_bug1001011(self): | 1190 def test_bug1001011(self): |
1191 # Make sure join returns a NEW object for single item sequences | 1191 # Make sure join returns a NEW object for single item sequences |
1192 # involving a subclass. | 1192 # involving a subclass. |
1193 # Make sure that it is of the appropriate type. | 1193 # Make sure that it is of the appropriate type. |
1194 # Check the optimisation still occurs for standard objects. | 1194 # Check the optimisation still occurs for standard objects. |
1195 t = self.type2test | 1195 t = self.type2test |
1196 class subclass(t): | 1196 class subclass(t): |
1197 pass | 1197 pass |
1198 s1 = subclass("abcd") | 1198 s1 = subclass("abcd") |
1199 s2 = t().join([s1]) | 1199 s2 = t().join([s1]) |
1200 self.assert_(s1 is not s2) | 1200 self.assertIsNot(s1, s2) |
1201 self.assert_(type(s2) is t) | 1201 self.assertIs(type(s2), t) |
1202 | 1202 |
1203 s1 = t("abcd") | 1203 s1 = t("abcd") |
1204 s2 = t().join([s1]) | 1204 s2 = t().join([s1]) |
1205 self.assert_(s1 is s2) | 1205 self.assertIs(s1, s2) |
1206 | 1206 |
1207 # Should also test mixed-type join. | 1207 # Should also test mixed-type join. |
1208 if t is str: | 1208 if t is str: |
1209 s1 = subclass("abcd") | 1209 s1 = subclass("abcd") |
1210 s2 = "".join([s1]) | 1210 s2 = "".join([s1]) |
1211 self.assert_(s1 is not s2) | 1211 self.assertIsNot(s1, s2) |
1212 self.assert_(type(s2) is t) | 1212 self.assertIs(type(s2), t) |
1213 | 1213 |
1214 s1 = t("abcd") | 1214 s1 = t("abcd") |
1215 s2 = "".join([s1]) | 1215 s2 = "".join([s1]) |
1216 self.assert_(s1 is s2) | 1216 self.assertIs(s1, s2) |
1217 | 1217 |
1218 ## elif t is str8: | 1218 ## elif t is str8: |
1219 ## s1 = subclass("abcd") | 1219 ## s1 = subclass("abcd") |
1220 ## s2 = "".join([s1]) | 1220 ## s2 = "".join([s1]) |
1221 ## self.assert_(s1 is not s2) | 1221 ## self.assertIsNot(s1, s2) |
1222 ## self.assert_(type(s2) is str) # promotes! | 1222 ## self.assertIs(type(s2), str) # promotes! |
1223 | 1223 |
1224 ## s1 = t("abcd") | 1224 ## s1 = t("abcd") |
1225 ## s2 = "".join([s1]) | 1225 ## s2 = "".join([s1]) |
1226 ## self.assert_(s1 is not s2) | 1226 ## self.assertIsNot(s1, s2) |
1227 ## self.assert_(type(s2) is str) # promotes! | 1227 ## self.assertIs(type(s2), str) # promotes! |
1228 | 1228 |
1229 else: | 1229 else: |
1230 self.fail("unexpected type for MixinStrUnicodeTest %r" % t) | 1230 self.fail("unexpected type for MixinStrUnicodeTest %r" % t) |
OLD | NEW |