Skip to content

Commit 8373f28

Browse files
committed
test(app): add more stub add tests.
Signed-off-by: Braden Mars <[email protected]>
1 parent d09183c commit 8373f28

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tests/app/test_stubs.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
from micropy.app import stubs as stubs_app
55
from micropy.app.stubs import stubs_app as app
6+
from micropy.exceptions import StubError, StubNotFound
67
from micropy.pyd import PyDevice
78
from micropy.stubs.source import StubSource
89
from pytest_mock import MockerFixture
@@ -73,9 +74,7 @@ def test_stubs_create__script_error(pyb_mock, micropy_obj, runner):
7374

7475
@pytest.mark.parametrize("force", [True, False])
7576
@pytest.mark.parametrize("micropy_obj", [MicroPyScenario(impl_add=False)], indirect=True)
76-
def test_stubs_add_success(
77-
mocker: MockerFixture, micropy_obj, runner, stubs_locator_mock, mock_repo, force
78-
):
77+
def test_stubs_add_success(micropy_obj, runner, stubs_locator_mock, mock_repo, force):
7978
stubs_locator_mock.ready.return_value.__enter__.return_value = "test-stub"
8079
args = ["add", "test-stub"]
8180
if force:
@@ -88,6 +87,24 @@ def test_stubs_add_success(
8887
micropy_obj.stubs.add.assert_called_once_with("test-stub", force=force)
8988

9089

90+
@pytest.mark.parametrize("micropy_obj", [MicroPyScenario(impl_add=False)], indirect=True)
91+
def test_stubs_add__not_found(micropy_obj, runner, stubs_locator_mock, mock_repo):
92+
micropy_obj.stubs.add.side_effect = StubNotFound()
93+
result = runner.invoke(app, ["add", "nonexistent-stub"], obj=micropy_obj)
94+
assert result.exit_code == 1
95+
assert "could not be found" in result.stdout
96+
stubs_locator_mock.ready.assert_called_once_with("nonexistent-stub")
97+
98+
99+
@pytest.mark.parametrize("micropy_obj", [MicroPyScenario(impl_add=False)], indirect=True)
100+
def test_stubs_add__invalid(micropy_obj, runner, stubs_locator_mock, mock_repo):
101+
micropy_obj.stubs.add.side_effect = StubError()
102+
result = runner.invoke(app, ["add", "invalid-stub"], obj=micropy_obj)
103+
assert result.exit_code == 1
104+
assert "is not a valid stub!" in result.stdout
105+
stubs_locator_mock.ready.assert_called_once_with("invalid-stub")
106+
107+
91108
@pytest.mark.parametrize(
92109
"micropy_obj", [MicroPyScenario(), MicroPyScenario(project_exists=False)], indirect=True
93110
)

0 commit comments

Comments
 (0)