@@ -356,12 +356,9 @@ def test_history_run_all_commands(base_app):
356356 assert out == []
357357
358358def test_history_run_one_command (base_app ):
359- run_cmd (base_app , 'help' )
360- # because of the way run_cmd works, it will not
361- # process the cmdqueue. So we can check to see
362- # if the cmdqueue has a waiting item
363- run_cmd (base_app , 'history -r 1' )
364- assert len (base_app .cmdqueue ) == 1
359+ expected = run_cmd (base_app , 'help' )
360+ output = run_cmd (base_app , 'history -r 1' )
361+ assert output == expected
365362
366363def test_base_load (base_app , request ):
367364 test_dir = os .path .dirname (request .module .__file__ )
@@ -525,88 +522,6 @@ def test_relative_load_requires_an_argument(base_app, capsys):
525522 assert base_app .cmdqueue == []
526523
527524
528- def test_base_save (base_app ):
529- # TODO: Use a temporary directory for the file
530- filename = 'deleteme.txt'
531- base_app .feedback_to_output = True
532- run_cmd (base_app , 'help' )
533- run_cmd (base_app , 'help save' )
534-
535- # Test the * form of save which saves all commands from history
536- out = run_cmd (base_app , 'save * {}' .format (filename ))
537- assert out == normalize ('Saved to {}\n ' .format (filename ))
538- expected = normalize ("""
539- help
540-
541- help save
542-
543- save * deleteme.txt
544- """ )
545- with open (filename ) as f :
546- content = normalize (f .read ())
547- assert content == expected
548-
549- # Test the N form of save which saves a numbered command from history
550- out = run_cmd (base_app , 'save 1 {}' .format (filename ))
551- assert out == normalize ('Saved to {}\n ' .format (filename ))
552- expected = normalize ('help' )
553- with open (filename ) as f :
554- content = normalize (f .read ())
555- assert content == expected
556-
557- # Test the blank form of save which saves the most recent command from history
558- out = run_cmd (base_app , 'save {}' .format (filename ))
559- assert out == normalize ('Saved to {}\n ' .format (filename ))
560- expected = normalize ('save 1 {}' .format (filename ))
561- with open (filename ) as f :
562- content = normalize (f .read ())
563- assert content == expected
564-
565- # Delete file that was created
566- os .remove (filename )
567-
568- def test_save_parse_error (base_app , capsys ):
569- invalid_file = '~!@'
570- run_cmd (base_app , 'save {}' .format (invalid_file ))
571- out , err = capsys .readouterr ()
572- assert out == ''
573- assert err .startswith ('ERROR: Could not understand save target {}\n ' .format (invalid_file ))
574-
575- def test_save_tempfile (base_app ):
576- # Just run help to make sure there is something in the history
577- base_app .feedback_to_output = True
578- run_cmd (base_app , 'help' )
579- out = run_cmd (base_app , 'save *' )
580- output = out [0 ]
581- assert output .startswith ('Saved to ' )
582-
583- # Delete the tempfile which was created
584- temp_file = output .split ('Saved to ' )[1 ].strip ()
585- os .remove (temp_file )
586-
587- def test_save_invalid_history_index (base_app , capsys ):
588- run_cmd (base_app , 'save 5' )
589- out , err = capsys .readouterr ()
590- assert out == ''
591- assert err .startswith ("EXCEPTION of type 'IndexError' occurred with message: 'list index out of range'\n " )
592-
593- def test_save_empty_history_and_index (base_app , capsys ):
594- run_cmd (base_app , 'save' )
595- out , err = capsys .readouterr ()
596- assert out == ''
597- assert err .startswith ("ERROR: History is empty, nothing to save.\n " )
598-
599- def test_save_invalid_path (base_app , capsys ):
600- # Just run help to make sure there is something in the history
601- run_cmd (base_app , 'help' )
602-
603- invalid_path = '/no_such_path/foobar.txt'
604- run_cmd (base_app , 'save {}' .format (invalid_path ))
605- out , err = capsys .readouterr ()
606- assert out == ''
607- assert err .startswith ("ERROR: Saving '{}' - " .format (invalid_path ))
608-
609-
610525def test_output_redirection (base_app ):
611526 fd , filename = tempfile .mkstemp (prefix = 'cmd2_test' , suffix = '.txt' )
612527 os .close (fd )
@@ -1144,8 +1059,7 @@ def test_custom_help_menu(help_app):
11441059 expected = normalize ("""
11451060Documented commands (type help <topic>):
11461061========================================
1147- edit history py quit save shell squat
1148- help load pyscript run set shortcuts
1062+ edit help history load py pyscript quit set shell shortcuts squat
11491063
11501064Undocumented commands:
11511065======================
@@ -1406,20 +1320,6 @@ def test_clipboard_failure(capsys):
14061320 assert 'Cannot redirect to paste buffer; install ``xclip`` and re-run to enable' in err
14071321
14081322
1409- def test_run_command_with_empty_arg (base_app ):
1410- command = 'help'
1411- base_app .feedback_to_output = True
1412- run_cmd (base_app , command )
1413- out = run_cmd (base_app , 'run' )
1414- expected = normalize ('{}\n \n ' .format (command ) + BASE_HELP )
1415- assert out == expected
1416-
1417- def test_run_command_with_empty_history (base_app ):
1418- base_app .feedback_to_output = True
1419- out = run_cmd (base_app , 'run' )
1420- assert out == []
1421-
1422-
14231323class CmdResultApp (cmd2 .Cmd ):
14241324 def __init__ (self , * args , ** kwargs ):
14251325 # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x
0 commit comments