diff --git a/CHANGELOG.md b/CHANGELOG.md index 378fffcd..3f26178d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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()`. diff --git a/tests/test_history.py b/tests/test_history.py index ceaa9f83..99069802 100755 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -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): @@ -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