@@ -903,7 +903,34 @@ def test_history_file_permission_error(mocker, capsys):
903
903
cmd2 .Cmd (persistent_history_file = '/tmp/doesntmatter' )
904
904
out , err = capsys .readouterr ()
905
905
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
907
934
908
935
909
936
def test_history_populates_readline (hist_file ):
@@ -960,4 +987,4 @@ def test_persist_history_permission_error(hist_file, mocker, capsys):
960
987
app ._persist_history ()
961
988
out , err = capsys .readouterr ()
962
989
assert not out
963
- assert 'Cannot write' in err
990
+ assert 'Cannot write persistent history file ' in err
0 commit comments