diff options
author | Vincent Legoll <vincent.legoll@idgrilles.fr> | 2016-05-13 14:24:29 +0200 |
---|---|---|
committer | Vincent Legoll <vincent.legoll@idgrilles.fr> | 2016-06-23 15:45:06 +0200 |
commit | 19dd49020aacc9f1325bc188855975c3345843d9 (patch) | |
tree | 80daf7d0c2ae7b0ca9d516225e73e25767212fac | |
parent | 60bc7d7a03499aa124cdb7826a09e042ed8e1828 (diff) | |
download | cliff-19dd49020aacc9f1325bc188855975c3345843d9.tar.gz |
Add tests, cover more cases
line 147 in _assign_max_widths() was not covered,
work around some pep8 error E501 line too long.
Change-Id: I3d90162c5913ee8cbb0809d6342d95b4bc62fae2
Signed-off-by: Vincent Legoll <vincent.legoll@idgrilles.fr>
-rw-r--r-- | cliff/tests/test_formatters_table.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cliff/tests/test_formatters_table.py b/cliff/tests/test_formatters_table.py index f28fffe..a9cd975 100644 --- a/cliff/tests/test_formatters_table.py +++ b/cliff/tests/test_formatters_table.py @@ -66,6 +66,7 @@ def test_table_formatter(tw): assert expected == _table_tester_helper(c, d) +# Multi-line output when width is restricted to 42 columns expected_ml_val = '''\ +-------+--------------------------------+ | Field | Value | @@ -79,6 +80,39 @@ expected_ml_val = '''\ +-------+--------------------------------+ ''' +# Multi-line output when width is restricted to 80 columns +expected_ml_80_val = '''\ ++-------+----------------------------------------------------------------------+ +| Field | Value | ++-------+----------------------------------------------------------------------+ +| a | A | +| b | B | +| c | C | +| d | dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd | +| | ddddddddd | ++-------+----------------------------------------------------------------------+ +''' # noqa + +# Single-line output, for when no line length restriction apply +expected_sl_val = '''\ ++-------+-------------------------------------------------------------------------------+ +| Field | Value | ++-------+-------------------------------------------------------------------------------+ +| a | A | +| b | B | +| c | C | +| d | ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd | ++-------+-------------------------------------------------------------------------------+ +''' # noqa + + +@mock.patch('cliff.utils.terminal_width') +def test_table_formatter_no_cli_param(tw): + tw.return_value = 80 + c = ('a', 'b', 'c', 'd') + d = ('A', 'B', 'C', 'd' * 77) + assert expected_ml_80_val == _table_tester_helper(c, d, extra_args=args()) + @mock.patch('cliff.utils.terminal_width') def test_table_formatter_cli_param(tw): @@ -90,6 +124,24 @@ def test_table_formatter_cli_param(tw): @mock.patch('cliff.utils.terminal_width') +def test_table_formatter_no_cli_param_unlimited_tw(tw): + tw.return_value = 0 + c = ('a', 'b', 'c', 'd') + d = ('A', 'B', 'C', 'd' * 77) + # output should not be wrapped to multiple lines + assert expected_sl_val == _table_tester_helper(c, d, extra_args=args()) + + +@mock.patch('cliff.utils.terminal_width') +def test_table_formatter_cli_param_unlimited_tw(tw): + tw.return_value = 0 + c = ('a', 'b', 'c', 'd') + d = ('A', 'B', 'C', 'd' * 77) + assert (expected_ml_val == + _table_tester_helper(c, d, extra_args=['--max-width', '42'])) + + +@mock.patch('cliff.utils.terminal_width') @mock.patch.dict(os.environ, {'CLIFF_MAX_TERM_WIDTH': '666'}) def test_table_formatter_cli_param_envvar_big(tw): tw.return_value = 80 |