def test_wrap_text_wide_chars(): "Internal: Wrap wide characters based on column width" try: import wcwidth # noqa except ImportError: skip("test_wrap_text_wide_chars is skipped") rows = [["청자청자청자청자청자", "약간 감싸면 더 잘 보일 수있는 다소 긴 설명입니다"]] widths = [5, 20] expected = [["청자\n청자\n청자\n청자\n청자", "약간 감싸면 더 잘\n보일 수있는 다소 긴\n설명입니다"]] result = T._wrap_text_to_colwidths(rows, widths) assert_equal(result, expected)
def test_wrap_text_to_colwidths_multi_ansi_colors_in_subset(): """Internal: autowrapped text can retain multiple ANSI colors when they are around subsets of the cell""" data = [[("This is a rather \033[31mlong description\033[0m that" " might look better \033[93mif it is wrapped\033[0m a bit")]] result = T._wrap_text_to_colwidths(data, [30]) expected = [[ "\n".join([ "This is a rather \033[31mlong\033[0m", "\033[31mdescription\033[0m that might look", "better \033[93mif it is wrapped\033[0m a bit", ]) ]] assert_equal(expected, result)
def test_wrap_text_to_colwidths_single_ansi_colors_full_cell(): """Internal: autowrapped text can retain a single ANSI colors when it is at the beginning and end of full cell""" data = [[("\033[31mThis is a rather long description that might" " look better if it is wrapped a bit\033[0m")]] result = T._wrap_text_to_colwidths(data, [30]) expected = [[ "\n".join([ "\033[31mThis is a rather long\033[0m", "\033[31mdescription that might look\033[0m", "\033[31mbetter if it is wrapped a bit\033[0m", ]) ]] assert_equal(expected, result)
def test_wrap_text_to_colwidths_multi_ansi_colors_full_cell(): """Internal: autowrapped text can retain multiple ANSI colors when they are at the beginning and end of full cell (e.g. text and background colors)""" data = [[("\033[31m\033[43mThis is a rather long description that" " might look better if it is wrapped a bit\033[0m")]] result = T._wrap_text_to_colwidths(data, [30]) expected = [[ "\n".join([ "\033[31m\033[43mThis is a rather long\033[0m", "\033[31m\033[43mdescription that might look\033[0m", "\033[31m\033[43mbetter if it is wrapped a bit\033[0m", ]) ]] assert_equal(expected, result)
def test_wrap_text_to_numbers(): """Internal: Test _wrap_text_to_colwidths force ignores numbers by default so as not to break alignment behaviors""" rows = [ ["first number", 123.456789, "123.456789"], ["second number", "987654.123", "987654.123"], ] widths = [6, 6, 6] expected = [ ["first\nnumber", 123.456789, "123.45\n6789"], ["second\nnumber", "987654.123", "987654\n.123"], ] result = T._wrap_text_to_colwidths(rows, widths, numparses=[True, True, False]) assert_equal(result, expected)
def test_wrap_text_to_colwidths_colors_wide_char(): """Internal: autowrapped text can retain a ANSI colors with wide chars""" try: import wcwidth # noqa except ImportError: skip("test_wrap_text_to_colwidths_colors_wide_char is skipped") data = [[("\033[31m약간 감싸면 더 잘 보일 수있는 다소 긴" " 설명입니다 설명입니다 설명입니다 설명입니다 설명\033[0m")]] result = T._wrap_text_to_colwidths(data, [30]) expected = [[ "\n".join([ "\033[31m약간 감싸면 더 잘 보일 수있는\033[0m", "\033[31m다소 긴 설명입니다 설명입니다\033[0m", "\033[31m설명입니다 설명입니다 설명\033[0m", ]) ]] assert_equal(expected, result)
def test_wrap_text_to_colwidths(): "Internal: Test _wrap_text_to_colwidths to show it will wrap text based on colwidths" rows = [ ["mini", "medium", "decently long", "wrap will be ignored"], [ "small", "JustOneWordThatIsWayTooLong", "this is unreasonably long for a single cell length", "also ignored here", ], ] widths = [10, 10, 20, None] expected = [ ["mini", "medium", "decently long", "wrap will be ignored"], [ "small", "JustOneWor\ndThatIsWay\nTooLong", "this is unreasonably\nlong for a single\ncell length", "also ignored here", ], ] result = T._wrap_text_to_colwidths(rows, widths) assert_equal(result, expected)