def test_7(self, bash, part_full_user, part_full_group): _, user = part_full_user partgroup, fullgroup = part_full_group completion = assert_complete(bash, "sudo chown %s:%s" % (user, partgroup)) assert completion == "%s:%s" % (user, fullgroup) assert completion.endswith(" ")
def test_github_issue_526_1(self, bash): r"""Regression tests for unprocessed escape sequences after quotes Ref [1] https://github.com/scop/bash-completion/pull/492#discussion_r637213822 Ref [2] https://github.com/scop/bash-completion/pull/526 The escape sequences in the local variable of "value" in "_quote_readline_by_ref" needs to be unescaped by passing it to printf as the format string. This causes a problem in the following case [where the spaces after "alpha\" is a TAB character inserted in the command string by "C-v TAB"]: $ echo alpha\ b[TAB] """ os.mkdir("./alpha\tbeta") assert (assert_complete( # Remark on "rendered_cmd": Bash aligns the last character 'b' # in the rendered cmd to an "8 x n" boundary using spaces. # Here, the command string is assumed to start from column 2 # because the width of PS1 (conftest.PS1 = '/@') is 2, bash, "echo alpha\\\026\tb", rendered_cmd="echo alpha\\ b", ) == "eta/")
def test_partial_hostname(self, bash, known_hosts): first_char, partial_hosts = partialize(bash, known_hosts) completion = assert_complete(bash, "ssh %s" % first_char) if len(completion) == 1: assert completion == partial_hosts[0][1:] else: assert completion == sorted(x for x in partial_hosts)
def test_partial_hosts(self, bash, hosts, prefix): first_char, partial_hosts = partialize(bash, hosts) completion = assert_complete(bash, f"xhost {prefix}{first_char}") if len(completion) == 1: assert completion == partial_hosts[0][1:] else: assert completion == sorted(f"{prefix}{x}" for x in partial_hosts)
def test_5(self, bash, part_full_user, part_full_group): _, user = part_full_user partgroup, fullgroup = part_full_group completion = assert_complete( bash, "chown %s:%s" % (user, partgroup)) assert completion.list == ["%s:%s" % (user, fullgroup)] assert completion.line.endswith(" ")
def test_install(self, bash, slapt_getrc): if not is_bash_type(bash, "slapt-get"): pytest.skip("slapt-get not found") completion = assert_complete( bash, "slapt-get -c %s --install " % slapt_getrc) assert completion == sorted( "abc-4-i686-1 ran-1.2-noarch-1 qwe-2.1-i486-1".split())
def test_partial_hosts(self, bash, hosts, prefix): first_char, partial_hosts = partialize(bash, hosts) completion = assert_complete(bash, "xhost %s%s" % (prefix, first_char)) if len(completion) == 1: assert completion == partial_hosts[0][1:] else: assert completion == sorted(x for x in partial_hosts)
def test_partial_hostname(self, bash, known_hosts): first_char, partial_hosts = partialize(bash, known_hosts) user = "******" completion = assert_complete(bash, f"finger {user}@{first_char}") if len(completion) == 1: assert completion == partial_hosts[0][1:] else: assert completion == [f"{user}@{x}" for x in partial_hosts]
def test_8(self, bash, part_full_user, part_full_group): """Test giving up on degenerate cases instead of spewing junk.""" _, user = part_full_user partgroup, _ = part_full_group for x in range(2, 5): completion = assert_complete( bash, "chown %s%s:%s" % (user, x * "\\", partgroup)) assert not completion
def test_8(self, bash, part_full_user, part_full_group): """Test giving up on degenerate cases instead of spewing junk.""" _, user = part_full_user partgroup, _ = part_full_group for x in range(2, 5): completion = assert_complete( bash, "chown %s%s:%s" % (user, x * "\\", partgroup)) assert not completion.list
def test_partial_hostname(self, bash, known_hosts): first_char, partial_hosts = partialize(bash, known_hosts) user = "******" completion = assert_complete(bash, "finger %s@%s" % (user, first_char)) if len(completion) == 1: assert completion == partial_hosts[0][1:] else: assert completion == ["%s@%s" % (user, x) for x in partial_hosts]
def test_7(self, bash, part_full_user, part_full_group): _, user = part_full_user partgroup, fullgroup = part_full_group completion = assert_complete( bash, "doas chown %s:%s" % (user, partgroup) ) assert completion == fullgroup[len(partgroup) :] assert completion.endswith(" ")
def test_10(self, request, bash, colonpath): if not is_bash_type(bash, "man"): pytest.skip("Command not found") completion = assert_complete( bash, "man Bash::C", env=dict(MANPATH="%s:%s/man" % (TestMan.manpath, colonpath)), ) assert completion == "ompletion"
def test_7(self, bash, part_full_group): """Test preserving special chars in $prefix$partgroup<TAB>.""" part, full = part_full_group for prefix in (r"funky\ user:"******"funky.user:"******"funky\.user:"******"fu\ nky.user:"******"f\ o\ o\.\bar:", r"foo\_b\ a\.r\ :"): completion = assert_complete(bash, "chown %s%s" % (prefix, part)) assert completion == "%s%s" % (prefix, full) assert completion.output.endswith(" ")
def test_7(self, bash, part_full_group): """Test preserving special chars in $prefix$partgroup<TAB>.""" part, full = part_full_group for prefix in (r"funky\ user:"******"funky.user:"******"funky\.user:"******"fu\ nky.user:"******"f\ o\ o\.\bar:", r"foo\_b\ a\.r\ :"): completion = assert_complete( bash, "chown %s%s" % (prefix, part)) assert completion.list == ["%s%s" % (prefix, full)] assert completion.line.endswith(" ")
def test_10(self, request, bash, colonpath): with bash_env_saved(bash) as bash_env: bash_env.write_env( "MANPATH", "%s:%s/man" % (TestMan.manpath, colonpath), quote=False, ) completion = assert_complete(bash, "man Bash::C") assert completion == "ompletion"
def test_1(self, bash): files, dirs = create_dummy_filedirs( ".eps .EPS .pdf .PDF .ps .PS .txt".split(), "foo".split(), ) completion = assert_complete(bash, "kpdf ") assert completion == [ x for x in sorted(files + ["%s/" % d for d in dirs]) if x.lower() != ".txt" ]
def test_1(self, bash): files, dirs = create_dummy_filedirs( (".dvi .DVI .dvi.bz2 .DVI.bz2 .dvi.gz .DVI.gz .dvi.Z .DVI.Z " ".txt").split(), "foo".split(), ) completion = assert_complete(bash, "kdvi ") assert completion == [ x for x in sorted(files + ["%s/" % d for d in dirs]) if x.lower() != ".txt" ]
def test_1(self, bash, setup_fixture): fixture_dir, files, dirs = setup_fixture assert_bash_exec(bash, "cd %s" % shlex.quote(str(fixture_dir))) try: completion = assert_complete(bash, "kdvi ") finally: assert_bash_exec(bash, "cd -", want_output=None) assert completion == [ x for x in sorted(files + ["%s/" % d for d in dirs]) if x.lower() != ".txt" ]
def test_3(self, bash): """~part should complete to ~full<SPACE> if home dir does not exist.""" res = assert_bash_exec(bash, "for u in $(compgen -u); do " "eval test -d ~$u || echo $u; unset u; done", want_output=True).strip().split() part_full = find_unique_completion_pair(res) if not part_full: pytest.skip("No suitable test user found") return part, full = part_full completion = assert_complete(bash, "ls ~%s" % part) assert completion.list == ["~%s" % full] assert completion.line.endswith(" ")
def test_3(self, bash): """~part should complete to ~full<SPACE> if home dir does not exist.""" res = assert_bash_exec( bash, "for u in $(compgen -u); do " "eval test -d ~$u || echo $u; unset u; done", want_output=True).strip().split() part_full = find_unique_completion_pair(res) if not part_full: pytest.skip("No suitable test user found") return part, full = part_full completion = assert_complete(bash, "ls ~%s" % part) assert completion.list == ["~%s" % full] assert completion.line.endswith(" ")
def test_2(self, bash, functions, cmd, expected_completion): """Test meta-completion for completion functions that signal that completion should be retried (i.e. change compspec and return 124). cmd2: The case when the completion spec is overwritten by the one that contains "-F func" cmd3: The case when the completion spec is overwritten by the one without "-F func". cmd4: The case when the completion spec is removed, in which we expect no completions. This mimics the behavior of Bash's progcomp for the exit status 124. cmd5: The case when the completion spec is unchanged. The retry should be attempted at most once to avoid infinite loops. COMPREPLY should be cleared before the retry. """ assert assert_complete(bash, "meta %s " % cmd) == expected_completion
def test_1(self, bash): files, dirs = create_dummy_filedirs( (".bmp .BMP .cbr .CBR .cbz .CBZ .djv .DJV .djvu .DJVU .dvi " ".DVI .dvi.bz2 .dvi.BZ2 .DVI.bz2 .DVI.BZ2 .dvi.gz .dvi.GZ " ".DVI.gz .DVI.GZ .eps .EPS .eps.bz2 .eps.BZ2 .EPS.bz2 " ".EPS.BZ2 .eps.gz .eps.GZ .EPS.gz .EPS.GZ .gif .GIF .ico .ICO " ".jpeg .JPEG .jpg .JPG .miff .MIFF .pbm .PBM .pcx .PCX .pdf " ".PDF .pdf.bz2 .pdf.BZ2 .PDF.bz2 .PDF.BZ2 .pdf.gz .pdf.GZ " ".PDF.gz .PDF.GZ .pgm .PGM .png .PNG .pnm .PNM .ppm .PPM .ps " ".PS .ps.bz2 .ps.BZ2 .PS.bz2 .PS.BZ2 .ps.gz .ps.GZ .PS.gz " ".PS.GZ .tga .TGA .tif .TIF .tiff .TIFF .txt .xpm .XPM .xwd" ".XWD").split(), "foo".split(), ) completion = assert_complete(bash, "evince ") assert completion == [ x for x in sorted(files + ["%s/" % d for d in dirs]) if x.lower() != ".txt" ]
def test_1(self, bash, functions): assert_complete(bash, 'co1 "/tmp/aaa bbb" ') assert_bash_exec(bash, "! complete -p aaa", want_output=None)
def test_9(self, bash, part_full_group): """Test graceful fail on colon in user/group name.""" part, _ = part_full_group completion = assert_complete(bash, "chown foo:bar:%s" % part) assert not completion.list
def test_7(self, bash, part_full_group, prefix): """Test preserving special chars in $prefix$partgroup<TAB>.""" part, full = part_full_group completion = assert_complete(bash, "chown %s%s" % (prefix, part)) assert completion == "%s%s" % (prefix, full) assert completion.output.endswith(" ")
def test_6(self, bash, part_full_group): part, full = part_full_group completion = assert_complete(bash, "chown dot.user:%s" % part) assert completion.list == ["dot.user:%s" % full] assert completion.line.endswith(" ")
def test_6(self, bash, functions, funcname): completion = assert_complete(bash, r"%s a\$" % funcname, cwd="_filedir") assert completion == "b/"
def test_4(self, bash, part_full_user): part, full = part_full_user completion = assert_complete(bash, "chown %s" % part) assert completion == full assert completion.endswith(" ")
def test_8(self, bash, part_full_group): part, full = part_full_group completion = assert_complete(bash, "sudo chown dot.user:%s" % part) assert completion == full[len(part) :] assert completion.endswith(" ")
def test_9(self, bash, part_full_group, prefix): """Test preserving special chars in $prefix$partgroup<TAB>.""" part, full = part_full_group completion = assert_complete(bash, "sudo chown %s%s" % (prefix, part)) assert completion == full[len(part) :] assert completion.endswith(" ")
def test_hosts(self, bash, hosts, prefix): completion = assert_complete(bash, "xhost %s" % prefix) assert completion == ["%s%s" % (prefix, x) for x in hosts]
def test_4(self, bash, part_full_user): part, full = part_full_user completion = assert_complete(bash, "chown %s" % part) assert completion.list == [full] assert completion.line.endswith(" ")
def test_6(self, bash, part_full_group): part, full = part_full_group completion = assert_complete(bash, "chown dot.user:%s" % part) assert completion == "dot.user:%s" % full assert completion.output.endswith(" ")
def test_7(self, bash, functions, funcname): completion = assert_complete(bash, r"%s 'ab/" % funcname, cwd="_filedir") assert completion == "e'"
def test_9(self, bash, part_full_group): """Test graceful fail on colon in user/group name.""" part, _ = part_full_group completion = assert_complete(bash, "chown foo:bar:%s" % part) assert not completion
def test_6(self, bash, part_full_user): part, full = part_full_user completion = assert_complete(bash, "sudo chown %s" % part) assert completion == full[len(part) :] assert completion.endswith(" ")