File: test_str2unicode.py

package info (click to toggle)
jython 2.5.3-16%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,772 kB
  • ctags: 106,434
  • sloc: python: 351,322; java: 216,349; xml: 1,584; sh: 330; perl: 114; ansic: 102; makefile: 45
file content (90 lines) | stat: -rw-r--r-- 3,565 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import unittest


class TestStrReturnsUnicode(unittest.TestCase):

    def test_join(self):
        self.assertEquals(unicode, type(''.join([u'blah'])))

    def test_replace(self):
        self.assertEquals(unicode, type('hello'.replace('o', u'o')))

    def test_string_formatting_s(self):
        self.assertEquals(unicode, type('%s' % u'x'))
        self.assertEquals(unicode, type('%s %s' % (u'x', 'y')))
        self.assertEquals(unicode, type('%(x)s' % {'x' : u'x'}))

    def test_string_formatting_r(self):
        self.assertEquals(unicode, type('%r' % u'x'))
        self.assertEquals(unicode, type('%r %r' % (u'x', 'y')))
        self.assertEquals(unicode, type('%(x)r' % {'x' : u'x'}))

    def test_string_formatting_c(self):
        self.assertEquals(unicode, type('%c' % u'x'))
        self.assertEquals(unicode, type('%c %c' % (u'x', 'y')))
        self.assertEquals(unicode, type('%(x)c' % {'x' : u'x'}))


class TestStrReturnsStr(unittest.TestCase):

    def test_join(self):
        self.assertEquals(str, type(''.join(['blah'])))

    def test_replace(self):
        self.assertEquals(str, type('hello'.replace('o', 'oo')))

    def test_string_formatting_s(self):
        self.assertEquals(str, type('%s' % 'x'))
        self.assertEquals(str, type('%s %s' % ('x', 'y')))
        self.assertEquals(str, type('%(x)s' % {'x' : 'xxx'}))

    def test_string_formatting_r(self):
        self.assertEquals(str, type('%r' % 'x'))
        self.assertEquals(str, type('%r %r' % ('x', 'y')))
        self.assertEquals(str, type('%(x)r' % {'x' : 'x'}))

    def test_string_formatting_c(self):
        self.assertEquals(str, type('%c' % 'x'))
        self.assertEquals(str, type('%c %c' % ('x', 'y')))
        self.assertEquals(str, type('%(x)c' % {'x' : 'x'}))


class TestUnicodeReturnsUnicode(unittest.TestCase):

    def test_join(self):
        self.assertEquals(unicode, type(u''.join([u'blah'])))
        self.assertEquals(unicode, type(u''.join(['blah'])))

    def test_replace(self):
        self.assertEquals(unicode, type(u'hello'.replace('o', u'o')))
        self.assertEquals(unicode, type(u'hello'.replace(u'o', 'o')))
        self.assertEquals(unicode, type(u'hello'.replace(u'o', u'o')))
        self.assertEquals(unicode, type(u'hello'.replace('o', 'o')))

    def test_string_formatting_s(self):
        self.assertEquals(unicode, type(u'%s' % u'x'))
        self.assertEquals(unicode, type(u'%s' % 'x'))
        self.assertEquals(unicode, type(u'%s %s' % (u'x', 'y')))
        self.assertEquals(unicode, type(u'%s %s' % ('x', 'y')))
        self.assertEquals(unicode, type(u'%(x)s' % {'x' : u'x'}))
        self.assertEquals(unicode, type(u'%(x)s' % {'x' : 'x'}))

    def test_string_formatting_r(self):
        self.assertEquals(unicode, type(u'%r' % u'x'))
        self.assertEquals(unicode, type(u'%r' % 'x'))
        self.assertEquals(unicode, type(u'%r %r' % (u'x', 'y')))
        self.assertEquals(unicode, type(u'%r %r' % ('x', 'y')))
        self.assertEquals(unicode, type(u'%(x)r' % {'x' : u'x'}))
        self.assertEquals(unicode, type(u'%(x)r' % {'x' : 'x'}))

    def test_string_formatting_c(self):
        self.assertEquals(unicode, type(u'%c' % u'x'))
        self.assertEquals(unicode, type(u'%c' % 'x'))
        self.assertEquals(unicode, type(u'%c %c' % (u'x', 'y')))
        self.assertEquals(unicode, type(u'%c %c' % ('x', 'y')))
        self.assertEquals(unicode, type(u'%(x)c' % {'x' : u'x'}))
        self.assertEquals(unicode, type(u'%(x)c' % {'x' : 'x'}))


if __name__ == '__main__':
    unittest.main()