Skip to content

Commit

Permalink
Finalize refactoring of backend, including tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tekktrik committed Mar 13, 2024
1 parent 9ed76b1 commit 668d224
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions circfirm/backend/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def download_uf2(board_id: str, version: str, language: str = "en_US") -> None:

SUCCESS = 200
if response.status_code != SUCCESS:
if not list(uf2_file.parent.glob("*")):
uf2_file.parent.rmdir()
raise ConnectionError(f"Could not download the specified UF2 file:\n{url}")

uf2_file.parent.mkdir(parents=True, exist_ok=True)
Expand All @@ -70,7 +68,7 @@ def get_sorted_boards(board_id: Optional[str]) -> Dict[str, Dict[str, Set[str]]]
sorted_versions: Dict[str, Set[str]] = {}
if board_id is not None and board_id != board_folder:
continue
board_folder_full = get_board_folder(board_id)
board_folder_full = get_board_folder(board_folder)
for item in os.listdir(board_folder_full):
version, language = parse_firmware_info(item)
try:
Expand Down
4 changes: 2 additions & 2 deletions circfirm/cli/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def cache_list(board_id: Optional[str]) -> None:

if not board_list:
circfirm.cli.maybe_support("Versions have not been cached yet for any boards.")
sys.exit(0)
return

if board_id is not None and board_id not in board_list:
circfirm.cli.maybe_support(
f"No versions for board '{board_id}' are not cached."
)
sys.exit(0)
return

specified_board = board_id if board_id is not None else None
boards = circfirm.backend.cache.get_sorted_boards(specified_board)
Expand Down
5 changes: 4 additions & 1 deletion tests/cli/test_cli_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from click.testing import CliRunner

import circfirm
import circfirm.backend.cache
import tests.helpers
from circfirm.cli import cli

Expand Down Expand Up @@ -72,7 +73,9 @@ def test_cache_save() -> None:
cli, ["cache", "save", board, version, "--language", langauge]
)
assert result.exit_code == 0
expected_path = circfirm.backend.get_uf2_filepath(board, version, language=langauge)
expected_path = circfirm.backend.cache.get_uf2_filepath(
board, version, language=langauge
)
assert expected_path.exists()
shutil.rmtree(expected_path.parent.resolve())

Expand Down

0 comments on commit 668d224

Please sign in to comment.