From 2b9face1d6a7a4aacc0c4ea1d39e93c95a762563 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Fri, 11 Oct 2024 14:09:56 +0200 Subject: [PATCH 1/2] Fix list command names from importlib The compatibility code for importlib.metadata returned names was not correct. Closes: #188 --- pifpaf/__main__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pifpaf/__main__.py b/pifpaf/__main__.py index 3ff4b49..ccb93b2 100644 --- a/pifpaf/__main__.py +++ b/pifpaf/__main__.py @@ -73,6 +73,16 @@ def _format_multiple_exceptions(e, debug=False): DAEMONS = importlib.metadata.entry_points()['pifpaf.daemons'] +def _daemons_names(): + names = [] + if hasattr(DAEMONS, 'names'): + names = DAEMONS.names + else: + for i in DAEMONS: + names.append(i.name) + return names + + @click.group() @click.option('--verbose/--quiet', help="Print mode details.") @click.option('--debug', help="Show tracebacks on errors.", is_flag=True) @@ -119,14 +129,14 @@ def main(ctx, verbose=False, debug=False, log_file=None, @main.command(name="list") def drivers_list(): - for n in DAEMONS.keys(): + for n in _daemons_names(): click.echo(n) class RunGroup(click.MultiCommand): @staticmethod def list_commands(ctx): - return DAEMONS.keys() + return _daemons_names() def get_command(self, ctx, name): params = [click.Argument(["command"], nargs=-1)] From 4546eafd4f3695286b839a130f776e27969eba74 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Fri, 11 Oct 2024 14:15:18 +0200 Subject: [PATCH 2/2] Add test for pifpaf list command This adds a test that the pifpaf list command exites successfully and contains atleast one driver name. --- pifpaf/tests/test_cli.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pifpaf/tests/test_cli.py b/pifpaf/tests/test_cli.py index ccde70b..bc53c4e 100644 --- a/pifpaf/tests/test_cli.py +++ b/pifpaf/tests/test_cli.py @@ -147,6 +147,14 @@ def test_global_urls_variable_old_format(self): b"\"memcached://localhost:11217;memcached://localhost:11218\";", env[b"export PIFPAF_URLS"]) + def test_list_command(self): + c = subprocess.Popen(["pifpaf", "list"], + bufsize=0, + stdout=subprocess.PIPE) + (stdout, stderr) = c.communicate() + self.assertEqual(0, c.wait()) + self.assertIn(b'memcached', stdout) + def test_non_existing_command(self): # Keep PATH to just the one set by tox to run pifpaf self.useFixture(fixtures.EnvironmentVariable(