Skip to content

Commit

Permalink
mpflash: consistent naming of params with mpflash
Browse files Browse the repository at this point in the history
Signed-off-by: Jos Verlinde <[email protected]>
  • Loading branch information
Josverl committed Jun 30, 2024
1 parent da4f122 commit 63be0a7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/stubber/commands/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@click.version_option(package_name="micropython-stubber", prog_name="micropython-stubber✏️ ")
@click.option(
"-V",
"-v",
"-V",
"--verbose",
count=True,
default=0,
Expand Down
2 changes: 1 addition & 1 deletion src/stubber/commands/get_frozen_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@click.option(
"--version",
"--Version",
"-V",
"-v",
"version",
default="",
# default=[CONFIG.stable_version],
Expand Down
2 changes: 1 addition & 1 deletion src/stubber/commands/get_mcu_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@stubber_cli.command(name="get-mcu-stubs")
@click.option(
"--variant",
"-v",
# "-v",
type=click.Choice(["Full", "Mem", "DB"], case_sensitive=False),
default="DB",
show_default=True,
Expand Down
3 changes: 1 addition & 2 deletions src/stubber/commands/merge_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
@click.option("--family", default="micropython", type=str, show_default=True)
@click.option(
"--version",
"--Version",
"-V",
"-v",
"versions",
multiple=True,
default=["all"],
Expand Down
3 changes: 1 addition & 2 deletions src/stubber/commands/publish_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
@click.option("--family", default="micropython", type=str, show_default=True)
@click.option(
"--version",
"--Version",
"-V",
"-v",
"versions",
multiple=True,
default=[CONFIG.stable_version],
Expand Down
3 changes: 1 addition & 2 deletions src/stubber/commands/variants_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

@click.option(
"--version",
"--Version",
"-V",
"-v",
"version",
default=CONFIG.stable_version,
show_default=True,
Expand Down
61 changes: 43 additions & 18 deletions tests/commandline/stubber_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,19 @@ def test_cmd_switch(mocker: MockerFixture, params: List[str]):
mocker.patch("stubber.commands.clone_cmd.git.clone", autospec=True, return_value=0)
m_fetch = mocker.patch("stubber.commands.clone_cmd.git.fetch", autospec=True, return_value=0)

m_switch_branch = mocker.patch("stubber.commands.clone_cmd.git.switch_branch", autospec=True, return_value=0)
m_switch_tag = mocker.patch("stubber.commands.clone_cmd.git.switch_tag", autospec=True, return_value=0)
mocker.patch("stubber.commands.clone_cmd.git.get_local_tag", autospec=True, return_value="v1.42")
m_switch_branch = mocker.patch(
"stubber.commands.clone_cmd.git.switch_branch", autospec=True, return_value=0
)
m_switch_tag = mocker.patch(
"stubber.commands.clone_cmd.git.switch_tag", autospec=True, return_value=0
)
mocker.patch(
"stubber.commands.clone_cmd.git.get_local_tag", autospec=True, return_value="v1.42"
)

m_match = mocker.patch("stubber.utils.repos.match_lib_with_mpy", autospec=True) # Moved to other module
m_match = mocker.patch(
"stubber.utils.repos.match_lib_with_mpy", autospec=True
) # Moved to other module

mocker.patch("stubber.commands.clone_cmd.Path.exists", return_value=True)
result = runner.invoke(stubber.stubber_cli, params)
Expand Down Expand Up @@ -134,9 +142,15 @@ def test_cmd_switch_version(mocker: MockerFixture, version: str):
m_clone = mocker.patch("stubber.commands.clone_cmd.git.clone", autospec=True, return_value=0)
m_fetch = mocker.patch("stubber.commands.clone_cmd.git.fetch", autospec=True, return_value=0)

m_switch = mocker.patch("stubber.commands.clone_cmd.git.switch_branch", autospec=True, return_value=0)
m_checkout = mocker.patch("stubber.commands.clone_cmd.git.checkout_tag", autospec=True, return_value=0)
m_get_l_tag = mocker.patch("stubber.commands.clone_cmd.git.get_local_tag", autospec=True, return_value="v1.42")
m_switch = mocker.patch(
"stubber.commands.clone_cmd.git.switch_branch", autospec=True, return_value=0
)
m_checkout = mocker.patch(
"stubber.commands.clone_cmd.git.checkout_tag", autospec=True, return_value=0
)
m_get_l_tag = mocker.patch(
"stubber.commands.clone_cmd.git.get_local_tag", autospec=True, return_value="v1.42"
)

m_match = mocker.patch("stubber.utils.repos.match_lib_with_mpy", autospec=True)

Expand Down Expand Up @@ -204,7 +218,9 @@ def test_cmd_stub(mocker: MockerFixture):

m_generate.assert_called_once_with(Path("."))
m_postprocessing.assert_called_once()
m_postprocessing.assert_called_once_with([Path(".")], stubgen=False, black=True, autoflake=False)
m_postprocessing.assert_called_once_with(
[Path(".")], stubgen=False, black=True, autoflake=False
)
assert result.exit_code == 0


Expand All @@ -216,13 +232,17 @@ def test_cmd_get_frozen(mocker: MockerFixture, tmp_path: Path):
# check basic command line sanity check
runner = CliRunner()

m_get_local_tag = mocker.patch("stubber.basicgit.get_local_tag", autospec=True, return_value="v1.42")
m_get_local_tag = mocker.patch(
"stubber.basicgit.get_local_tag", autospec=True, return_value="v1.42"
)

m_freeze_any = mocker.patch("stubber.commands.get_frozen_cmd.freeze_any", autospec=True)
m_post = mocker.patch("stubber.utils.do_post_processing", autospec=True)

# fake run - need to ensure that there is a destination folder
result = runner.invoke(stubber.stubber_cli, ["get-frozen", "--stub-folder", tmp_path.as_posix()])
result = runner.invoke(
stubber.stubber_cli, ["get-frozen", "--stub-folder", tmp_path.as_posix()]
)
assert result.exit_code == 0
# FIXME : test fails in CI
m_freeze_any.assert_called_once()
Expand All @@ -243,8 +263,6 @@ def test_cmd_get_frozen(mocker: MockerFixture, tmp_path: Path):
# )




##########################################################################################
# get-core
##########################################################################################
Expand Down Expand Up @@ -278,36 +296,41 @@ def test_cmd_get_docstubs(mocker: MockerFixture, tmp_path: Path):
# check basic command line sanity check
runner = CliRunner()

m_get_l_tag = mocker.patch("stubber.basicgit.get_local_tag", autospec=True, return_value="v1.42")
m_get_l_tag = mocker.patch(
"stubber.basicgit.get_local_tag", autospec=True, return_value="v1.42"
)

# from stubber.commands.get_docstubs import generate_from_rst
m_generate = mocker.patch("stubber.commands.get_docstubs_cmd.generate_from_rst", autospec=True)

# fake run
result = runner.invoke(stubber.stubber_cli, ["get-docstubs", "--stub-folder", tmp_path.as_posix()])
result = runner.invoke(
stubber.stubber_cli, ["get-docstubs", "--stub-folder", tmp_path.as_posix()]
)
assert result.exit_code == 0
# process is called
assert m_generate.call_count == 1
m_generate.assert_called_once()
assert m_get_l_tag.call_count >= 1



##########################################################################################
# merge
##########################################################################################
@pytest.mark.parametrize(
"cmdline",
[
["merge", "-V", "1.18", "-V", "1.19"],
["merge", "-v", "1.18", "-v", "1.19"],
["merge", "--version", "latest"],
],
)
@pytest.mark.mocked
def test_cmd_merge(mocker: MockerFixture, cmdline: List[str]):
runner = CliRunner()
# from stubber.commands.clone import git
m_merge_docstubs = mocker.patch("stubber.commands.merge_cmd.merge_all_docstubs", autospec=True, return_value={})
m_merge_docstubs = mocker.patch(
"stubber.commands.merge_cmd.merge_all_docstubs", autospec=True, return_value={}
)
result = runner.invoke(stubber.stubber_cli, cmdline)
assert result.exit_code == 0
m_merge_docstubs.assert_called_once()
Expand All @@ -327,7 +350,9 @@ def test_cmd_merge(mocker: MockerFixture, cmdline: List[str]):
def test_cmd_publish(mocker: MockerFixture, cmdline: List[str]):
runner = CliRunner()
# from stubber.commands.clone import git
m_publish_multiple = mocker.patch("stubber.commands.publish_cmd.publish_multiple", autospec=True, return_value={})
m_publish_multiple = mocker.patch(
"stubber.commands.publish_cmd.publish_multiple", autospec=True, return_value={}
)
result = runner.invoke(stubber.stubber_cli, cmdline)
assert result.exit_code == 0
m_publish_multiple.assert_called_once()

0 comments on commit 63be0a7

Please sign in to comment.