Skip to content

Commit e13fc34

Browse files
authored
Merge pull request #832 from python-cmd2/rstrip
Took out rstrip() calls that are no longer neeeded
2 parents 1cb8de9 + 42ee1cb commit e13fc34

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,7 +3358,7 @@ def do_history(self, args: argparse.Namespace) -> Optional[bool]:
33583358
with os.fdopen(fd, 'w') as fobj:
33593359
for command in history:
33603360
if command.statement.multiline_command:
3361-
fobj.write('{}\n'.format(command.expanded.rstrip()))
3361+
fobj.write('{}\n'.format(command.expanded))
33623362
else:
33633363
fobj.write('{}\n'.format(command.raw))
33643364
try:
@@ -3372,7 +3372,7 @@ def do_history(self, args: argparse.Namespace) -> Optional[bool]:
33723372
with open(os.path.expanduser(args.output_file), 'w') as fobj:
33733373
for item in history:
33743374
if item.statement.multiline_command:
3375-
fobj.write('{}\n'.format(item.expanded.rstrip()))
3375+
fobj.write('{}\n'.format(item.expanded))
33763376
else:
33773377
fobj.write('{}\n'.format(item.raw))
33783378
plural = 's' if len(history) > 1 else ''

cmd2/history.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ def pr(self, script=False, expanded=False, verbose=False) -> str:
4545
"""
4646
if verbose:
4747
raw = self.raw.rstrip()
48-
expanded = self.expanded.rstrip()
48+
expanded = self.expanded
4949

5050
ret_str = self._listformat.format(self.idx, raw)
5151
if raw != expanded:
5252
ret_str += '\n' + self._ex_listformat.format(self.idx, expanded)
5353
else:
5454
if expanded:
55-
ret_str = self.expanded.rstrip()
55+
ret_str = self.expanded
5656
else:
5757
ret_str = self.raw.rstrip()
5858

tests/test_history.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,17 @@ def test_history_with_span_index_error(base_app):
447447
with pytest.raises(ValueError):
448448
base_app.onecmd('history "hal :"')
449449

450-
def test_history_output_file(base_app):
451-
run_cmd(base_app, 'help')
452-
run_cmd(base_app, 'shortcuts')
453-
run_cmd(base_app, 'help history')
450+
def test_history_output_file():
451+
app = cmd2.Cmd(multiline_commands=['alias'])
452+
run_cmd(app, 'help')
453+
run_cmd(app, 'shortcuts')
454+
run_cmd(app, 'help history')
455+
run_cmd(app, 'alias create my_alias history;')
454456

455457
fd, fname = tempfile.mkstemp(prefix='', suffix='.txt')
456458
os.close(fd)
457-
run_cmd(base_app, 'history -o "{}"'.format(fname))
458-
expected = normalize('\n'.join(['help', 'shortcuts', 'help history']))
459+
run_cmd(app, 'history -o "{}"'.format(fname))
460+
expected = normalize('\n'.join(['help', 'shortcuts', 'help history', 'alias create my_alias history;']))
459461
with open(fname) as f:
460462
content = normalize(f.read())
461463
assert content == expected
@@ -471,10 +473,12 @@ def test_history_bad_output_file(base_app):
471473
assert not out
472474
assert "Error saving" in err[0]
473475

474-
def test_history_edit(base_app, monkeypatch):
476+
def test_history_edit(monkeypatch):
477+
app = cmd2.Cmd(multiline_commands=['alias'])
478+
475479
# Set a fake editor just to make sure we have one. We aren't really
476480
# going to call it due to the mock
477-
base_app.editor = 'fooedit'
481+
app.editor = 'fooedit'
478482

479483
# Mock out the _run_editor call so we don't actually open an editor
480484
edit_mock = mock.MagicMock(name='_run_editor')
@@ -484,9 +488,11 @@ def test_history_edit(base_app, monkeypatch):
484488
run_script_mock = mock.MagicMock(name='do_run_script')
485489
monkeypatch.setattr("cmd2.Cmd.do_run_script", run_script_mock)
486490

487-
# Run help command just so we have a command in history
488-
run_cmd(base_app, 'help')
489-
run_cmd(base_app, 'history -e 1')
491+
# Put commands in history
492+
run_cmd(app, 'help')
493+
run_cmd(app, 'alias create my_alias history;')
494+
495+
run_cmd(app, 'history -e 1:2')
490496

491497
# Make sure both functions were called
492498
edit_mock.assert_called_once()

0 commit comments

Comments
 (0)