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>
This commit is contained in:
Vincent Legoll
2016-05-13 14:24:29 +02:00
parent 60bc7d7a03
commit 19dd49020a

View File

@@ -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):
@@ -89,6 +123,24 @@ def test_table_formatter_cli_param(tw):
_table_tester_helper(c, d, extra_args=['--max-width', '42']))
@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):