diff --git a/requirements.txt b/requirements.txt index 7b5b682c..0f9b89e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tests/test_cli_argcomplete.py b/tests/test_cli_argcomplete.py index 49c8db20..f80cc67b 100644 --- a/tests/test_cli_argcomplete.py +++ b/tests/test_cli_argcomplete.py @@ -1,15 +1,15 @@ 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 @@ -17,35 +17,38 @@ def setUp(self): 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) @@ -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)