summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/pyscript/raises_exception.py (renamed from tests/scripts/raises_exception.py)0
-rw-r--r--tests/pyscript/recursive.py11
-rw-r--r--tests/pyscript/run.py6
-rw-r--r--tests/pyscript/to_run.py2
-rw-r--r--tests/scripts/recursive.py8
-rw-r--r--tests/test_cmd2.py12
-rw-r--r--tests/test_run_pyscript.py16
7 files changed, 32 insertions, 23 deletions
diff --git a/tests/scripts/raises_exception.py b/tests/pyscript/raises_exception.py
index 738edaf2..738edaf2 100644
--- a/tests/scripts/raises_exception.py
+++ b/tests/pyscript/raises_exception.py
diff --git a/tests/pyscript/recursive.py b/tests/pyscript/recursive.py
new file mode 100644
index 00000000..21550592
--- /dev/null
+++ b/tests/pyscript/recursive.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+# coding=utf-8
+# flake8: noqa F821
+"""
+Example demonstrating that calling run_pyscript recursively inside another Python script isn't allowed
+"""
+import os
+
+app.cmd_echo = True
+my_dir = (os.path.dirname(os.path.realpath(sys.argv[0])))
+app('run_pyscript {}'.format(os.path.join(my_dir, 'stop.py')))
diff --git a/tests/pyscript/run.py b/tests/pyscript/run.py
new file mode 100644
index 00000000..47250a10
--- /dev/null
+++ b/tests/pyscript/run.py
@@ -0,0 +1,6 @@
+# flake8: noqa F821
+import os
+
+app.cmd_echo = True
+my_dir = (os.path.dirname(os.path.realpath(sys.argv[0])))
+run(os.path.join(my_dir, 'to_run.py'))
diff --git a/tests/pyscript/to_run.py b/tests/pyscript/to_run.py
new file mode 100644
index 00000000..b207952d
--- /dev/null
+++ b/tests/pyscript/to_run.py
@@ -0,0 +1,2 @@
+# flake8: noqa F821
+print("I have been run")
diff --git a/tests/scripts/recursive.py b/tests/scripts/recursive.py
deleted file mode 100644
index 7d37e540..00000000
--- a/tests/scripts/recursive.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env python
-# coding=utf-8
-# flake8: noqa F821
-"""
-Example demonstrating that running a Python script recursively inside another Python script isn't allowed
-"""
-app.cmd_echo = True
-app('run_pyscript ../script.py')
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index d4dbfe55..3f8c43b7 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -236,6 +236,7 @@ def test_base_shell(base_app, monkeypatch):
assert out == []
assert m.called
+
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')
@@ -263,17 +264,6 @@ def test_base_py(base_app):
assert "NameError: name 'self' is not defined" in err
-@pytest.mark.skipif(sys.platform == 'win32',
- reason="Unit test doesn't work on win32, but feature does")
-def test_py_run_script(base_app, request):
- test_dir = os.path.dirname(request.module.__file__)
- python_script = os.path.join(test_dir, 'script.py')
- expected = 'This is a python script running ...'
-
- out, err = run_cmd(base_app, "py run('{}')".format(python_script))
- assert expected in out
-
-
def test_base_error(base_app):
out, err = run_cmd(base_app, 'meow')
assert "is not a recognized command" in err[0]
diff --git a/tests/test_run_pyscript.py b/tests/test_run_pyscript.py
index ded95225..15cdd7be 100644
--- a/tests/test_run_pyscript.py
+++ b/tests/test_run_pyscript.py
@@ -32,7 +32,7 @@ def test_run_pyscript(base_app, request):
def test_run_pyscript_recursive_not_allowed(base_app, request):
test_dir = os.path.dirname(request.module.__file__)
- python_script = os.path.join(test_dir, 'scripts', 'recursive.py')
+ python_script = os.path.join(test_dir, 'pyscript', 'recursive.py')
expected = 'Recursively entering interactive Python consoles is not allowed.'
out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
@@ -41,7 +41,7 @@ def test_run_pyscript_recursive_not_allowed(base_app, request):
def test_run_pyscript_with_nonexist_file(base_app):
python_script = 'does_not_exist.py'
out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
- assert "Error opening script file" in err[0]
+ assert "Error reading script file" in err[0]
def test_run_pyscript_with_non_python_file(base_app, request):
m = mock.MagicMock(name='input', return_value='2')
@@ -54,7 +54,7 @@ def test_run_pyscript_with_non_python_file(base_app, request):
def test_run_pyscript_with_exception(base_app, request):
test_dir = os.path.dirname(request.module.__file__)
- python_script = os.path.join(test_dir, 'scripts', 'raises_exception.py')
+ python_script = os.path.join(test_dir, 'pyscript', 'raises_exception.py')
out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
assert err[0].startswith('Traceback')
assert "TypeError: unsupported operand type(s) for +: 'int' and 'str'" in err[-1]
@@ -91,7 +91,7 @@ def test_run_pyscript_stop(base_app, request):
# Verify onecmd_plus_hooks() returns True if any commands in a pyscript return True for stop
test_dir = os.path.dirname(request.module.__file__)
- # help.py doesn't run any commands that returns True for stop
+ # help.py doesn't run any commands that return True for stop
python_script = os.path.join(test_dir, 'pyscript', 'help.py')
stop = base_app.onecmd_plus_hooks('run_pyscript {}'.format(python_script))
assert not stop
@@ -100,3 +100,11 @@ def test_run_pyscript_stop(base_app, request):
python_script = os.path.join(test_dir, 'pyscript', 'stop.py')
stop = base_app.onecmd_plus_hooks('run_pyscript {}'.format(python_script))
assert stop
+
+def test_run_pyscript_run(base_app, request):
+ test_dir = os.path.dirname(request.module.__file__)
+ python_script = os.path.join(test_dir, 'pyscript', 'run.py')
+ expected = 'I have been run'
+
+ out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
+ assert expected in out \ No newline at end of file