2222
2323import cmd2
2424from cmd2 import clipboard , constants , utils
25- from .conftest import run_cmd , normalize , BASE_HELP , BASE_HELP_VERBOSE , \
26- HELP_HISTORY , SHORTCUTS_TXT , SHOW_TXT , SHOW_LONG
25+ from .conftest import run_cmd , normalize , verify_help_text , HELP_HISTORY , SHORTCUTS_TXT , SHOW_TXT , SHOW_LONG
2726
2827def CreateOutsimApp ():
2928 c = cmd2 .Cmd ()
@@ -53,21 +52,20 @@ def test_empty_statement(base_app):
5352
5453def test_base_help (base_app ):
5554 out , err = run_cmd (base_app , 'help' )
56- expected = normalize (BASE_HELP )
57- assert out == expected
55+ verify_help_text (base_app , out )
5856
5957def test_base_help_verbose (base_app ):
6058 out , err = run_cmd (base_app , 'help -v' )
61- expected = normalize (BASE_HELP_VERBOSE )
62- assert out == expected
59+ verify_help_text (base_app , out )
6360
6461 # Make sure :param type lines are filtered out of help summary
6562 help_doc = base_app .do_help .__func__ .__doc__
6663 help_doc += "\n :param fake param"
6764 base_app .do_help .__func__ .__doc__ = help_doc
6865
6966 out , err = run_cmd (base_app , 'help --verbose' )
70- assert out == expected
67+ verify_help_text (base_app , out )
68+ assert ':param' not in '' .join (out )
7169
7270def test_base_argparse_help (base_app ):
7371 # Verify that "set -h" gives the same output as "help set" and that it starts in a way that makes sense
@@ -427,18 +425,17 @@ def test_output_redirection(base_app):
427425 try :
428426 # Verify that writing to a file works
429427 run_cmd (base_app , 'help > {}' .format (filename ))
430- expected = normalize (BASE_HELP )
431428 with open (filename ) as f :
432- content = normalize ( f .read () )
433- assert content == expected
429+ content = f .read ()
430+ verify_help_text ( base_app , content )
434431
435432 # Verify that appending to a file also works
436433 run_cmd (base_app , 'help history >> {}' .format (filename ))
437- expected = normalize (BASE_HELP + '\n ' + HELP_HISTORY )
438434 with open (filename ) as f :
439- content = normalize (f .read ())
440- assert content == expected
441- except :
435+ appended_content = f .read ()
436+ assert appended_content .startswith (content )
437+ assert len (appended_content ) > len (content )
438+ except Exception :
442439 raise
443440 finally :
444441 os .remove (filename )
@@ -448,19 +445,18 @@ def test_output_redirection_to_nonexistent_directory(base_app):
448445
449446 # Verify that writing to a file in a non-existent directory doesn't work
450447 run_cmd (base_app , 'help > {}' .format (filename ))
451- expected = normalize (BASE_HELP )
452448 with pytest .raises (FileNotFoundError ):
453449 with open (filename ) as f :
454- content = normalize ( f .read () )
455- assert content == expected
450+ content = f .read ()
451+ verify_help_text ( base_app , content )
456452
457453 # Verify that appending to a file also works
458454 run_cmd (base_app , 'help history >> {}' .format (filename ))
459- expected = normalize (BASE_HELP + '\n ' + HELP_HISTORY )
460455 with pytest .raises (FileNotFoundError ):
461456 with open (filename ) as f :
462- content = normalize (f .read ())
463- assert content == expected
457+ appended_content = f .read ()
458+ verify_help_text (base_app , appended_content )
459+ assert len (appended_content ) > len (content )
464460
465461def test_output_redirection_to_too_long_filename (base_app ):
466462 filename = '~/sdkfhksdjfhkjdshfkjsdhfkjsdhfkjdshfkjdshfkjshdfkhdsfkjhewfuihewiufhweiufhiweufhiuewhiuewhfiuwehfia' \
@@ -471,19 +467,18 @@ def test_output_redirection_to_too_long_filename(base_app):
471467
472468 # Verify that writing to a file in a non-existent directory doesn't work
473469 run_cmd (base_app , 'help > {}' .format (filename ))
474- expected = normalize (BASE_HELP )
475470 with pytest .raises (OSError ):
476471 with open (filename ) as f :
477- content = normalize ( f .read () )
478- assert content == expected
472+ content = f .read ()
473+ verify_help_text ( base_app , content )
479474
480475 # Verify that appending to a file also works
481476 run_cmd (base_app , 'help history >> {}' .format (filename ))
482- expected = normalize (BASE_HELP + '\n ' + HELP_HISTORY )
483477 with pytest .raises (OSError ):
484478 with open (filename ) as f :
485- content = normalize (f .read ())
486- assert content == expected
479+ appended_content = f .read ()
480+ verify_help_text (base_app , content )
481+ assert len (appended_content ) > len (content )
487482
488483
489484def test_feedback_to_output_true (base_app ):
@@ -530,8 +525,7 @@ def test_disallow_redirection(base_app):
530525
531526 # Verify output wasn't redirected
532527 out , err = run_cmd (base_app , 'help > {}' .format (filename ))
533- expected = normalize (BASE_HELP )
534- assert out == expected
528+ verify_help_text (base_app , out )
535529
536530 # Verify that no file got created
537531 assert not os .path .exists (filename )
@@ -574,13 +568,14 @@ def test_pipe_to_shell_error(base_app):
574568def test_send_to_paste_buffer (base_app ):
575569 # Test writing to the PasteBuffer/Clipboard
576570 run_cmd (base_app , 'help >' )
577- expected = normalize ( BASE_HELP )
578- assert normalize ( cmd2 . cmd2 . get_paste_buffer ()) == expected
571+ paste_contents = cmd2 . cmd2 . get_paste_buffer ( )
572+ verify_help_text ( base_app , paste_contents )
579573
580574 # Test appending to the PasteBuffer/Clipboard
581575 run_cmd (base_app , 'help history >>' )
582- expected = normalize (BASE_HELP + '\n ' + HELP_HISTORY )
583- assert normalize (cmd2 .cmd2 .get_paste_buffer ()) == expected
576+ appended_contents = cmd2 .cmd2 .get_paste_buffer ()
577+ assert appended_contents .startswith (paste_contents )
578+ assert len (appended_contents ) > len (paste_contents )
584579
585580
586581def test_base_timing (base_app ):
@@ -901,17 +896,7 @@ def test_custom_command_help(help_app):
901896
902897def test_custom_help_menu (help_app ):
903898 out , err = run_cmd (help_app , 'help' )
904- expected = normalize ("""
905- Documented commands (type help <topic>):
906- ========================================
907- alias help load py quit run_script shell squat
908- edit history macro pyscript run_pyscript set shortcuts
909-
910- Undocumented commands:
911- ======================
912- undoc
913- """ )
914- assert out == expected
899+ verify_help_text (help_app , out )
915900
916901def test_help_undocumented (help_app ):
917902 out , err = run_cmd (help_app , 'help undoc' )
@@ -962,62 +947,11 @@ def helpcat_app():
962947
963948def test_help_cat_base (helpcat_app ):
964949 out , err = run_cmd (helpcat_app , 'help' )
965- expected = normalize ("""Documented commands (type help <topic>):
966-
967- Custom Category
968- ===============
969- edit squat
970-
971- Some Category
972- =============
973- cat_nodoc diddly
974-
975- Other
976- =====
977- alias history macro pyscript run_pyscript set shortcuts
978- help load py quit run_script shell
979-
980- Undocumented commands:
981- ======================
982- undoc
983- """ )
984- assert out == expected
950+ verify_help_text (helpcat_app , out )
985951
986952def test_help_cat_verbose (helpcat_app ):
987953 out , err = run_cmd (helpcat_app , 'help --verbose' )
988- expected = normalize ("""Documented commands (type help <topic>):
989-
990- Custom Category
991- ================================================================================
992- edit This overrides the edit command and does nothing.
993- squat This command does diddly squat...
994-
995- Some Category
996- ================================================================================
997- cat_nodoc
998- diddly This command does diddly
999-
1000- Other
1001- ================================================================================
1002- alias Manage aliases
1003- help List available commands or provide detailed help for a specific command
1004- history View, run, edit, save, or clear previously entered commands
1005- load Run commands in script file that is encoded as either ASCII or UTF-8 text
1006- macro Manage macros
1007- py Invoke Python command or shell
1008- pyscript Run a Python script file inside the console
1009- quit Exit this application
1010- run_pyscript Run a Python script file inside the console
1011- run_script Run commands in script file that is encoded as either ASCII or UTF-8 text
1012- set Set a settable parameter or show current settings of parameters
1013- shell Execute a command as if at the OS prompt
1014- shortcuts List available shortcuts
1015-
1016- Undocumented commands:
1017- ======================
1018- undoc
1019- """ )
1020- assert out == expected
954+ verify_help_text (helpcat_app , out )
1021955
1022956
1023957class SelectApp (cmd2 .Cmd ):
@@ -1656,12 +1590,10 @@ def test_multiple_aliases(base_app):
16561590 run_cmd (base_app , 'alias create {} help' .format (alias1 ))
16571591 run_cmd (base_app , 'alias create {} help -v' .format (alias2 ))
16581592 out , err = run_cmd (base_app , alias1 )
1659- expected = normalize (BASE_HELP )
1660- assert out == expected
1593+ verify_help_text (base_app , out )
16611594
16621595 out , err = run_cmd (base_app , alias2 )
1663- expected = normalize (BASE_HELP_VERBOSE )
1664- assert out == expected
1596+ verify_help_text (base_app , out )
16651597
16661598def test_macro_no_subcommand (base_app ):
16671599 out , err = run_cmd (base_app , 'macro' )
@@ -1716,8 +1648,7 @@ def test_macro_create_with_args(base_app):
17161648
17171649 # Run the macro
17181650 out , err = run_cmd (base_app , 'fake help -v' )
1719- expected = normalize (BASE_HELP_VERBOSE )
1720- assert out == expected
1651+ verify_help_text (base_app , out )
17211652
17221653def test_macro_create_with_escaped_args (base_app ):
17231654 # Create the macro
@@ -1810,12 +1741,11 @@ def test_multiple_macros(base_app):
18101741 run_cmd (base_app , 'macro create {} help' .format (macro1 ))
18111742 run_cmd (base_app , 'macro create {} help -v' .format (macro2 ))
18121743 out , err = run_cmd (base_app , macro1 )
1813- expected = normalize (BASE_HELP )
1814- assert out == expected
1744+ verify_help_text (base_app , out )
18151745
1816- out , err = run_cmd (base_app , macro2 )
1817- expected = normalize ( BASE_HELP_VERBOSE )
1818- assert out == expected
1746+ out2 , err2 = run_cmd (base_app , macro2 )
1747+ verify_help_text ( base_app , out2 )
1748+ assert len ( out2 ) > len ( out )
18191749
18201750def test_nonexistent_macro (base_app ):
18211751 from cmd2 .parsing import StatementParser
@@ -1878,7 +1808,7 @@ def test_onecmd_raw_str_continue(outsim_app):
18781808 stop = outsim_app .onecmd (line )
18791809 out = outsim_app .stdout .getvalue ()
18801810 assert not stop
1881- assert normalize ( out ) == normalize ( BASE_HELP )
1811+ verify_help_text ( outsim_app , out )
18821812
18831813def test_onecmd_raw_str_quit (outsim_app ):
18841814 line = "quit"
0 commit comments