diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-02-04 15:31:51 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-02-04 15:31:51 -0500 |
commit | d04e21f670955b8ce9ecf5f4baf9d1256aa86bbf (patch) | |
tree | beb84dc2dbf07d87d7e2f5a101f655a11d8f3ce1 | |
parent | c04fd950308311ff39a0c4980a780a5419d36288 (diff) | |
download | cmd2-git-d04e21f670955b8ce9ecf5f4baf9d1256aa86bbf.tar.gz |
Added can_clip declaration inside Windows code section for purposes of unit testsing.
Also added a unit test for running a python script.
-rwxr-xr-x | cmd2.py | 4 | ||||
-rw-r--r-- | tests/script.py | 2 | ||||
-rw-r--r-- | tests/test_cmd2.py | 10 |
3 files changed, 15 insertions, 1 deletions
@@ -236,6 +236,7 @@ to be installed on operating system. if sys.platform == "win32": # Running on Windows + can_clip = False try: import win32clipboard @@ -255,11 +256,12 @@ if sys.platform == "win32": win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(txt) win32clipboard.CloseClipboard() + + can_clip = True except ImportError: def get_paste_buffer(*args): raise OSError(pastebufferr % ('pywin32', 'Download from http://sourceforge.net/projects/pywin32/')) - write_to_paste_buffer = get_paste_buffer elif sys.platform == 'darwin': # Running on Mac OS X diff --git a/tests/script.py b/tests/script.py new file mode 100644 index 00000000..30d45960 --- /dev/null +++ b/tests/script.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python +print("This is a python script running ...")
\ No newline at end of file diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 94db1a8d..6b071035 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -84,6 +84,16 @@ def test_base_py(base_app, capsys): assert out.rstrip() == '3' +def test_base_run_python_script(base_app, capsys, 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 ...\n' + + run_cmd(base_app, "py run('{}')".format(python_script)) + out, err = capsys.readouterr() + assert out == expected + + def test_base_error(base_app): out = run_cmd(base_app, 'meow') assert out == ["*** Unknown syntax: meow"] |