summaryrefslogtreecommitdiff
path: root/tests/test_cli.py
diff options
context:
space:
mode:
authorVictor Uriarte <victor.m.uriarte@intel.com>2016-06-15 19:18:56 -0700
committerVictor Uriarte <victor.m.uriarte@intel.com>2016-06-15 20:42:36 -0700
commit451d6d5d380cb4246c47e374aa9c4034fc7f9805 (patch)
treea91f6238cf02bd25dfff29071a8d32df6e9b9d0d /tests/test_cli.py
parent5eab09b6d3e60c9c530d372f0d51849f438a8a7b (diff)
downloadsqlparse-451d6d5d380cb4246c47e374aa9c4034fc7f9805.tar.gz
Add test_cli.py
References: http://stackoverflow.com/questions/18160078/how-do-you-write-tests-for-the-argparse-portion-of-a-python-module http://dustinrcollins.com/testing-python-command-line-apps https://github.com/mdklatt/cookiecutter-python-app
Diffstat (limited to 'tests/test_cli.py')
-rw-r--r--tests/test_cli.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py
new file mode 100644
index 0000000..81d8449
--- /dev/null
+++ b/tests/test_cli.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+
+import os
+import subprocess
+import sys
+
+import pytest
+
+import sqlparse
+import sqlparse.__main__
+from tests.utils import FILES_DIR
+
+path = os.path.join(FILES_DIR, 'function.sql')
+
+
+def test_cli_main_empty():
+ with pytest.raises(SystemExit):
+ sqlparse.cli.main([])
+
+
+def test_parser_empty():
+ with pytest.raises(SystemExit):
+ parser = sqlparse.cli.create_parser()
+ parser.parse_args([])
+
+
+def test_main_help():
+ # Call with the --help option as a basic sanity check.
+ with pytest.raises(SystemExit) as exinfo:
+ sqlparse.cli.main(["--help", ])
+ assert exinfo.value.code == 0
+
+
+def test_valid_args():
+ # test doesn't abort
+ assert sqlparse.cli.main([path, '-r']) is not None
+
+
+def test_script():
+ # Call with the --help option as a basic sanity check.
+ cmdl = "{0:s} -m sqlparse.cli --help".format(sys.executable)
+ assert subprocess.call(cmdl.split()) == 0