From e74ba5ee32f69d6aa3cedd3131bc6ed25ea6b8ec Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Tue, 10 Dec 2019 13:13:38 -0500 Subject: Took out rstrip() calls that are no longer neeeded --- cmd2/history.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd2/history.py b/cmd2/history.py index 576ac37d..3b18fbeb 100644 --- a/cmd2/history.py +++ b/cmd2/history.py @@ -45,14 +45,14 @@ class HistoryItem(): """ if verbose: raw = self.raw.rstrip() - expanded = self.expanded.rstrip() + expanded = self.expanded ret_str = self._listformat.format(self.idx, raw) if raw != expanded: ret_str += '\n' + self._ex_listformat.format(self.idx, expanded) else: if expanded: - ret_str = self.expanded.rstrip() + ret_str = self.expanded else: ret_str = self.raw.rstrip() -- cgit v1.2.1 From fb5f7a80ce50139ea99bbf6a0d8aa8df7c3db453 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Tue, 10 Dec 2019 14:31:46 -0500 Subject: Took out more rstrip() calls that are no longer neeeded --- cmd2/cmd2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 28a9dedb..6c4fdcbd 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3358,7 +3358,7 @@ class Cmd(cmd.Cmd): with os.fdopen(fd, 'w') as fobj: for command in history: if command.statement.multiline_command: - fobj.write('{}\n'.format(command.expanded.rstrip())) + fobj.write('{}\n'.format(command.expanded)) else: fobj.write('{}\n'.format(command.raw)) try: @@ -3372,7 +3372,7 @@ class Cmd(cmd.Cmd): with open(os.path.expanduser(args.output_file), 'w') as fobj: for item in history: if item.statement.multiline_command: - fobj.write('{}\n'.format(item.expanded.rstrip())) + fobj.write('{}\n'.format(item.expanded)) else: fobj.write('{}\n'.format(item.raw)) plural = 's' if len(history) > 1 else '' -- cgit v1.2.1 From bff8f7a4ef8b6cb8e160242b673ef30980e84fdb Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Tue, 10 Dec 2019 16:05:43 -0500 Subject: Increased code coverage --- tests/test_history.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/test_history.py b/tests/test_history.py index 4b900030..11f189f6 100755 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -447,15 +447,17 @@ def test_history_with_span_index_error(base_app): with pytest.raises(ValueError): base_app.onecmd('history "hal :"') -def test_history_output_file(base_app): - run_cmd(base_app, 'help') - run_cmd(base_app, 'shortcuts') - run_cmd(base_app, 'help history') +def test_history_output_file(): + app = cmd2.Cmd(multiline_commands=['alias']) + run_cmd(app, 'help') + run_cmd(app, 'shortcuts') + run_cmd(app, 'help history') + run_cmd(app, 'alias create my_alias history;') fd, fname = tempfile.mkstemp(prefix='', suffix='.txt') os.close(fd) - run_cmd(base_app, 'history -o "{}"'.format(fname)) - expected = normalize('\n'.join(['help', 'shortcuts', 'help history'])) + run_cmd(app, 'history -o "{}"'.format(fname)) + expected = normalize('\n'.join(['help', 'shortcuts', 'help history', 'alias create my_alias history;'])) with open(fname) as f: content = normalize(f.read()) assert content == expected @@ -471,10 +473,12 @@ def test_history_bad_output_file(base_app): assert not out assert "Error saving" in err[0] -def test_history_edit(base_app, monkeypatch): +def test_history_edit(monkeypatch): + app = cmd2.Cmd(multiline_commands=['alias']) + # Set a fake editor just to make sure we have one. We aren't really # going to call it due to the mock - base_app.editor = 'fooedit' + app.editor = 'fooedit' # Mock out the _run_editor call so we don't actually open an editor edit_mock = mock.MagicMock(name='_run_editor') @@ -484,9 +488,11 @@ def test_history_edit(base_app, monkeypatch): run_script_mock = mock.MagicMock(name='do_run_script') monkeypatch.setattr("cmd2.Cmd.do_run_script", run_script_mock) - # Run help command just so we have a command in history - run_cmd(base_app, 'help') - run_cmd(base_app, 'history -e 1') + # Put commands in history + run_cmd(app, 'help') + run_cmd(app, 'alias create my_alias history;') + + run_cmd(app, 'history -e 1:2') # Make sure both functions were called edit_mock.assert_called_once() -- cgit v1.2.1