From 7cd0278edecdd0e8aa75d2c82cfd76382602e3e1 Mon Sep 17 00:00:00 2001 From: Mike Lin Date: Sun, 19 Nov 2023 01:44:28 -1000 Subject: [PATCH 1/3] update argcomplete dependency & test --- requirements.txt | 2 +- tests/test_cli_argcomplete.py | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) 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..d07cf537 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,42 @@ 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, "rb") as tr: + tr.seek(0) + return tr.read().decode().split(IFS) + @pytest.mark.skipif( + "PYTEST_CURRENT_TEST" in os.environ, + 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 +61,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) From b4e06435c2aff1439e730694bee7fc38853dc58d Mon Sep 17 00:00:00 2001 From: Mike Lin Date: Sun, 19 Nov 2023 02:05:32 -1000 Subject: [PATCH 2/3] fix --- tests/test_cli_argcomplete.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_cli_argcomplete.py b/tests/test_cli_argcomplete.py index d07cf537..ed09a63a 100644 --- a/tests/test_cli_argcomplete.py +++ b/tests/test_cli_argcomplete.py @@ -39,10 +39,7 @@ def run_completer( tr.seek(0) return tr.read().decode().split(IFS) - @pytest.mark.skipif( - "PYTEST_CURRENT_TEST" in os.environ, - reason="must run with unittest, not pytest, due to fd capture conflict", - ) + @pytest.mark.skip(reason="must run with unittest, not pytest, due to fd capture conflict") def test_completion(self): p = WDL.CLI.create_arg_parser() From a49ce8f493afb8a0c89b7d5d66e3f4c21dd5fac3 Mon Sep 17 00:00:00 2001 From: Mike Lin Date: Sun, 19 Nov 2023 02:15:10 -1000 Subject: [PATCH 3/3] polish --- tests/test_cli_argcomplete.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_cli_argcomplete.py b/tests/test_cli_argcomplete.py index ed09a63a..f80cc67b 100644 --- a/tests/test_cli_argcomplete.py +++ b/tests/test_cli_argcomplete.py @@ -35,9 +35,8 @@ def run_completer( completer(parser, output_stream=t, exit_method=sys.exit, **kwargs) if cm.exception.code != 0: raise Exception("Unexpected exit code %d" % cm.exception.code) - with open(t.name, "rb") as tr: - tr.seek(0) - return tr.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):