Skip to content

Commit

Permalink
Update boards subcommand name for query command
Browse files Browse the repository at this point in the history
  • Loading branch information
tekktrik committed Mar 14, 2024
1 parent 3e3b3f5 commit 6977634
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion circfirm/backend/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_rate_limit() -> Tuple[int, int, datetime.datetime]:
return available, total, reset_time


def get_board_list(token: str) -> List[str]:
def get_board_id_list(token: str) -> List[str]:
"""Get a list of CircuitPython boards."""
boards = set()
headers = BASE_REQUESTS_HEADERS.copy()
Expand Down
8 changes: 4 additions & 4 deletions circfirm/cli/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def cli():
"""Query things like latest versions and board lists."""


@cli.command(name="boards")
@cli.command(name="board-ids")
@click.option("-r", "--regex", default=".*", help="Regex pattern to use for board IDs")
def query_boards(regex: str) -> None:
def query_board_ids(regex: str) -> None:
"""Query the local CircuitPython board list."""
settings = circfirm.cli.get_settings()
gh_token = settings["token"]["github"]
Expand All @@ -41,11 +41,11 @@ def query_boards(regex: str) -> None:
if do_output:
boards = circfirm.cli.announce_and_await(
"Fetching boards list",
circfirm.backend.github.get_board_list,
circfirm.backend.github.get_board_id_list,
args=(gh_token,),
)
else:
boards = circfirm.backend.github.get_board_list(gh_token)
boards = circfirm.backend.github.get_board_id_list(gh_token)
except ValueError as err:
raise click.ClickException(err.args[0])
except requests.ConnectionError as err:
Expand Down
6 changes: 3 additions & 3 deletions docs/commands/query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ See ``circfirm query --help`` and ``circfirm query [command] --help`` for more i
Querying Board IDs
------------------

You can query a list of valid board IDs from the CircuitPython GitHub repository using ``circfirm query boards``.
You can query a list of valid board IDs from the CircuitPython GitHub repository using ``circfirm query board-ids``.

You can use the ``--regex`` option to further select boards from the list matching a provided regex pattern.
The pattern will be searched for **ANYWHERE** in the board ID (e.g., "hello" **would** match "123hello123") unless
Expand All @@ -27,10 +27,10 @@ the pattern specifies otherwise.
.. code-block:: shell
# List all board IDs
circfirm query boards
circfirm query board-ids
# List all board IDs containing the phrase "pico"
circfirm query boards --regex pico
circfirm query board-ids --regex pico
Querying Board Versions
-----------------------
Expand Down
6 changes: 3 additions & 3 deletions tests/backend/test_backend_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def test_get_board_list() -> None:
"""Tests the ability of the backend to get the board list."""
# Test successful retrieval
token = os.environ["GH_TOKEN"]
board_list = circfirm.backend.github.get_board_list(token)
expected_board_list = tests.helpers.get_boards_from_git()
board_list = circfirm.backend.github.get_board_id_list(token)
expected_board_list = tests.helpers.get_board_ids_from_git()
assert board_list == expected_board_list

# Test unsuccessful retrieval
with pytest.raises(ValueError):
circfirm.backend.github.get_board_list("badtoken")
circfirm.backend.github.get_board_id_list("badtoken")


def test_get_rate_limit() -> None:
Expand Down
16 changes: 8 additions & 8 deletions tests/cli/test_cli_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def simulate_no_connection(arg: str) -> NoReturn:
raise requests.ConnectionError


def test_query_boards(monkeypatch: pytest.MonkeyPatch) -> None:
def test_query_board_ids(monkeypatch: pytest.MonkeyPatch) -> None:
"""Tests the ability to query the boards using the CLI."""
# Test an unauthenticated request with supporting text
boards = tests.helpers.get_boards_from_git()
pre_expected_output = "".join([f"{board}\n" for board in boards])
board_ids = tests.helpers.get_board_ids_from_git()
pre_expected_output = "".join([f"{board}\n" for board in board_ids])
expected_output = "\n".join(
[
"Boards list will now be synchronized with the git repository.",
Expand All @@ -40,7 +40,7 @@ def test_query_boards(monkeypatch: pytest.MonkeyPatch) -> None:
]
)

result = RUNNER.invoke(cli, ["query", "boards"])
result = RUNNER.invoke(cli, ["query", "board-ids"])
assert result.exit_code == 0
assert result.output == expected_output

Expand All @@ -51,24 +51,24 @@ def test_query_boards(monkeypatch: pytest.MonkeyPatch) -> None:
assert result.exit_code == 0
result = RUNNER.invoke(cli, ["config", "edit", "output.supporting.silence", "true"])
assert result.exit_code == 0
result = RUNNER.invoke(cli, ["query", "boards"])
result = RUNNER.invoke(cli, ["query", "board-ids"])
assert result.exit_code == 0
assert result.output == pre_expected_output

# Test a request with a faulty token
result = RUNNER.invoke(cli, ["config", "edit", "token.github", "badtoken"])
assert result.exit_code == 0
result = RUNNER.invoke(cli, ["query", "boards"])
result = RUNNER.invoke(cli, ["query", "board-ids"])
assert result.exit_code != 0

result = RUNNER.invoke(cli, ["config", "reset"])
assert result.exit_code == 0

# Tests failure when cannot fetch results due to no network connection
monkeypatch.setattr(
circfirm.backend.github, "get_board_list", simulate_no_connection
circfirm.backend.github, "get_board_id_list", simulate_no_connection
)
result = RUNNER.invoke(cli, ["query", "boards"])
result = RUNNER.invoke(cli, ["query", "board-ids"])
assert result.exit_code != 0
assert (
result.output.split("\n")[-2]
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def copy_firmwares() -> None:
)


def get_boards_from_git() -> List[str]:
def get_board_ids_from_git() -> List[str]:
"""Get a list of board IDs from the sandbox git repository."""
ports_path = pathlib.Path("tests/sandbox/circuitpython")
board_paths = ports_path.glob("ports/*/boards/*")
Expand Down

0 comments on commit 6977634

Please sign in to comment.