Merge pull request #62 from cpforbes/show-match

Add MATCH parameter to the show command to limit the list of modules.
This commit is contained in:
Patrick 2021-01-06 11:02:41 -08:00 committed by GitHub
commit 5eecbdcfcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

3
.gitignore vendored
View file

@ -110,3 +110,6 @@ venv.bak/
.vscode/
.DS_STORE
# emacs
*~

View file

@ -753,16 +753,24 @@ def update(ctx, all): # pragma: no cover
click.echo("None of the modules found on the device need an update.")
@click.argument("match", required=False, nargs=1)
@main.command()
def show(): # pragma: no cover
def show(match): # pragma: no cover
"""
Show a list of available modules in the bundle. These are modules which
*could* be installed on the device.
If MATCH is specified only matching modules will be listed.
"""
available_modules = get_bundle_versions()
module_names = sorted([m.replace(".py", "") for m in available_modules])
if match is not None:
module_names = [m for m in module_names if match in m]
click.echo("\n".join(module_names))
click.echo("{} packages.".format(len(module_names)))
click.echo(
"{} shown of {} packages.".format(len(module_names), len(available_modules))
)
# pylint: disable=too-many-locals,too-many-branches

View file

@ -28,6 +28,7 @@ import pytest
import json
import requests
from unittest import mock
from click.testing import CliRunner
def test_Module_init_file_module():
@ -637,3 +638,31 @@ def test_get_bundle_network_error():
mock_requests.get.assert_called_once_with(url, stream=True)
assert mock_logger.warning.call_count == 1
mock_requests.get().raise_for_status.assert_called_once_with()
def test_show_command():
runner = CliRunner()
TEST_BUNDLE_MODULES = ["one.py", "two.py", "three.py"]
with mock.patch("circup.get_bundle_versions", return_value=TEST_BUNDLE_MODULES):
result = runner.invoke(circup.show)
assert result.exit_code == 0
assert all([m.replace(".py", "") in result.output for m in TEST_BUNDLE_MODULES])
def test_show_match_command():
runner = CliRunner()
TEST_BUNDLE_MODULES = ["one.py", "two.py", "three.py"]
with mock.patch("circup.get_bundle_versions", return_value=TEST_BUNDLE_MODULES):
result = runner.invoke(circup.show, ["t"])
assert result.exit_code == 0
assert "one" not in result.output
def test_show_match_py_command():
# Check that py does not match the .py extention in the module names
runner = CliRunner()
TEST_BUNDLE_MODULES = ["one.py", "two.py", "three.py"]
with mock.patch("circup.get_bundle_versions", return_value=TEST_BUNDLE_MODULES):
result = runner.invoke(circup.show, ["py"])
assert result.exit_code == 0
assert "0 shown" in result.output