/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: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    tests,
22
22
    utextwrap,
23
23
    )
24
 
from . import features
25
24
 
26
25
 
27
26
# Japanese "Good morning".
34
33
_str_SD = _str_S + _str_D
35
34
_str_DS = _str_D + _str_S
36
35
 
 
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
 
79
80
class TestUTextFill(tests.TestCase):
80
81
 
81
82
    def test_fill_simple(self):
85
86
 
86
87
    def test_fill_with_breaks(self):
87
88
        # Demonstrate complicated case.
88
 
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D*2
 
89
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D * 2
89
90
        self.assertEqual(u'\n'.join(["spam ham",
90
91
                                     "egg spam",
91
92
                                     "hamegg" + _str_D[0],
92
93
                                     _str_D[1:],
93
94
                                     "spam" + _str_D[:2],
94
 
                                     _str_D[2:]+_str_D[:2],
 
95
                                     _str_D[2:] + _str_D[:2],
95
96
                                     _str_D[2:]]),
96
97
                         utextwrap.fill(text, 8))
97
98
 
98
99
    def test_fill_without_breaks(self):
99
 
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D*2
 
100
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D * 2
100
101
        self.assertEqual(u'\n'.join(["spam ham",
101
102
                                     "egg",
102
 
                                     "spamhamegg", 
 
103
                                     "spamhamegg",
103
104
                                     # border between single width and double
104
105
                                     # width.
105
106
                                     _str_D,
106
107
                                     "spam" + _str_D[:2],
107
 
                                     _str_D[2:]+_str_D[:2],
 
108
                                     _str_D[2:] + _str_D[:2],
108
109
                                     _str_D[2:]]),
109
110
                         utextwrap.fill(text, 8, break_long_words=False))
110
111
 
111
112
    def test_fill_indent_with_breaks(self):
112
 
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
113
 
                                   subsequent_indent=' '*4)
 
113
        w = utextwrap.UTextWrapper(8, initial_indent=' ' * 4,
 
114
                                   subsequent_indent=' ' * 4)
114
115
        self.assertEqual(u'\n'.join(["    hell",
115
116
                                     "    o" + _str_D[0],
116
117
                                     "    " + _str_D[1:3],
119
120
                         w.fill(_str_SD))
120
121
 
121
122
    def test_fill_indent_without_breaks(self):
122
 
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
123
 
                                   subsequent_indent=' '*4)
 
123
        w = utextwrap.UTextWrapper(8, initial_indent=' ' * 4,
 
124
                                   subsequent_indent=' ' * 4)
124
125
        w.break_long_words = False
125
126
        self.assertEqual(u'\n'.join(["    hello",
126
127
                                     "    " + _str_D[:2],
129
130
                         w.fill(_str_SD))
130
131
 
131
132
    def test_fill_indent_without_breaks_with_fixed_width(self):
132
 
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
133
 
                                   subsequent_indent=' '*4)
 
133
        w = utextwrap.UTextWrapper(8, initial_indent=' ' * 4,
 
134
                                   subsequent_indent=' ' * 4)
134
135
        w.break_long_words = False
135
136
        w.width = 3
136
137
        self.assertEqual(u'\n'.join(["    hello",
141
142
                                     ]),
142
143
                         w.fill(_str_SD))
143
144
 
 
145
 
144
146
class TestUTextWrapAmbiWidth(tests.TestCase):
145
 
    _cyrill_char = u"\u0410" # east_asian_width() == 'A'
 
147
    _cyrill_char = u"\u0410"  # east_asian_width() == 'A'
146
148
 
147
149
    def test_ambiwidth1(self):
148
150
        w = utextwrap.UTextWrapper(4, ambiguous_width=1)
149
 
        s = self._cyrill_char*8
150
 
        self.assertEqual([self._cyrill_char*4]*2, w.wrap(s))
 
151
        s = self._cyrill_char * 8
 
152
        self.assertEqual([self._cyrill_char * 4] * 2, w.wrap(s))
151
153
 
152
154
    def test_ambiwidth2(self):
153
155
        w = utextwrap.UTextWrapper(4, ambiguous_width=2)
154
 
        s = self._cyrill_char*8
155
 
        self.assertEqual([self._cyrill_char*2]*4, w.wrap(s))
 
156
        s = self._cyrill_char * 8
 
157
        self.assertEqual([self._cyrill_char * 2] * 4, w.wrap(s))
156
158
 
157
159
 
158
160
# Regression test with Python's test_textwrap
169
171
        testcase.overrideAttr(test_textwrap, 'wrap', utextwrap.wrap)
170
172
        testcase.overrideAttr(test_textwrap, 'fill', utextwrap.fill)
171
173
 
172
 
 
173
174
    def setup_both(testcase, base_class, reused_class):
174
175
        super(base_class, testcase).setUp()
175
176
        override_textwrap_symbols(testcase)
176
177
        reused_class.setUp(testcase)
177
178
 
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
 
 
185
184
    class TestLongWord(tests.TestCase, test_textwrap.LongWordTestCase):
186
185
 
187
186
        def setUp(self):
188
187
            setup_both(self, TestLongWord, test_textwrap.LongWordTestCase)
189
188
 
190
 
 
191
189
    class TestIndent(tests.TestCase, test_textwrap.IndentTestCases):
192
190
 
193
191
        def setUp(self):