@@ -727,12 +727,6 @@ def shell_app():
727727 app .stdout = StdOut ()
728728 return app
729729
730- @pytest .mark .skipif (sys .platform == 'win32' or sys .platform .startswith ('linux' ),
731- reason = "Unit test passes when I run it, but fails on TravisCI and AppVeyor machines" )
732- def test_default_to_shell_found (shell_app ):
733- out = run_cmd (shell_app , 'echo Hello' )
734- assert out == []
735-
736730def test_default_to_shell_unknown (shell_app ):
737731 unknown_command = 'zyxcw23'
738732 out = run_cmd (shell_app , unknown_command )
@@ -762,3 +756,60 @@ def test_ansi_prompt_escaped():
762756 assert prompt != color_prompt
763757 assert readline_safe_prompt .startswith (readline_hack_start + app ._colorcodes [color ][True ] + readline_hack_end )
764758 assert readline_safe_prompt .endswith (readline_hack_start + app ._colorcodes [color ][False ] + readline_hack_end )
759+
760+
761+ class HelpApp (cmd2 .Cmd ):
762+ """Class for testing custom help_* methods which override docstring help."""
763+ def __init__ (self , * args , ** kwargs ):
764+ # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x
765+ cmd2 .Cmd .__init__ (self , * args , ** kwargs )
766+
767+ def do_squat (self , arg ):
768+ """This docstring help will never be shown because the help_squat method overrides it."""
769+ pass
770+
771+ def help_squat (self ):
772+ self .stdout .write ('This command does diddly squat...\n ' )
773+
774+ def do_pause (self , arg ):
775+ """This overrides the pause command and does nothing."""
776+ pass
777+
778+ # This command will be in the "undocumented" section of the help menu
779+ def do_undoc (self , arg ):
780+ pass
781+
782+ @pytest .fixture
783+ def help_app ():
784+ app = HelpApp ()
785+ app .stdout = StdOut ()
786+ return app
787+
788+ def test_custom_command_help (help_app ):
789+ out = run_cmd (help_app , 'help squat' )
790+ expected = normalize ('This command does diddly squat...' )
791+ assert out == expected
792+
793+ def test_custom_help_menu (help_app ):
794+ out = run_cmd (help_app , 'help' )
795+ expected = normalize ("""
796+ Documented commands (type help <topic>):
797+ ========================================
798+ _relative_load edit history pause pyscript run set shortcuts squat
799+ cmdenvironment help load py quit save shell show
800+
801+ Undocumented commands:
802+ ======================
803+ undoc
804+ """ )
805+ assert out == expected
806+
807+ def test_help_undocumented (help_app ):
808+ out = run_cmd (help_app , 'help undoc' )
809+ expected = normalize ('*** No help on undoc' )
810+ assert out == expected
811+
812+ def test_help_overridden_method (help_app ):
813+ out = run_cmd (help_app , 'help pause' )
814+ expected = normalize ('This overrides the pause command and does nothing.' )
815+ assert out == expected
0 commit comments