/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-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

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