Skip to content

Commit e87d1ca

Browse files
committed
Increased code coverage in history tests and updated change log.
1 parent 3351655 commit e87d1ca

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* add `allow_clipboard` initialization parameter and attribute to disable ability to
99
add output to the operating system clipboard
1010
* Updated unit tests to be Python 3.12 compliant.
11+
* Fall back to bz2 compression of history file when lzma is not installed.
1112
* Deletions (potentially breaking changes)
1213
* Removed `apply_style` from `Cmd.pwarning()`.
1314

tests/test_history.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,34 @@ def test_history_file_permission_error(mocker, capsys):
903903
cmd2.Cmd(persistent_history_file='/tmp/doesntmatter')
904904
out, err = capsys.readouterr()
905905
assert not out
906-
assert 'Cannot read' in err
906+
assert 'Cannot read persistent history file' in err
907+
908+
909+
def test_history_file_bad_compression(mocker, capsys):
910+
history_file = '/tmp/doesntmatter'
911+
with open(history_file, "wb") as f:
912+
f.write(b"THIS IS NOT COMPRESSED DATA")
913+
914+
cmd2.Cmd(persistent_history_file=history_file)
915+
out, err = capsys.readouterr()
916+
assert not out
917+
assert 'Error decompressing persistent history data' in err
918+
919+
920+
def test_history_file_bad_json(mocker, capsys):
921+
import lzma
922+
923+
data = b"THIS IS NOT JSON"
924+
compressed_data = lzma.compress(data)
925+
926+
history_file = '/tmp/doesntmatter'
927+
with open(history_file, "wb") as f:
928+
f.write(compressed_data)
929+
930+
cmd2.Cmd(persistent_history_file=history_file)
931+
out, err = capsys.readouterr()
932+
assert not out
933+
assert 'Error processing persistent history data' in err
907934

908935

909936
def test_history_populates_readline(hist_file):
@@ -960,4 +987,4 @@ def test_persist_history_permission_error(hist_file, mocker, capsys):
960987
app._persist_history()
961988
out, err = capsys.readouterr()
962989
assert not out
963-
assert 'Cannot write' in err
990+
assert 'Cannot write persistent history file' in err

0 commit comments

Comments
 (0)