summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-02-17 11:39:50 -0500
committerGitHub <noreply@github.com>2020-02-17 11:39:50 -0500
commit729e152c525bc30d36f130f8dc8442aeb00d1de8 (patch)
tree25f9041650716c5be91926da39af0b0ebaca853f /tests/test_cmd2.py
parent013b9e0a2c75e17f8aa0e0f7cbe50d84d2f657d8 (diff)
parent555db5d98fc122dc21d3bb239c079d68272cc0c3 (diff)
downloadcmd2-git-729e152c525bc30d36f130f8dc8442aeb00d1de8.tar.gz
Merge pull request #888 from python-cmd2/pyscript_fixes
pyscript fixes
Diffstat (limited to 'tests/test_cmd2.py')
-rwxr-xr-xtests/test_cmd2.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 376658e5..dc9a3fa1 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -205,14 +205,24 @@ 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 shallow 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'
+
+ # Place an editable object in py_locals. Since we make a shallow copy of py_locals,
+ # this object should be editable from the py environment.
+ base_app.py_locals['my_list'] = []
+ out, err = run_cmd(base_app, 'py my_list.append(2)')
+ assert not out and not err
+ assert base_app.py_locals['my_list'][0] == 2
- # 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'