Skip to content

Commit

Permalink
Increased code coverage in history tests and updated change log.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Sep 16, 2024
1 parent 3351655 commit e87d1ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* add `allow_clipboard` initialization parameter and attribute to disable ability to
add output to the operating system clipboard
* Updated unit tests to be Python 3.12 compliant.
* Fall back to bz2 compression of history file when lzma is not installed.
* Deletions (potentially breaking changes)
* Removed `apply_style` from `Cmd.pwarning()`.

Expand Down
31 changes: 29 additions & 2 deletions tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,34 @@ def test_history_file_permission_error(mocker, capsys):
cmd2.Cmd(persistent_history_file='/tmp/doesntmatter')
out, err = capsys.readouterr()
assert not out
assert 'Cannot read' in err
assert 'Cannot read persistent history file' in err


def test_history_file_bad_compression(mocker, capsys):
history_file = '/tmp/doesntmatter'
with open(history_file, "wb") as f:
f.write(b"THIS IS NOT COMPRESSED DATA")

cmd2.Cmd(persistent_history_file=history_file)
out, err = capsys.readouterr()
assert not out
assert 'Error decompressing persistent history data' in err


def test_history_file_bad_json(mocker, capsys):
import lzma

data = b"THIS IS NOT JSON"
compressed_data = lzma.compress(data)

history_file = '/tmp/doesntmatter'
with open(history_file, "wb") as f:
f.write(compressed_data)

cmd2.Cmd(persistent_history_file=history_file)
out, err = capsys.readouterr()
assert not out
assert 'Error processing persistent history data' in err


def test_history_populates_readline(hist_file):
Expand Down Expand Up @@ -960,4 +987,4 @@ def test_persist_history_permission_error(hist_file, mocker, capsys):
app._persist_history()
out, err = capsys.readouterr()
assert not out
assert 'Cannot write' in err
assert 'Cannot write persistent history file' in err

0 comments on commit e87d1ca

Please sign in to comment.