/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_utextwrap.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    tests,
22
22
    utextwrap,
23
23
    )
 
24
from . import features
24
25
 
25
26
 
26
27
# Japanese "Good morning".
33
34
_str_SD = _str_S + _str_D
34
35
_str_DS = _str_D + _str_S
35
36
 
36
 
 
37
37
class TestUTextWrap(tests.TestCase):
38
38
 
39
39
    def check_width(self, text, expected_width):
40
40
        w = utextwrap.UTextWrapper()
41
41
        self.assertEqual(
42
 
            w._width(text),
43
 
            expected_width,
44
 
            "Width of %r should be %d" % (text, expected_width))
 
42
                w._width(text),
 
43
                expected_width,
 
44
                "Width of %r should be %d" % (text, expected_width))
45
45
 
46
46
    def test_width(self):
47
47
        self.check_width(_str_D, 8)
61
61
        self.check_cut(s, 12, 8)
62
62
        self.check_cut(s, 13, 9)
63
63
        self.check_cut(s, 14, 9)
64
 
        self.check_cut(u'A' * 5, 3, 3)
 
64
        self.check_cut(u'A'*5, 3, 3)
65
65
 
66
66
    def test_split(self):
67
67
        w = utextwrap.UTextWrapper()
68
68
        self.assertEqual(list(_str_D), w._split(_str_D))
69
 
        self.assertEqual([_str_S] + list(_str_D), w._split(_str_SD))
70
 
        self.assertEqual(list(_str_D) + [_str_S], w._split(_str_DS))
 
69
        self.assertEqual([_str_S]+list(_str_D), w._split(_str_SD))
 
70
        self.assertEqual(list(_str_D)+[_str_S], w._split(_str_DS))
71
71
 
72
72
    def test_wrap(self):
73
73
        self.assertEqual(list(_str_D), utextwrap.wrap(_str_D, 1))
76
76
        self.assertEqual(list(_str_D),
77
77
                         utextwrap.wrap(_str_D, 3, break_long_words=False))
78
78
 
79
 
 
80
79
class TestUTextFill(tests.TestCase):
81
80
 
82
81
    def test_fill_simple(self):
86
85
 
87
86
    def test_fill_with_breaks(self):
88
87
        # Demonstrate complicated case.
89
 
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D * 2
 
88
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D*2
90
89
        self.assertEqual(u'\n'.join(["spam ham",
91
90
                                     "egg spam",
92
91
                                     "hamegg" + _str_D[0],
93
92
                                     _str_D[1:],
94
93
                                     "spam" + _str_D[:2],
95
 
                                     _str_D[2:] + _str_D[:2],
 
94
                                     _str_D[2:]+_str_D[:2],
96
95
                                     _str_D[2:]]),
97
96
                         utextwrap.fill(text, 8))
98
97
 
99
98
    def test_fill_without_breaks(self):
100
 
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D * 2
 
99
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D*2
101
100
        self.assertEqual(u'\n'.join(["spam ham",
102
101
                                     "egg",
103
 
                                     "spamhamegg",
 
102
                                     "spamhamegg", 
104
103
                                     # border between single width and double
105
104
                                     # width.
106
105
                                     _str_D,
107
106
                                     "spam" + _str_D[:2],
108
 
                                     _str_D[2:] + _str_D[:2],
 
107
                                     _str_D[2:]+_str_D[:2],
109
108
                                     _str_D[2:]]),
110
109
                         utextwrap.fill(text, 8, break_long_words=False))
111
110
 
112
111
    def test_fill_indent_with_breaks(self):
113
 
        w = utextwrap.UTextWrapper(8, initial_indent=' ' * 4,
114
 
                                   subsequent_indent=' ' * 4)
 
112
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
 
113
                                   subsequent_indent=' '*4)
115
114
        self.assertEqual(u'\n'.join(["    hell",
116
115
                                     "    o" + _str_D[0],
117
116
                                     "    " + _str_D[1:3],
120
119
                         w.fill(_str_SD))
121
120
 
122
121
    def test_fill_indent_without_breaks(self):
123
 
        w = utextwrap.UTextWrapper(8, initial_indent=' ' * 4,
124
 
                                   subsequent_indent=' ' * 4)
 
122
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
 
123
                                   subsequent_indent=' '*4)
125
124
        w.break_long_words = False
126
125
        self.assertEqual(u'\n'.join(["    hello",
127
126
                                     "    " + _str_D[:2],
130
129
                         w.fill(_str_SD))
131
130
 
132
131
    def test_fill_indent_without_breaks_with_fixed_width(self):
133
 
        w = utextwrap.UTextWrapper(8, initial_indent=' ' * 4,
134
 
                                   subsequent_indent=' ' * 4)
 
132
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
 
133
                                   subsequent_indent=' '*4)
135
134
        w.break_long_words = False
136
135
        w.width = 3
137
136
        self.assertEqual(u'\n'.join(["    hello",
142
141
                                     ]),
143
142
                         w.fill(_str_SD))
144
143
 
145
 
 
146
144
class TestUTextWrapAmbiWidth(tests.TestCase):
147
 
    _cyrill_char = u"\u0410"  # east_asian_width() == 'A'
 
145
    _cyrill_char = u"\u0410" # east_asian_width() == 'A'
148
146
 
149
147
    def test_ambiwidth1(self):
150
148
        w = utextwrap.UTextWrapper(4, ambiguous_width=1)
151
 
        s = self._cyrill_char * 8
152
 
        self.assertEqual([self._cyrill_char * 4] * 2, w.wrap(s))
 
149
        s = self._cyrill_char*8
 
150
        self.assertEqual([self._cyrill_char*4]*2, w.wrap(s))
153
151
 
154
152
    def test_ambiwidth2(self):
155
153
        w = utextwrap.UTextWrapper(4, ambiguous_width=2)
156
 
        s = self._cyrill_char * 8
157
 
        self.assertEqual([self._cyrill_char * 2] * 4, w.wrap(s))
 
154
        s = self._cyrill_char*8
 
155
        self.assertEqual([self._cyrill_char*2]*4, w.wrap(s))
158
156
 
159
157
 
160
158
# Regression test with Python's test_textwrap
171
169
        testcase.overrideAttr(test_textwrap, 'wrap', utextwrap.wrap)
172
170
        testcase.overrideAttr(test_textwrap, 'fill', utextwrap.fill)
173
171
 
 
172
 
174
173
    def setup_both(testcase, base_class, reused_class):
175
174
        super(base_class, testcase).setUp()
176
175
        override_textwrap_symbols(testcase)
177
176
        reused_class.setUp(testcase)
178
177
 
 
178
 
179
179
    class TestWrap(tests.TestCase, test_textwrap.WrapTestCase):
180
180
 
181
181
        def setUp(self):
182
182
            setup_both(self, TestWrap, test_textwrap.WrapTestCase)
183
183
 
 
184
 
184
185
    class TestLongWord(tests.TestCase, test_textwrap.LongWordTestCase):
185
186
 
186
187
        def setUp(self):
187
188
            setup_both(self, TestLongWord, test_textwrap.LongWordTestCase)
188
189
 
 
190
 
189
191
    class TestIndent(tests.TestCase, test_textwrap.IndentTestCases):
190
192
 
191
193
        def setUp(self):