Skip to content

Commit

Permalink
Set default prefs in only one place
Browse files Browse the repository at this point in the history
  • Loading branch information
claui committed Jul 30, 2024
1 parent 6123477 commit 750be80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
13 changes: 0 additions & 13 deletions itchcraft/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""The primary module in itchcraft."""

from contextlib import ExitStack
from dataclasses import dataclass

from . import devices, prefs
from .errors import CliError
Expand All @@ -17,25 +16,13 @@
logger = get_logger(__name__)


@dataclass(frozen=True)
class StartParams:
"""Parameters for the `start` method or CLI subcommand."""

duration: CliEnum[Duration] = prefs.default(Duration)
generation: CliEnum[Generation] = prefs.default(Generation)
skin_sensitivity: CliEnum[SkinSensitivity] = prefs.default(
SkinSensitivity
)


# pylint: disable=too-few-public-methods
class Api:
"""Tech demo for interfacing with heat-based USB insect bite healers"""

# pylint: disable=no-self-use
def start(
self,
# Re-enumerating all the `StartParams` fields to make Fire happy
duration: CliEnum[Duration] = prefs.default(Duration),
generation: CliEnum[Generation] = prefs.default(Generation),
skin_sensitivity: CliEnum[SkinSensitivity] = prefs.default(
Expand Down
43 changes: 27 additions & 16 deletions tests/test_heat_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@
AbstractContextManager,
nullcontext,
)
from dataclasses import asdict
from typing import Optional, Union
from typing import Optional, TypedDict, Union
from unittest.mock import ANY

import pytest
import pytest_mock

from itchcraft import Api, devices
from itchcraft.api import StartParams
from itchcraft.backend import BulkTransferDevice
from itchcraft.device import Device
from itchcraft.heat_it import HeatItDevice
from itchcraft.prefs import Duration, Generation, SkinSensitivity
from itchcraft.prefs import (
CliEnum,
Duration,
Generation,
SkinSensitivity,
)


class StartParams(TypedDict, total=False):
"""Parameters for the `start` method in parameterized tests."""

duration: CliEnum[Duration]
generation: CliEnum[Generation]
skin_sensitivity: CliEnum[SkinSensitivity]


@pytest.fixture(name='dummy_device')
Expand Down Expand Up @@ -99,7 +110,7 @@ def test_child_sensitive_short(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x00, 0x00, 0x08],
Expand Down Expand Up @@ -146,7 +157,7 @@ def test_child_sensitive_medium(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x00, 0x01, 0x09],
Expand Down Expand Up @@ -193,7 +204,7 @@ def test_child_sensitive_long(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x00, 0x02, 0x0A],
Expand Down Expand Up @@ -235,7 +246,7 @@ def test_adult_sensitive_short(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x02, 0x00, 0x0A],
Expand Down Expand Up @@ -275,7 +286,7 @@ def test_adult_sensitive_medium(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x02, 0x01, 0x0B],
Expand Down Expand Up @@ -315,7 +326,7 @@ def test_adult_sensitive_long(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x02, 0x02, 0x0C],
Expand Down Expand Up @@ -358,7 +369,7 @@ def test_child_regular_short(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x01, 0x00, 0x09],
Expand Down Expand Up @@ -399,7 +410,7 @@ def test_child_regular_medium(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x01, 0x01, 0x0A],
Expand Down Expand Up @@ -440,7 +451,7 @@ def test_child_regular_long(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x01, 0x02, 0x0B],
Expand Down Expand Up @@ -481,7 +492,7 @@ def test_adult_regular_short(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x03, 0x00, 0x0B],
Expand Down Expand Up @@ -517,7 +528,7 @@ def test_adult_regular_medium(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x03, 0x01, 0x0C],
Expand Down Expand Up @@ -553,7 +564,7 @@ def test_adult_regular_long(
bulk_transfer: pytest_mock.MockType,
preferences: StartParams,
) -> None:
Api().start(**asdict(preferences))
Api().start(**preferences)
bulk_transfer.assert_called_with(
ANY,
[0xFF, 0x08, 0x03, 0x02, 0x0D],
Expand Down

0 comments on commit 750be80

Please sign in to comment.