@@ -461,6 +461,17 @@ def test_history_output_file(base_app):
461461 content = normalize (f .read ())
462462 assert content == expected
463463
464+ def test_history_bad_output_file (base_app ):
465+ run_cmd (base_app , 'help' )
466+ run_cmd (base_app , 'shortcuts' )
467+ run_cmd (base_app , 'help history' )
468+
469+ fname = os .path .join (os .path .sep , "fake" , "fake" , "fake" )
470+ out , err = run_cmd (base_app , 'history -o "{}"' .format (fname ))
471+
472+ assert not out
473+ assert "Error saving" in err [0 ]
474+
464475def test_history_edit (base_app , monkeypatch ):
465476 # Set a fake editor just to make sure we have one. We aren't really
466477 # going to call it due to the mock
@@ -492,21 +503,23 @@ def test_history_run_one_command(base_app):
492503 out2 , err2 = run_cmd (base_app , 'history -r 1' )
493504 assert out1 == out2
494505
495- def test_history_clear (base_app ):
506+ def test_history_clear (hist_file ):
496507 # Add commands to history
497- run_cmd (base_app , 'help' )
498- run_cmd (base_app , 'alias' )
508+ app = cmd2 .Cmd (persistent_history_file = hist_file )
509+ run_cmd (app , 'help' )
510+ run_cmd (app , 'alias' )
499511
500512 # Make sure history has items
501- out , err = run_cmd (base_app , 'history' )
513+ out , err = run_cmd (app , 'history' )
502514 assert out
503515
504516 # Clear the history
505- run_cmd (base_app , 'history --clear' )
517+ run_cmd (app , 'history --clear' )
506518
507- # Make sure history is empty
508- out , err = run_cmd (base_app , 'history' )
519+ # Make sure history is empty and its file is gone
520+ out , err = run_cmd (app , 'history' )
509521 assert out == []
522+ assert not os .path .exists (hist_file )
510523
511524def test_history_verbose_with_other_options (base_app ):
512525 # make sure -v shows a usage error if any other options are present
0 commit comments