|
1 | 1 | """Test output of the various forms of tabular data.""" |
| 2 | +from pytest import mark |
2 | 3 |
|
3 | 4 | import tabulate as tabulate_module |
4 | 5 | from common import assert_equal, raises, skip, check_warnings |
@@ -2638,6 +2639,44 @@ def test_intfmt(): |
2638 | 2639 | assert_equal(expected, result) |
2639 | 2640 |
|
2640 | 2641 |
|
| 2642 | +def test_intfmt_with_string_as_integer(): |
| 2643 | + "Output: integer format" |
| 2644 | + result = tabulate([[82642], ["1500"], [2463]], intfmt=",", tablefmt="plain") |
| 2645 | + expected = "82,642\n 1500\n 2,463" |
| 2646 | + assert_equal(expected, result) |
| 2647 | + |
| 2648 | + |
| 2649 | +@mark.skip(reason="It detects all values as floats but there are strings and integers.") |
| 2650 | +def test_intfmt_with_string_with_floats(): |
| 2651 | + "Output: integer format" |
| 2652 | + result = tabulate([[82000.38], ["1500.47"], ["2463"], [92165]], intfmt=",", tablefmt="plain") |
| 2653 | + expected = "82000.4\n 1500.47\n 2463\n92,165" |
| 2654 | + assert_equal(expected, result) |
| 2655 | + |
| 2656 | + |
| 2657 | +def test_intfmt_with_colors(): |
| 2658 | + "Regression: Align ANSI-colored values as if they were colorless." |
| 2659 | + colortable = [ |
| 2660 | + ("\x1b[33mabc\x1b[0m", 42, "\x1b[31m42\x1b[0m"), |
| 2661 | + ("\x1b[35mdef\x1b[0m", 987654321, "\x1b[32m987654321\x1b[0m"), |
| 2662 | + ] |
| 2663 | + colorheaders = ("test", "\x1b[34mtest\x1b[0m", "test") |
| 2664 | + formatted = tabulate(colortable, colorheaders, "grid", intfmt=",") |
| 2665 | + expected = "\n".join( |
| 2666 | + [ |
| 2667 | + "+--------+-------------+-------------+", |
| 2668 | + "| test | \x1b[34mtest\x1b[0m | test |", |
| 2669 | + "+========+=============+=============+", |
| 2670 | + "| \x1b[33mabc\x1b[0m | 42 | \x1b[31m42\x1b[0m |", |
| 2671 | + "+--------+-------------+-------------+", |
| 2672 | + "| \x1b[35mdef\x1b[0m | 987,654,321 | \x1b[32m987,654,321\x1b[0m |", |
| 2673 | + "+--------+-------------+-------------+", |
| 2674 | + ] |
| 2675 | + ) |
| 2676 | + print(f"expected: {expected!r}\n\ngot: {formatted!r}\n") |
| 2677 | + assert_equal(expected, formatted) |
| 2678 | + |
| 2679 | + |
2641 | 2680 | def test_empty_data_with_headers(): |
2642 | 2681 | "Output: table with empty data and headers as firstrow" |
2643 | 2682 | expected = "" |
|
0 commit comments