1import builtins 2 3import pytest 4 5from xonsh.completers.python import python_signature_complete 6 7 8@pytest.fixture(autouse=True) 9def xonsh_execer_autouse(xonsh_builtins, xonsh_execer): 10 return xonsh_execer 11 12 13def foo(x, y, z): 14 pass 15 16 17def bar(wakka="wow", jawaka="mom"): 18 pass 19 20 21def baz(sonata, artica=True): 22 pass 23 24 25def always_true(x, y): 26 return True 27 28 29BASE_CTX = {"foo": foo, "bar": bar, "baz": baz} 30FOO_ARGS = {"x=", "y=", "z="} 31BAR_ARGS = {"wakka=", "jawaka="} 32BAZ_ARGS = {"sonata=", "artica="} 33 34 35@pytest.mark.parametrize( 36 "line, end, exp", 37 [ 38 ("foo(", 4, FOO_ARGS), # I have no idea why this one needs to be first 39 ("foo()", 3, set()), 40 ("foo()", 4, FOO_ARGS), 41 ("foo()", 5, set()), 42 ("foo(x, ", 6, FOO_ARGS), 43 ("foo(x, )", 6, FOO_ARGS), 44 ("bar()", 4, BAR_ARGS), 45 ("baz()", 4, BAZ_ARGS), 46 ("foo(bar(", 8, BAR_ARGS), 47 ("foo(bar()", 9, FOO_ARGS), 48 ("foo(bar())", 4, FOO_ARGS), 49 ], 50) 51def test_complete_python_signatures(line, end, exp): 52 ctx = dict(BASE_CTX) 53 obs = python_signature_complete("", line, end, ctx, always_true) 54 assert exp == obs 55