diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-01-29 20:07:46 -0500 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-01-29 20:07:46 -0500 |
| commit | 434a01f44e7d2302b4deef8f2e8069cbc26df560 (patch) | |
| tree | cb3d5425668954fdd92989121ab53741c56908f8 /tests | |
| parent | 82fe1d473ca2fe0278568036659fa78cb3c17f78 (diff) | |
| parent | cd377071cd122bc92a829322e00ae43fd5a5c254 (diff) | |
| download | cmd2-git-434a01f44e7d2302b4deef8f2e8069cbc26df560.tar.gz | |
Merge branch 'master' into 2.0
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/test_history.py | 13 | ||||
| -rw-r--r-- | tests/test_table_creator.py | 46 |
2 files changed, 46 insertions, 13 deletions
diff --git a/tests/test_history.py b/tests/test_history.py index 29ca020a..49898a85 100755 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -521,7 +521,7 @@ def test_history_run_one_command(base_app): out2, err2 = run_cmd(base_app, 'history -r 1') assert out1 == out2 -def test_history_clear(hist_file): +def test_history_clear(mocker, hist_file): # Add commands to history app = cmd2.Cmd(persistent_history_file=hist_file) run_cmd(app, 'help') @@ -539,6 +539,17 @@ def test_history_clear(hist_file): assert out == [] assert not os.path.exists(hist_file) + # Clear the history again and make sure the FileNotFoundError from trying to delete missing history file is silent + run_cmd(app, 'history --clear') + + # Cause os.remove to fail and make sure error gets printed + mock_remove = mocker.patch('os.remove') + mock_remove.side_effect = OSError + + out, err = run_cmd(app, 'history --clear') + assert out == [] + assert 'Error removing history file' in err[0] + def test_history_verbose_with_other_options(base_app): # make sure -v shows a usage error if any other options are present options_to_test = ['-r', '-e', '-o file', '-t file', '-c', '-x'] diff --git a/tests/test_table_creator.py b/tests/test_table_creator.py index 58dd6fdf..649674a4 100644 --- a/tests/test_table_creator.py +++ b/tests/test_table_creator.py @@ -20,18 +20,6 @@ from cmd2.table_creator import ( def test_column_creation(): - # No width specified, blank label - c = Column("") - assert c.width == 1 - - # No width specified, label isn't blank but has no width - c = Column(ansi.style('', fg=ansi.fg.green)) - assert c.width == 1 - - # No width specified, label has width - c = Column("short\nreally long") - assert c.width == ansi.style_aware_wcswidth("really long") - # Width less than 1 with pytest.raises(ValueError) as excinfo: Column("Column 1", width=0) @@ -46,6 +34,36 @@ def test_column_creation(): Column("Column 1", max_data_lines=0) assert "Max data lines cannot be less than 1" in str(excinfo.value) + # No width specified, blank label + c = Column("") + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == 1 + + # No width specified, label isn't blank but has no width + c = Column(ansi.style('', fg=ansi.fg.green)) + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == 1 + + # No width specified, label has width + c = Column("a line") + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == ansi.style_aware_wcswidth("a line") + + # No width specified, label has width and multiple lines + c = Column("short\nreally long") + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == ansi.style_aware_wcswidth("really long") + + # No width specified, label has tabs + c = Column("line\twith\ttabs") + assert c.width is None + tc = TableCreator([c]) + assert tc.cols[0].width == ansi.style_aware_wcswidth("line with tabs") + def test_column_alignment(): column_1 = Column("Col 1", width=10, @@ -241,6 +259,10 @@ def test_tabs(): inter_cell='\t', post_line='\t') assert row == ' Col 1 Col 2 ' + with pytest.raises(ValueError) as excinfo: + TableCreator([column_1, column_2], tab_width=0) + assert "Tab width cannot be less than 1" in str(excinfo.value) + def test_simple_table_creation(): column_1 = Column("Col 1", width=16) |
