Lines Matching refs:self
19 def show(self, textin):
30 def check(self, result, expect):
31 self.assertEqual(result, expect,
33 self.show(expect), self.show(result)))
35 def check_wrap(self, text, width, expect, **kwargs):
37 self.check(result, expect)
39 def check_split(self, text, expect):
40 result = self.wrapper._split(text)
41 self.assertEqual(result, expect,
48 def setUp(self):
49 self.wrapper = TextWrapper(width=45)
51 def test_simple(self):
56 self.check_wrap(text, 12,
63 self.check_wrap(text, 42,
66 self.check_wrap(text, 80, [text])
68 def test_empty_string(self):
70 self.check_wrap("", 6, [])
71 self.check_wrap("", 6, [], drop_whitespace=False)
73 def test_empty_string_with_initial_indent(self):
75 self.check_wrap("", 6, [], initial_indent="++")
76 self.check_wrap("", 6, [], initial_indent="++", drop_whitespace=False)
78 def test_whitespace(self):
97 self.check(result, expect)
100 self.check(result, '\n'.join(expect))
104 self.check_wrap(text, 80, expect)
108 self.check_wrap(text, 80, expect, tabsize=4)
110 def test_fix_sentence_endings(self):
118 self.check(wrapper.wrap(text), expect)
125 self.check(wrapper.wrap(text), expect)
128 self.check(wrapper.wrap(text), expect)
132 self.check(wrapper.wrap(text), expect)
136 self.check(wrapper.wrap(text), expect)
142 self.check(wrapper.wrap(text), expect)
146 self.check(wrapper.wrap(text), expect)
150 self.check(wrapper.wrap(text), expect)
152 def test_wrap_short(self):
157 self.check_wrap(text, 20, ["This is a short",
159 self.check_wrap(text, 40, ["This is a short paragraph."])
162 def test_wrap_short_1line(self):
167 self.check_wrap(text, 30, ["This is a short line."])
168 self.check_wrap(text, 30, ["(1) This is a short line."],
172 def test_hyphenated(self):
178 self.check_wrap(text, 40,
181 self.check_wrap(text, 41,
184 self.check_wrap(text, 42,
190 self.check_wrap(text, 1, expect, break_long_words=False)
191 self.check_split(text, expect)
193 self.check_split('e-mail', ['e-mail'])
194 self.check_split('Jelly-O', ['Jelly-O'])
196 self.check_split('half-a-crown', 'half-|a-|crown'.split('|'))
198 def test_hyphenated_numbers(self):
203 self.check_wrap(text, 30, ['Python 1.0.0 was released on',
206 self.check_wrap(text, 40, ['Python 1.0.0 was released on 1994-01-26.',
208 self.check_wrap(text, 1, text.split(), break_long_words=False)
211 self.check_wrap(text, 25, ["I do all my shopping at",
213 self.check_wrap(text, 27, ["I do all my shopping at",
215 self.check_wrap(text, 29, ["I do all my shopping at 7-11."])
216 self.check_wrap(text, 1, text.split(), break_long_words=False)
218 def test_em_dash(self):
221 self.check_wrap(text, 25,
227 self.check_wrap(text, 29,
232 self.check_wrap(text, 30, expect)
233 self.check_wrap(text, 35, expect)
234 self.check_wrap(text, 36,
243 self.check_wrap(text, 15, expect)
244 self.check_wrap(text, 16, expect)
248 self.check_wrap(text, 17, expect)
249 self.check_wrap(text, 19, expect)
252 self.check_wrap(text, 29, expect)
253 self.check_wrap(text, 31, expect)
256 self.check_wrap(text, 32, expect)
257 self.check_wrap(text, 35, expect)
265 self.check_split(text, expect)
270 self.check_split(text, expect)
273 def test_unix_options (self):
278 self.check_wrap(text, 20,
283 self.check_wrap(text, 21,
289 self.check_wrap(text, 32, expect)
290 self.check_wrap(text, 34, expect)
291 self.check_wrap(text, 35, expect)
292 self.check_wrap(text, 38, expect)
295 self.check_wrap(text, 39, expect)
296 self.check_wrap(text, 41, expect)
299 self.check_wrap(text, 42, expect)
305 self.check_split(text, expect)
307 def test_funky_hyphens (self):
310 self.check_split("what the--hey!", ["what", " ", "the", "--", "hey!"])
311 self.check_split("what the--", ["what", " ", "the--"])
312 self.check_split("what the--.", ["what", " ", "the--."])
313 self.check_split("--text--.", ["--text--."])
319 self.check_split("--option", ["--option"])
320 self.check_split("--option-opt", ["--option-", "opt"])
321 self.check_split("foo --option-opt bar",
324 def test_punct_hyphens(self):
332 self.check_split("the 'wibble-wobble' widget",
334 self.check_split('the "wibble-wobble" widget',
336 self.check_split("the (wibble-wobble) widget",
338 self.check_split("the ['wibble-wobble'] widget",
342 self.check_split("what-d'you-call-it.",
345 def test_funky_parens (self):
348 self.check_split("foo (--option) bar",
352 self.check_split("foo (bar) baz",
354 self.check_split("blah (ding dong), wubba",
358 def test_drop_whitespace_false(self):
362 self.check_wrap(text, 10,
367 def test_drop_whitespace_false_whitespace_only(self):
369 self.check_wrap(" ", 6, [" "], drop_whitespace=False)
371 def test_drop_whitespace_false_whitespace_only_with_indent(self):
374 self.check_wrap(" ", 6, [" "], drop_whitespace=False,
377 def test_drop_whitespace_whitespace_only(self):
379 self.check_wrap(" ", 6, [])
381 def test_drop_whitespace_leading_whitespace(self):
387 self.check_wrap(text, 50,
389 self.check_wrap(text, 30,
392 def test_drop_whitespace_whitespace_line(self):
397 self.check_wrap(text, 6, ["abcd", " ", "efgh"],
399 self.check_wrap(text, 6, ["abcd", "efgh"])
401 def test_drop_whitespace_whitespace_only_with_indent(self):
405 self.check_wrap(" ", 6, [], initial_indent="++")
407 def test_drop_whitespace_whitespace_indent(self):
411 self.check_wrap("abcd efgh", 6, [" abcd", " efgh"],
414 def test_split(self):
420 result = self.wrapper._split(text)
421 self.check(result,
425 def test_break_on_hyphens(self):
428 self.check_wrap(text, 10, ["yaba daba-", "doo"],
430 self.check_wrap(text, 10, ["yaba", "daba-doo"],
433 def test_bad_width(self):
436 self.assertRaises(ValueError, wrap, text, 0)
437 self.assertRaises(ValueError, wrap, text, -1)
439 def test_no_split_at_umlaut(self):
441 self.check_wrap(text, 13, ["Die", "Empf\xe4nger-", "Auswahl"])
443 def test_umlaut_followed_by_dash(self):
445 self.check_wrap(text, 7, ["aa \xe4\xe4-", "\xe4\xe4"])
447 def test_non_breaking_space(self):
450 self.check_wrap(text, 20,
456 self.check_wrap(text, 20,
462 def test_narrow_non_breaking_space(self):
466 self.check_wrap(text, 20,
472 self.check_wrap(text, 20,
482 def test_simple(self):
483 self.check_wrap(self.text, 12,
486 self.check_wrap(self.text, 12,
489 self.check_wrap(self.text, 12,
493 self.check_wrap(self.text, 13,
497 self.check_wrap(self.text, 80, [self.text], max_lines=1)
498 self.check_wrap(self.text, 12,
507 def test_spaces(self):
509 self.check_wrap(self.text, 12,
516 self.check_wrap(self.text, 6,
521 self.check_wrap(self.text + ' ' * 10, 12,
530 def test_placeholder(self):
531 self.check_wrap(self.text, 12,
535 self.check_wrap(self.text, 12,
541 with self.assertRaises(ValueError):
542 wrap(self.text, 16, initial_indent=' ',
544 with self.assertRaises(ValueError):
545 wrap(self.text, 16, subsequent_indent=' ',
547 self.check_wrap(self.text, 16,
554 self.check_wrap(self.text, 16,
560 self.check_wrap(self.text, 80, [self.text], placeholder='.' * 1000)
562 def test_placeholder_backtrack(self):
568 self.check_wrap(text, 12,
575 def setUp(self):
576 self.wrapper = TextWrapper()
577 self.text = '''\
582 def test_break_long(self):
585 self.check_wrap(self.text, 30,
590 self.check_wrap(self.text, 50,
596 self.check_wrap('-'*10+'hello', 10,
607 self.check_wrap(self.text, 12,
618 def test_nobreak_long(self):
620 self.wrapper.break_long_words = 0
621 self.wrapper.width = 30
627 result = self.wrapper.wrap(self.text)
628 self.check(result, expect)
631 result = wrap(self.text, width=30, break_long_words=0)
632 self.check(result, expect)
634 def test_max_lines_long(self):
635 self.check_wrap(self.text, 12,
644 def setUp(self):
645 self.wrapper = TextWrapper()
646 self.text1 = '''\
649 self.text2 = '''\
653 def test_break_long_words_on_hyphen(self):
656 self.check_wrap(self.text1, 50, expected)
660 self.check_wrap(self.text1, 10, expected)
664 self.check_wrap(self.text2, 10, expected)
666 def test_break_long_words_not_on_hyphen(self):
669 self.check_wrap(self.text1, 50, expected, break_on_hyphens=False)
673 self.check_wrap(self.text1, 10, expected, break_on_hyphens=False)
677 self.check_wrap(self.text2, 10, expected)
679 def test_break_on_hyphen_but_not_long_words(self):
684 self.check_wrap(self.text1, 50, expected, break_long_words=False)
689 self.check_wrap(self.text1, 10, expected, break_long_words=False)
693 self.check_wrap(self.text2, 10, expected)
696 def test_do_not_break_long_words_or_on_hyphens(self):
700 self.check_wrap(self.text1, 50, expected,
707 self.check_wrap(self.text1, 10, expected,
713 self.check_wrap(self.text2, 10, expected)
718 def setUp(self):
719 self.text = '''\
724 def test_fill(self):
732 result = fill(self.text, 40)
733 self.check(result, expect)
736 def test_initial_indent(self):
742 result = wrap(self.text, 40, initial_indent=" ")
743 self.check(result, expect)
746 result = fill(self.text, 40, initial_indent=" ")
747 self.check(result, expect)
750 def test_subsequent_indent(self):
759 result = fill(self.text, 40,
761 self.check(result, expect)
768 def assertUnchanged(self, text):
770 self.assertEqual(text, dedent(text))
772 def test_dedent_nomargin(self):
775 self.assertUnchanged(text)
779 self.assertUnchanged(text)
783 self.assertUnchanged(text)
787 self.assertUnchanged(text)
789 def test_dedent_even(self):
793 self.assertEqual(expect, dedent(text))
798 self.assertEqual(expect, dedent(text))
803 self.assertEqual(expect, dedent(text))
805 def test_dedent_uneven(self):
817 self.assertEqual(expect, dedent(text))
822 self.assertEqual(expect, dedent(text))
827 self.assertEqual(expect, dedent(text))
829 def test_dedent_declining(self):
833 self.assertEqual(expect, dedent(text))
838 self.assertEqual(expect, dedent(text))
843 self.assertEqual(expect, dedent(text))
846 def test_dedent_preserve_internal_tabs(self):
849 self.assertEqual(expect, dedent(text))
853 self.assertEqual(expect, dedent(expect))
858 def test_dedent_preserve_margin_tabs(self):
860 self.assertUnchanged(text)
864 self.assertUnchanged(text)
869 self.assertEqual(expect, dedent(text))
872 self.assertEqual(expect, dedent(text))
875 self.assertEqual(expect, dedent(text))
879 self.assertEqual(expect, dedent(text))
884 self.assertEqual(expect, dedent(text))
908 def test_indent_nomargin_default(self):
910 for text in self.CASES:
911 self.assertEqual(indent(text, ''), text)
913 def test_indent_nomargin_explicit_default(self):
916 for text in self.CASES:
917 self.assertEqual(indent(text, '', None), text)
919 def test_indent_nomargin_all_lines(self):
923 for text in self.CASES:
924 self.assertEqual(indent(text, '', predicate), text)
926 def test_indent_no_lines(self):
929 for text in self.CASES:
930 self.assertEqual(indent(text, ' ', predicate), text)
932 def test_roundtrip_spaces(self):
934 for text in self.ROUNDTRIP_CASES:
935 self.assertEqual(dedent(indent(text, ' ')), text)
937 def test_roundtrip_tabs(self):
939 for text in self.ROUNDTRIP_CASES:
940 self.assertEqual(dedent(indent(text, '\t\t')), text)
942 def test_roundtrip_mixed(self):
944 for text in self.ROUNDTRIP_CASES:
945 self.assertEqual(dedent(indent(text, ' \t \t ')), text)
947 def test_indent_default(self):
962 for text, expect in zip(self.CASES, expected):
963 self.assertEqual(indent(text, prefix), expect)
965 def test_indent_explicit_default(self):
980 for text, expect in zip(self.CASES, expected):
981 self.assertEqual(indent(text, prefix, None), expect)
983 def test_indent_all_lines(self):
999 for text, expect in zip(self.CASES, expected):
1000 self.assertEqual(indent(text, prefix, predicate), expect)
1002 def test_indent_empty_lines(self):
1018 for text, expect in zip(self.CASES, expected):
1019 self.assertEqual(indent(text, prefix, predicate), expect)
1024 def check_shorten(self, text, width, expect, **kwargs):
1026 self.check(result, expect)
1028 def test_simple(self):
1032 self.check_shorten(text, 18, "Hello there, [...]")
1033 self.check_shorten(text, len(text), text)
1034 self.check_shorten(text, len(text) - 1,
1038 def test_placeholder(self):
1041 self.check_shorten(text, 17, "Hello there,$$", placeholder='$$')
1042 self.check_shorten(text, 18, "Hello there, how$$", placeholder='$$')
1043 self.check_shorten(text, 18, "Hello there, $$", placeholder=' $$')
1044 self.check_shorten(text, len(text), text, placeholder='$$')
1045 self.check_shorten(text, len(text) - 1,
1049 def test_empty_string(self):
1050 self.check_shorten("", 6, "")
1052 def test_whitespace(self):
1057 self.check_shorten(text, 62,
1060 self.check_shorten(text, 61,
1064 self.check_shorten("hello world! ", 12, "hello world!")
1065 self.check_shorten("hello world! ", 11, "hello [...]")
1068 self.check_shorten("hello world! ", 10, "[...]")
1070 def test_width_too_small_for_placeholder(self):
1072 with self.assertRaises(ValueError):
1075 def test_first_word_too_long_but_placeholder_fits(self):
1076 self.check_shorten("Helloo", 5, "[...]")