diff options
| author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-15 19:18:56 -0700 |
|---|---|---|
| committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-15 20:42:36 -0700 |
| commit | 451d6d5d380cb4246c47e374aa9c4034fc7f9805 (patch) | |
| tree | a91f6238cf02bd25dfff29071a8d32df6e9b9d0d | |
| parent | 5eab09b6d3e60c9c530d372f0d51849f438a8a7b (diff) | |
| download | sqlparse-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
| -rw-r--r-- | setup.cfg | 7 | ||||
| -rw-r--r-- | tests/test_cli.py | 42 |
2 files changed, 48 insertions, 1 deletions
@@ -2,7 +2,7 @@ universal = 1 [pytest] -xfail_strict=true +xfail_strict = True [flake8] exclude = @@ -10,3 +10,8 @@ exclude = ignore = W503, E731 + +[coverage:run] +branch = False +omit = + sqlparse/__main__.py 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 |
