Skip to content

Commit 022a041

Browse files
authored
Fix list command names from importlib (#189)
* Fix list command names from importlib The compatibility code for importlib.metadata returned names was not correct. Closes: #188 * Add test for pifpaf list command This adds a test that the pifpaf list command exites successfully and contains atleast one driver name.
1 parent 019aeac commit 022a041

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pifpaf/__main__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ def _format_multiple_exceptions(e, debug=False):
7373
DAEMONS = importlib.metadata.entry_points()['pifpaf.daemons']
7474

7575

76+
def _daemons_names():
77+
names = []
78+
if hasattr(DAEMONS, 'names'):
79+
names = DAEMONS.names
80+
else:
81+
for i in DAEMONS:
82+
names.append(i.name)
83+
return names
84+
85+
7686
@click.group()
7787
@click.option('--verbose/--quiet', help="Print mode details.")
7888
@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,
119129

120130
@main.command(name="list")
121131
def drivers_list():
122-
for n in DAEMONS.keys():
132+
for n in _daemons_names():
123133
click.echo(n)
124134

125135

126136
class RunGroup(click.MultiCommand):
127137
@staticmethod
128138
def list_commands(ctx):
129-
return DAEMONS.keys()
139+
return _daemons_names()
130140

131141
def get_command(self, ctx, name):
132142
params = [click.Argument(["command"], nargs=-1)]

pifpaf/tests/test_cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ def test_global_urls_variable_old_format(self):
147147
b"\"memcached://localhost:11217;memcached://localhost:11218\";",
148148
env[b"export PIFPAF_URLS"])
149149

150+
def test_list_command(self):
151+
c = subprocess.Popen(["pifpaf", "list"],
152+
bufsize=0,
153+
stdout=subprocess.PIPE)
154+
(stdout, stderr) = c.communicate()
155+
self.assertEqual(0, c.wait())
156+
self.assertIn(b'memcached', stdout)
157+
150158
def test_non_existing_command(self):
151159
# Keep PATH to just the one set by tox to run pifpaf
152160
self.useFixture(fixtures.EnvironmentVariable(

0 commit comments

Comments
 (0)