From 795cd53d7fcade9a0724ade132c0e542e3d3f07a Mon Sep 17 00:00:00 2001 From: Nishant Rodrigues Date: Sun, 26 Apr 2020 22:57:32 +0530 Subject: [PATCH] tests - test auto complete script - remove redundant test --- tqdm/tests/tests_completion.py | 34 ---------------------------------- tqdm/tests/tests_main.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 34 deletions(-) delete mode 100644 tqdm/tests/tests_completion.py diff --git a/tqdm/tests/tests_completion.py b/tqdm/tests/tests_completion.py deleted file mode 100644 index 74da11d3..00000000 --- a/tqdm/tests/tests_completion.py +++ /dev/null @@ -1,34 +0,0 @@ -import re -import tqdm -import tqdm.cli - -RE_OPT = re.compile(r'(\w+) :', flags=re.M) - - -def doc2opt(doc): - return ('--' + i for i in RE_OPT.findall(doc)) - - -def test_autogenerate_cli(): - # CLI options - options = {'-h', '--help', '-v', '--version'} - for doc in (tqdm.tqdm.__init__.__doc__, tqdm.cli.CLI_EXTRA_DOC): - options.update(doc2opt(doc)) - options.difference_update( - '--' + i for i in ('name',) + tqdm.cli.UNSUPPORTED_OPTS) - - # All options - # Add new CLI options to this list - all_opts = { - '-h', '-v', '--help', '--version', - '--desc', '--total', '--leave', '--ncols', - '--mininterval', '--maxinterval', '--miniters', - '--ascii', '--disable', '--unit', '--unit_scale', - '--dynamic_ncols', '--smoothing', '--bar_format', - '--initial', '--position', '--postfix', '--unit_divisor', - '--bytes', '--write_bytes', '--lock_args', '--nrows', - '--delim', '--buf_size', '--manpath', '--log', - '--comppath' - } - - assert options == all_opts diff --git a/tqdm/tests/tests_main.py b/tqdm/tests/tests_main.py index ca444829..2eeddc4e 100644 --- a/tqdm/tests/tests_main.py +++ b/tqdm/tests/tests_main.py @@ -5,6 +5,7 @@ from shutil import rmtree from tempfile import mkdtemp from tqdm.cli import main, TqdmKeyError, TqdmTypeError from tqdm.utils import IS_WIN +from io import open as io_open from tests_tqdm import with_setup, pretest, posttest, _range, closing, \ UnicodeIO, StringIO, SkipTest @@ -115,6 +116,31 @@ def test_comppath(): rmtree(tmp, True) +def test_autocomplete(): + """Test CLI auto completion arguments""" + if IS_WIN: + raise SkipTest + tmp = mkdtemp() + man = path.join(tmp, "tqdm_completion.sh") + print(man) + assert not path.exists(man) + try: + main(argv=['--comppath', tmp], fp=NULL) + except SystemExit: + pass + else: + raise SystemExit("Expected system exit") + assert path.exists(man) + with io_open(man, mode='r', encoding='utf-8') as fd: + script = fd.read() + opts = { + '--help', '--desc', '--total', '--leave', '--ncols', '--ascii', '--dynamic_ncols', + '--position', '--bytes', '--nrows', '--delim', '--manpath', '--comppath' + } + assert all(args in script for args in opts) + rmtree(tmp, True) + + def test_exceptions(): """Test CLI Exceptions""" _SYS = sys.stdin, sys.argv