@@ -15,14 +15,45 @@ def cmdfinalization_hook(data: plugin.CommandFinalizationData) -> plugin.Command
1515 print (HOOK_OUTPUT )
1616 return data
1717
18+ def test_run_pyscript_base (base_app , request ):
19+ test_dir = os .path .dirname (request .module .__file__ )
20+ python_script = os .path .join (test_dir , 'script.py' )
21+ expected = 'This is a python script running ...'
22+
23+ out , err = run_cmd (base_app , "run_pyscript {}" .format (python_script ))
24+ assert expected in out
25+
26+ def test_run_pyscript_recursive_not_allowed (base_app , request ):
27+ test_dir = os .path .dirname (request .module .__file__ )
28+ python_script = os .path .join (test_dir , 'scripts' , 'recursive.py' )
29+ expected = 'Recursively entering interactive Python consoles is not allowed.'
30+
31+ out , err = run_cmd (base_app , "run_pyscript {}" .format (python_script ))
32+ assert err [0 ] == expected
33+
34+ def test_run_pyscript_with_nonexist_file (base_app ):
35+ python_script = 'does_not_exist.py'
36+ out , err = run_cmd (base_app , "run_pyscript {}" .format (python_script ))
37+ assert "Error opening script file" in err [0 ]
38+
39+ def test_run_pyscript_with_exception (base_app , request ):
40+ test_dir = os .path .dirname (request .module .__file__ )
41+ python_script = os .path .join (test_dir , 'scripts' , 'raises_exception.py' )
42+ out , err = run_cmd (base_app , "run_pyscript {}" .format (python_script ))
43+ assert err [0 ].startswith ('Traceback' )
44+ assert "TypeError: unsupported operand type(s) for +: 'int' and 'str'" in err [- 1 ]
45+
46+ def test_run_pyscript_requires_an_argument (base_app ):
47+ out , err = run_cmd (base_app , "run_pyscript" )
48+ assert "the following arguments are required: script_path" in err [1 ]
49+
1850def test_run_pyscript_help (base_app , request ):
1951 test_dir = os .path .dirname (request .module .__file__ )
2052 python_script = os .path .join (test_dir , 'pyscript' , 'help.py' )
2153 out1 , err1 = run_cmd (base_app , 'help' )
2254 out2 , err2 = run_cmd (base_app , 'run_pyscript {}' .format (python_script ))
2355 assert out1 and out1 == out2
2456
25-
2657def test_run_pyscript_dir (base_app , request ):
2758 test_dir = os .path .dirname (request .module .__file__ )
2859 python_script = os .path .join (test_dir , 'pyscript' , 'pyscript_dir.py' )
@@ -31,7 +62,6 @@ def test_run_pyscript_dir(base_app, request):
3162 assert out
3263 assert out [0 ] == "['cmd_echo']"
3364
34-
3565def test_run_pyscript_stdout_capture (base_app , request ):
3666 base_app .register_cmdfinalization_hook (cmdfinalization_hook )
3767 test_dir = os .path .dirname (request .module .__file__ )
@@ -54,3 +84,13 @@ def test_run_pyscript_stop(base_app, request):
5484 python_script = os .path .join (test_dir , 'pyscript' , 'stop.py' )
5585 stop = base_app .onecmd_plus_hooks ('run_pyscript {}' .format (python_script ))
5686 assert stop
87+
88+ def test_pyscript_deprecated_but_works (base_app , request ):
89+ test_dir = os .path .dirname (request .module .__file__ )
90+ python_script = os .path .join (test_dir , 'script.py' )
91+ expected = 'This is a python script running ...'
92+
93+ out , err = run_cmd (base_app , "pyscript {}" .format (python_script ))
94+ assert expected in out
95+ assert "pyscript has been renamed and will be removed" in err [0 ]
96+
0 commit comments