diff options
Diffstat (limited to 'tests/pyscript')
-rw-r--r-- | tests/pyscript/environment.py | 20 | ||||
-rw-r--r-- | tests/pyscript/recursive.py | 1 | ||||
-rw-r--r-- | tests/pyscript/run.py | 6 | ||||
-rw-r--r-- | tests/pyscript/to_run.py | 2 |
4 files changed, 21 insertions, 8 deletions
diff --git a/tests/pyscript/environment.py b/tests/pyscript/environment.py new file mode 100644 index 00000000..5e4d93d6 --- /dev/null +++ b/tests/pyscript/environment.py @@ -0,0 +1,20 @@ +# flake8: noqa F821 +# Tests that cmd2 populates __name__, __file__, and sets sys.path[0] to our directory +import os +import sys +app.cmd_echo = True + +if __name__ != '__main__': + print("Error: __name__ is: {}".format(__name__)) + quit() + +if __file__ != sys.argv[0]: + print("Error: __file__ is: {}".format(__file__)) + quit() + +our_dir = os.path.dirname(os.path.abspath(__file__)) +if our_dir != sys.path[0]: + print("Error: our_dir is: {}".format(our_dir)) + quit() + +print("PASSED") diff --git a/tests/pyscript/recursive.py b/tests/pyscript/recursive.py index 21550592..7f02bb78 100644 --- a/tests/pyscript/recursive.py +++ b/tests/pyscript/recursive.py @@ -5,6 +5,7 @@ Example demonstrating that calling run_pyscript recursively inside another Python script isn't allowed """ import os +import sys app.cmd_echo = True my_dir = (os.path.dirname(os.path.realpath(sys.argv[0]))) diff --git a/tests/pyscript/run.py b/tests/pyscript/run.py deleted file mode 100644 index 47250a10..00000000 --- a/tests/pyscript/run.py +++ /dev/null @@ -1,6 +0,0 @@ -# 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 deleted file mode 100644 index b207952d..00000000 --- a/tests/pyscript/to_run.py +++ /dev/null @@ -1,2 +0,0 @@ -# flake8: noqa F821 -print("I have been run") |