@@ -131,8 +131,6 @@ def test_base_run_python_script(base_app, capsys, request):
131131 assert out == expected
132132
133133
134- @pytest .mark .skipif (sys .platform == 'win32' ,
135- reason = "Unit test doesn't work on win32, but feature does" )
136134def test_base_run_pyscript (base_app , capsys , request ):
137135 test_dir = os .path .dirname (request .module .__file__ )
138136 python_script = os .path .join (test_dir , 'script.py' )
@@ -142,6 +140,34 @@ def test_base_run_pyscript(base_app, capsys, request):
142140 out , err = capsys .readouterr ()
143141 assert out == expected
144142
143+ def test_recursive_pyscript_not_allowed (base_app , capsys , request ):
144+ test_dir = os .path .dirname (request .module .__file__ )
145+ python_script = os .path .join (test_dir , 'scripts' , 'recursive.py' )
146+ expected = 'ERROR: Recursively entering interactive Python consoles is not allowed.\n '
147+
148+ run_cmd (base_app , "pyscript {}" .format (python_script ))
149+ out , err = capsys .readouterr ()
150+ assert err == expected
151+
152+ def test_pyscript_with_nonexist_file (base_app , capsys ):
153+ python_script = 'does_not_exist.py'
154+ run_cmd (base_app , "pyscript {}" .format (python_script ))
155+ out , err = capsys .readouterr ()
156+ assert err .startswith ('ERROR: [Errno 2] No such file or directory:' )
157+
158+ def test_pyscript_with_exception (base_app , capsys , request ):
159+ test_dir = os .path .dirname (request .module .__file__ )
160+ python_script = os .path .join (test_dir , 'scripts' , 'raises_exception.py' )
161+ run_cmd (base_app , "pyscript {}" .format (python_script ))
162+ out , err = capsys .readouterr ()
163+ assert err .startswith ('Traceback' )
164+ assert err .endswith ("TypeError: unsupported operand type(s) for +: 'int' and 'str'\n " )
165+
166+ def test_pyscript_requires_an_argument (base_app , capsys ):
167+ run_cmd (base_app , "pyscript" )
168+ out , err = capsys .readouterr ()
169+ assert err .startswith ('ERROR: pyscript command requires at least 1 argument ...' )
170+
145171
146172def test_base_error (base_app ):
147173 out = run_cmd (base_app , 'meow' )
@@ -957,3 +983,21 @@ def test_select_uneven_list_of_tuples(select_app):
957983
958984 # And verify the expected output to stdout
959985 assert out == expected
986+
987+ @pytest .fixture
988+ def noarglist_app ():
989+ cmd2 .set_use_arg_list (False )
990+ app = cmd2 .Cmd ()
991+ app .stdout = StdOut ()
992+ return app
993+
994+ def test_pyscript_with_noarglist (noarglist_app , capsys , request ):
995+ test_dir = os .path .dirname (request .module .__file__ )
996+ python_script = os .path .join (test_dir , '..' , 'examples' , 'scripts' , 'arg_printer.py' )
997+ expected = """Running Python script 'arg_printer.py' which was called with 2 arguments
998+ arg 1: 'foo'
999+ arg 2: 'bar'
1000+ """
1001+ run_cmd (noarglist_app , 'pyscript {} foo bar' .format (python_script ))
1002+ out , err = capsys .readouterr ()
1003+ assert out == expected
0 commit comments