From 6817a562708c4ea9e436917104c1a4a569b0ba6b Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Tue, 30 Jul 2013 12:33:38 +0200 Subject: [PATCH] minor adjustment, added test for positional argument completion --HG-- branch : argcomplete --- _pytest/_argcomplete.py | 1 - testing/test_parseopt.py | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/_pytest/_argcomplete.py b/_pytest/_argcomplete.py index 2a836a766..4fb666490 100644 --- a/_pytest/_argcomplete.py +++ b/_pytest/_argcomplete.py @@ -55,7 +55,6 @@ if os.environ.get('_ARGCOMPLETE'): if sys.version_info[:2] < (2, 6): sys.exit(1) try: - import argcomplete import argcomplete.completers except ImportError: sys.exit(-1) diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index 97b0c4d3a..3c7194c4d 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -175,10 +175,10 @@ def test_addoption_parser_epilog(testdir): @pytest.mark.skipif("sys.version_info < (2,5)") def test_argcomplete(testdir): + if not py.path.local.sysfind('bash'): + pytest.skip("bash not available") import os - p = py.path.local.make_numbered_dir(prefix="test_argcomplete-", - keep=None, rootdir=testdir.tmpdir) - script = p._fastjoin('test_argcomplete') + script = os.path.join(os.getcwd(), 'test_argcomplete') with open(str(script), 'w') as fp: # redirect output from argcomplete to stdin and stderr is not trivial # http://stackoverflow.com/q/12589419/1307905 @@ -187,14 +187,22 @@ def test_argcomplete(testdir): '8>&1 9>&2') os.environ['_ARGCOMPLETE'] = "1" os.environ['_ARGCOMPLETE_IFS'] = "\x0b" - os.environ['COMP_LINE'] = "py.test --fu" - os.environ['COMP_POINT'] = "12" os.environ['COMP_WORDBREAKS'] = ' \\t\\n"\\\'><=;|&(:' - result = testdir.run('bash', str(script), '--fu') + arg = '--fu' + os.environ['COMP_LINE'] = "py.test " + arg + os.environ['COMP_POINT'] = str(len(os.environ['COMP_LINE'])) + result = testdir.run('bash', str(script), arg) print dir(result), result.ret if result.ret == 255: # argcomplete not found - assert True + pytest.skip("argcomplete not available") else: result.stdout.fnmatch_lines(["--funcargs", "--fulltrace"]) + + os.mkdir('test_argcomplete.d') + arg = 'test_argc' + os.environ['COMP_LINE'] = "py.test " + arg + os.environ['COMP_POINT'] = str(len(os.environ['COMP_LINE'])) + result = testdir.run('bash', str(script), arg) + result.stdout.fnmatch_lines(["test_argcomplete", "test_argcomplete.d/"])