Skip to content

Commit

Permalink
sleep - fix test quirk
Browse files Browse the repository at this point in the history
  • Loading branch information
IGalat committed Nov 11, 2024
1 parent 5acfa8c commit 6a08030
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions tests/tapper/controller/test_sleep_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class SleepFixture:
mock_actual_sleep: MagicMock | Callable[[Any], None]

def get_time_slept(self) -> float:
return sum(call_.args[0] for call_ in self.mock_actual_sleep.call_args_list)
return round(
sum(call_.args[0] for call_ in self.mock_actual_sleep.call_args_list), 5
)


@pytest.fixture
Expand All @@ -37,20 +39,6 @@ def sleep_fixture() -> SleepFixture:
)


@dataclass
class Counter:
count: int = 0
ticks: list[float] = field(default_factory=list)
result: bool = False
at_3: Callable[[], bool] | None = None

def tick(self) -> bool:
self.count += 1
if self.count == 3 and self.at_3 is not None:
return self.at_3()
return self.result


class TestSleep:
def test_simplest(self, sleep_fixture: SleepFixture) -> None:
sleep_fixture.sleep(123)
Expand Down Expand Up @@ -128,6 +116,20 @@ def assert_time_equals(time_1: float, time_2: float) -> None:
assert abs(time_1 - time_2) < 0.05


@dataclass
class Counter:
count: int = 0
ticks: list[float] = field(default_factory=list)
result: bool = False
at_3: Callable[[], bool] | None = None

def tick(self) -> bool:
self.count += 1
if self.count == 3 and self.at_3 is not None:
return self.at_3()
return self.result


class TestRealSleep:
def test_zero_time(self) -> None:
processor = SleepCommandProcessor(
Expand Down

0 comments on commit 6a08030

Please sign in to comment.