Skip to content

Commit

Permalink
More coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Hook25 committed Jan 23, 2025
1 parent ebe2836 commit 0d3e1b9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
7 changes: 3 additions & 4 deletions checkbox-ng/plainbox/impl/session/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,10 +1318,9 @@ def _strtobool(self, val):

def _parse_value(self, m, value):
try:
if m.value_type == "bool":
return self._strtobool(value)
elif m.value_type == "natural":
return int(value)
return {"bool": self._strtobool, "natural": int}[m.value_type](
value
)
except ValueError:
raise SystemExit(

Check warning on line 1325 in checkbox-ng/plainbox/impl/session/assistant.py

View check run for this annotation

Codecov / codecov/patch

checkbox-ng/plainbox/impl/session/assistant.py#L1325

Added line #L1325 was not covered by tests
("Invalid manifest {} value '{}'").format(
Expand Down
35 changes: 32 additions & 3 deletions checkbox-ng/plainbox/impl/session/test_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,24 @@ def test_use_alternate_selection(self, mock_get_providers):
"plainbox.impl.session.assistant.UsageExpectation",
new=mock.MagicMock(),
)
@mock.patch("os.path.isfile", return_value=False)
@mock.patch(
"plainbox.impl.session.assistant.open",
new=mock.mock_open(read_data="{}"),
)
@mock.patch("os.path.isfile", return_value=True)
def test_get_manifest_repr(self, isfile, _):
self_mock = mock.MagicMock()
self_mock._parse_value = partial(
SessionAssistant._parse_value, self_mock
)

selected_unit = mock.MagicMock(id="selected_manifest", is_hidden=False)
selected_unit = mock.MagicMock(
id="selected_manifest", is_hidden=False, value_type="bool"
)
selected_unit.Meta.name = "manifest entry"

selected_but_hidden = mock.MagicMock(
id="_hidden_manifest", is_hidden=True
id="_hidden_manifest", is_hidden=True, value_type="bool"
)
selected_but_hidden.Meta.name = "manifest entry"

Expand Down Expand Up @@ -412,3 +418,26 @@ def test__strtobool(self, _):

with self.assertRaises(ValueError):
strtobool(None, "value")

def test__parse_value(self, _):
self_mock = mock.MagicMock()

SessionAssistant._parse_value(
self_mock, mock.MagicMock(value_type="bool"), "t"
)

self.assertTrue(self_mock._strtobool.called)

self.assertEqual(
SessionAssistant._parse_value(
self_mock, mock.MagicMock(value_type="natural"), "1"
),
1,
)

with self.assertRaises(KeyError):
SessionAssistant._parse_value(
self_mock,
mock.MagicMock(value_type="weird new invention"),
"abc",
)

0 comments on commit 0d3e1b9

Please sign in to comment.