diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
commit | 458120dd40db6b4df55a4e96b650e16798ef06a0 (patch) | |
tree | 8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/lib/python/test/test_str.py | |
parent | 3a742c699f6806c1145aea5149bf15de15a0afd7 (diff) |
add hg and python
Diffstat (limited to 'sys/lib/python/test/test_str.py')
-rw-r--r-- | sys/lib/python/test/test_str.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/sys/lib/python/test/test_str.py b/sys/lib/python/test/test_str.py new file mode 100644 index 000000000..45942a66e --- /dev/null +++ b/sys/lib/python/test/test_str.py @@ -0,0 +1,89 @@ +import unittest +from test import test_support, string_tests + + +class StrTest( + string_tests.CommonTest, + string_tests.MixinStrUnicodeUserStringTest, + string_tests.MixinStrUserStringTest, + string_tests.MixinStrUnicodeTest, + ): + + type2test = str + + # We don't need to propagate to str + def fixtype(self, obj): + return obj + + def test_formatting(self): + string_tests.MixinStrUnicodeUserStringTest.test_formatting(self) + self.assertRaises(OverflowError, '%c'.__mod__, 0x1234) + + def test_conversion(self): + # Make sure __str__() behaves properly + class Foo0: + def __unicode__(self): + return u"foo" + + class Foo1: + def __str__(self): + return "foo" + + class Foo2(object): + def __str__(self): + return "foo" + + class Foo3(object): + def __str__(self): + return u"foo" + + class Foo4(unicode): + def __str__(self): + return u"foo" + + class Foo5(str): + def __str__(self): + return u"foo" + + class Foo6(str): + def __str__(self): + return "foos" + + def __unicode__(self): + return u"foou" + + class Foo7(unicode): + def __str__(self): + return "foos" + def __unicode__(self): + return u"foou" + + class Foo8(str): + def __new__(cls, content=""): + return str.__new__(cls, 2*content) + def __str__(self): + return self + + class Foo9(str): + def __str__(self): + return "string" + def __unicode__(self): + return "not unicode" + + self.assert_(str(Foo0()).startswith("<")) # this is different from __unicode__ + self.assertEqual(str(Foo1()), "foo") + self.assertEqual(str(Foo2()), "foo") + self.assertEqual(str(Foo3()), "foo") + self.assertEqual(str(Foo4("bar")), "foo") + self.assertEqual(str(Foo5("bar")), "foo") + self.assertEqual(str(Foo6("bar")), "foos") + self.assertEqual(str(Foo7("bar")), "foos") + self.assertEqual(str(Foo8("foo")), "foofoo") + self.assertEqual(str(Foo9("foo")), "string") + self.assertEqual(unicode(Foo9("foo")), u"not unicode") + +def test_main(): + test_support.run_unittest(StrTest) + +if __name__ == "__main__": + test_main() |