summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-02-14 16:28:41 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-02-14 16:28:41 -0500
commit9156618a56d635bb51261d019a3703a1b4e3b588 (patch)
tree3f35d07cf668ec156dac6e97e612569c83aa36c6 /tests/test_cmd2.py
parent013b9e0a2c75e17f8aa0e0f7cbe50d84d2f657d8 (diff)
downloadcmd2-git-9156618a56d635bb51261d019a3703a1b4e3b588.tar.gz
Fixed bug where pyscripts could edit cmd2.Cmd.py_locals dictionary.
Fixed bug where cmd2 set sys.path[0] for a pyscript to its cwd instead of the script's directory. Fixed bug where sys.path was not being restored after a pyscript ran. Setting the following pyscript variables: __name__: __main__ __file__: script path (as typed) Removed do_py.run() function since it didn't handle arguments and offered no benefit over run_pyscript.
Diffstat (limited to 'tests/test_cmd2.py')
-rwxr-xr-xtests/test_cmd2.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 376658e5..41528612 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -205,14 +205,17 @@ def test_base_shell(base_app, monkeypatch):
def test_base_py(base_app):
- # Create a variable and make sure we can see it
- out, err = run_cmd(base_app, 'py qqq=3')
- assert not out
+ # Make sure py can't edit Cmd.py_locals. It used to be that cmd2 was passing its py_locals
+ # dictionary to the py environment instead of a copy.
+ base_app.py_locals['test_var'] = 5
+ out, err = run_cmd(base_app, 'py del[locals()["test_var"]]')
+ assert not out and not err
+ assert base_app.py_locals['test_var'] == 5
- out, err = run_cmd(base_app, 'py print(qqq)')
- assert out[0].rstrip() == '3'
+ out, err = run_cmd(base_app, 'py print(test_var)')
+ assert out[0].rstrip() == '5'
- # Add a more complex statement
+ # Try a print statement
out, err = run_cmd(base_app, 'py print("spaces" + " in this " + "command")')
assert out[0].rstrip() == 'spaces in this command'