Skip to content

Commit

Permalink
Merge pull request #472 from zapta/develop
Browse files Browse the repository at this point in the history
Tests cleanup
  • Loading branch information
Obijuan authored Nov 22, 2024
2 parents 1f880d5 + b84aa82 commit b4fe559
Show file tree
Hide file tree
Showing 28 changed files with 622 additions and 372 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,18 @@
},
"justMyCode": false,
},
{
"name": "Apio test",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"-s",
"test/commands/test_build.py"
],
"console": "integratedTerminal",
"justMyCode": false,
"cwd": "${workspaceFolder}"
},
]
}
2 changes: 1 addition & 1 deletion apio/apio_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _load_resource(self, name: str, allow_custom: bool = False) -> dict:

if filepath.exists():
if allow_custom:
click.secho(f"Loading project's custom '{name}' file.")
click.secho(f"Loading custom '{name}'.")
return self._load_resource_file(filepath)

# -- Load the stock resource file from the APIO package.
Expand Down
9 changes: 2 additions & 7 deletions apio/commands/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from apio.commands import options


# )


# R0914: Too many local variables (17/15)
# pylint: disable=R0914
def list_boards(apio_ctx: ApioContext):
Expand Down Expand Up @@ -88,13 +85,11 @@ def list_boards(apio_ctx: ApioContext):
# -- bullet points.
click.secho(f"{board:<{max_board_name_len}} | {item_fpga}")

# -- Print the footer.
if config.terminal_mode():
# -- Print the Footer
click.secho(seperator_line)
click.secho(f"Total: {len(apio_ctx.boards)} boards")

# -- Help message
# click.secho(BOARDS_MSG, fg="green")
click.secho(f"Total of {util.plurality(apio_ctx.boards, 'board')}")


# ---------------------------
Expand Down
3 changes: 2 additions & 1 deletion apio/commands/fpgas.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def list_fpgas(apio_ctx: ApioContext):
# -- Print the Footer
if config.terminal_mode():
click.secho(seperator_line)
click.secho(f"Total: {len(apio_ctx.fpgas)} fpgas\n")

click.secho(f"Total of {util.plurality(apio_ctx.fpgas, 'fpga')}")


# ---------------------------
Expand Down
63 changes: 56 additions & 7 deletions test/commands/test_boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,65 @@
# -- apio boards entry point
from apio.commands.boards import cli as cmd_boards

CUSTOM_BOARDS = """
{
"my_custom_board": {
"name": "My Custom Board v3.1c",
"fpga": "iCE40-UP5K-SG48",
"programmer": {
"type": "iceprog"
},
"usb": {
"vid": "0403",
"pid": "6010"
},
"ftdi": {
"desc": "My Custom Board"
}
}
}
"""


def test_boards(clirunner, configenv, validate_cliresult):
"""Test "apio boards" command."""
def test_list_ok(click_cmd_runner, setup_apio_test_env, assert_apio_cmd_ok):
"""Test normal board listing with the apio's boards.json."""

with clirunner.isolated_filesystem():
with click_cmd_runner.isolated_filesystem():

# -- Config the environment (conftest.configenv())
configenv()
# -- Config the apio test environment
setup_apio_test_env()

# -- Execute "apio boards"
result = clirunner.invoke(cmd_boards)
validate_cliresult(result)
result = click_cmd_runner.invoke(cmd_boards)
assert_apio_cmd_ok(result)
# -- Note: pytest sees the piped version of the command's output.
# -- Run 'apio build' | cat' to reproduce it.
assert "Loading custom 'boards.json'" not in result.output
assert "alhambra-ii" in result.output
assert "my_custom_board" not in result.output
assert "Total of 1 board" not in result.output


def test_custom_board(
click_cmd_runner, setup_apio_test_env, assert_apio_cmd_ok
):
"""Test boards listing with a custom boards.json file."""

with click_cmd_runner.isolated_filesystem():

# -- Config the apio test environment
setup_apio_test_env()

# -- Write a custom boards.json file in the project's directory.
with open("boards.json", "w", encoding="utf-8") as f:
f.write(CUSTOM_BOARDS)

# -- Execute "apio boards"
result = click_cmd_runner.invoke(cmd_boards)
assert_apio_cmd_ok(result)
# -- Note: pytest sees the piped version of the command's output.
# -- Run 'apio build' | cat' to reproduce it.
assert "Loading custom 'boards.json'" in result.output
assert "alhambra-ii" not in result.output
assert "my_custom_board" in result.output
assert "Total of 1 board" in result.output
Loading

0 comments on commit b4fe559

Please sign in to comment.