Fixes for argcomplete
- separate out most argcomplete related stuff in new file _argcomplete.py (could probably be in the py library) - allow positional arguments to be interspaced with optional arguments ( + test in test_parseopt.py ) - removed double argument in tox.ini - add documentation on installing argcomplete (>=0.5.7 as needed for Python 3), might need improving/incorporation in index. This does not work on 2.5 yet. I have patches for argcomplete (with/print()/"".format) but I am not sure they will be accepted. Agreed with hpk not to push for that. Removing argcomplete and leaving completion code active now works by early exit, so <TAB> no longer re-runs the programs without parameters (which took long for py.test) test calls bash with a script that redirects filedescriptor 8 (as used by argcomplete), so the result can be tested. --HG-- branch : argcomplete
This commit is contained in:
@@ -130,6 +130,21 @@ class TestParser:
|
||||
args = parser.parse(['--ultimate-answer', '42'])
|
||||
assert args.ultimate_answer == 42
|
||||
|
||||
def test_parse_split_positional_arguments(self):
|
||||
parser = parseopt.Parser()
|
||||
parser.addoption("-R", action='store_true')
|
||||
parser.addoption("-S", action='store_false')
|
||||
args = parser.parse(['-R', '4', '2', '-S'])
|
||||
assert getattr(args, parseopt.Config._file_or_dir) == ['4', '2']
|
||||
args = parser.parse(['-R', '-S', '4', '2', '-R'])
|
||||
assert getattr(args, parseopt.Config._file_or_dir) == ['4', '2']
|
||||
assert args.R == True
|
||||
assert args.S == False
|
||||
args = parser.parse(['-R', '4', '-S', '2'])
|
||||
assert getattr(args, parseopt.Config._file_or_dir) == ['4', '2']
|
||||
assert args.R == True
|
||||
assert args.S == False
|
||||
|
||||
def test_parse_defaultgetter(self):
|
||||
def defaultget(option):
|
||||
if not hasattr(option, 'type'):
|
||||
@@ -158,3 +173,28 @@ def test_addoption_parser_epilog(testdir):
|
||||
#assert result.ret != 0
|
||||
result.stdout.fnmatch_lines(["hint: hello world", "hint: from me too"])
|
||||
|
||||
@pytest.mark.skipif("sys.version_info < (2,5)")
|
||||
def test_argcomplete(testdir):
|
||||
import os
|
||||
p = py.path.local.make_numbered_dir(prefix="test_argcomplete-",
|
||||
keep=None, rootdir=testdir.tmpdir)
|
||||
script = p._fastjoin('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
|
||||
# so we use bash
|
||||
fp.write('COMP_WORDBREAKS="$COMP_WORDBREAKS" $(which py.test) '
|
||||
'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')
|
||||
print dir(result), result.ret
|
||||
if result.ret == 255:
|
||||
# argcomplete not found
|
||||
assert True
|
||||
else:
|
||||
result.stdout.fnmatch_lines(["--funcargs", "--fulltrace"])
|
||||
|
||||
Reference in New Issue
Block a user