Catch situations where currentframe() returns None. See SF patch #1447410, this is...
[python.git] / Lib / test / test_str.py
blob45942a66ef24ce5cf9c38f651e269de2844ae929
1 import unittest
2 from test import test_support, string_tests
5 class StrTest(
6 string_tests.CommonTest,
7 string_tests.MixinStrUnicodeUserStringTest,
8 string_tests.MixinStrUserStringTest,
9 string_tests.MixinStrUnicodeTest,
12 type2test = str
14 # We don't need to propagate to str
15 def fixtype(self, obj):
16 return obj
18 def test_formatting(self):
19 string_tests.MixinStrUnicodeUserStringTest.test_formatting(self)
20 self.assertRaises(OverflowError, '%c'.__mod__, 0x1234)
22 def test_conversion(self):
23 # Make sure __str__() behaves properly
24 class Foo0:
25 def __unicode__(self):
26 return u"foo"
28 class Foo1:
29 def __str__(self):
30 return "foo"
32 class Foo2(object):
33 def __str__(self):
34 return "foo"
36 class Foo3(object):
37 def __str__(self):
38 return u"foo"
40 class Foo4(unicode):
41 def __str__(self):
42 return u"foo"
44 class Foo5(str):
45 def __str__(self):
46 return u"foo"
48 class Foo6(str):
49 def __str__(self):
50 return "foos"
52 def __unicode__(self):
53 return u"foou"
55 class Foo7(unicode):
56 def __str__(self):
57 return "foos"
58 def __unicode__(self):
59 return u"foou"
61 class Foo8(str):
62 def __new__(cls, content=""):
63 return str.__new__(cls, 2*content)
64 def __str__(self):
65 return self
67 class Foo9(str):
68 def __str__(self):
69 return "string"
70 def __unicode__(self):
71 return "not unicode"
73 self.assert_(str(Foo0()).startswith("<")) # this is different from __unicode__
74 self.assertEqual(str(Foo1()), "foo")
75 self.assertEqual(str(Foo2()), "foo")
76 self.assertEqual(str(Foo3()), "foo")
77 self.assertEqual(str(Foo4("bar")), "foo")
78 self.assertEqual(str(Foo5("bar")), "foo")
79 self.assertEqual(str(Foo6("bar")), "foos")
80 self.assertEqual(str(Foo7("bar")), "foos")
81 self.assertEqual(str(Foo8("foo")), "foofoo")
82 self.assertEqual(str(Foo9("foo")), "string")
83 self.assertEqual(unicode(Foo9("foo")), u"not unicode")
85 def test_main():
86 test_support.run_unittest(StrTest)
88 if __name__ == "__main__":
89 test_main()