Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update argcomplete dependency & test #662

Merged
merged 3 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ regex>=2020.4.4
xdg>=2.0.0
docker>=3.4.0
PyYAML>=5.4.1,<7
argcomplete~=1.12
argcomplete>=3,<4
pygtail~=0.14
coloredlogs>=15,<16
python-json-logger>=2,<3
Expand Down
30 changes: 18 additions & 12 deletions tests/test_cli_argcomplete.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
import sys
import unittest
import subprocess
import pytest
import os
from tempfile import NamedTemporaryFile
import argcomplete
import contextlib
from .context import WDL

IFS = "\013"
COMP_WORDBREAKS = " \t\n\"'><=;|&(:"


class TestArgcomplete(unittest.TestCase):
def setUp(self):
self._os_environ = os.environ
os.environ = os.environ.copy()
os.environ["_ARGCOMPLETE"] = "1"
os.environ["IFS"] = IFS
os.environ["_ARGCOMPLETE_COMP_WORDBREAKS"] = COMP_WORDBREAKS
#os.environ["_ARC_DEBUG"] = "yes"
# os.environ["_ARC_DEBUG"] = "yes"
argcomplete.debug_stream = sys.stderr

def tearDown(self):
os.environ = self._os_environ

def run_completer(self, parser, command, point=None, completer=argcomplete.autocomplete, **kwargs):
def run_completer(
self, parser, command, point=None, completer=argcomplete.autocomplete, **kwargs
):
if point is None:
point = str(len(command))
with NamedTemporaryFile() as t:
with NamedTemporaryFile(mode="w") as t:
os.environ["COMP_LINE"] = command
os.environ["COMP_POINT"] = point
with self.assertRaises(SystemExit) as cm:
completer(parser, output_stream=t, exit_method=sys.exit, **kwargs)
if cm.exception.code != 0:
raise Exception("Unexpected exit code %d" % cm.exception.code)
t.seek(0)
return t.read().decode().split(IFS)
with open(t.name, "r") as tr:
return tr.read().split(IFS)

@pytest.mark.skip(reason="must run with unittest, not pytest, due to fd capture conflict")
def test_completion(self):
if "PYTEST_CURRENT_TEST" in os.environ:
# due to conflict with pytest fd capture, this case has to run under unittest only
return
p = WDL.CLI.create_arg_parser()

completions = self.run_completer(p, "miniwdl r")
self.assertEqual(set(completions), {"run", "run_self_test", "run-self-test"})

completions = self.run_completer(p, "miniwdl run --path test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/tasks test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/assemble_refbased.wdl ")
completions = self.run_completer(
p,
"miniwdl run --path test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/tasks test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/assemble_refbased.wdl ",
)
completions = set(completions)
self.assertTrue("--json" in completions)
self.assertTrue("refine_2x_and_plot.assembly_fasta=" in completions)
Expand All @@ -54,7 +57,10 @@ def test_completion(self):
self.assertTrue("refine_2x_and_plot.refine2_min_coverage=" not in completions)

# suggest optional inputs only when specifically prefixed
completions = self.run_completer(p, "miniwdl run --path test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/tasks test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/assemble_refbased.wdl refine_2x_and_plot.refine2_min_")
completions = self.run_completer(
p,
"miniwdl run --path test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/tasks test_corpi/broadinstitute/viral-ngs/pipes/WDL/workflows/assemble_refbased.wdl refine_2x_and_plot.refine2_min_",
)
completions = set(completions)
self.assertTrue("refine_2x_and_plot.assembly_fasta=" not in completions)
self.assertTrue("refine_2x_and_plot.refine2_min_coverage=" in completions)
Loading