Skip to content

Commit f1a6d0b

Browse files
do not directly compare floats
1 parent f5d6ea8 commit f1a6d0b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tests/test_machine_controller.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from unittest.mock import ANY, MagicMock, patch
22

3+
import pytest
4+
35
from src.config.config_manager import CONFIG
46
from src.config.config_types import PumpConfig
57
from src.machine.controller import MachineController, _build_preparation_data, _PreparationData
@@ -63,13 +65,13 @@ def test_build_preparation_data(self):
6365
# Verify results
6466
assert len(prep_data) == 2
6567
assert prep_data[0].pin == 1
66-
assert prep_data[0].volume_flow == 10.0
67-
assert prep_data[0].flow_time == 10.0 # 100ml / 10ml/s
68+
assert prep_data[0].volume_flow == pytest.approx(10.0)
69+
assert prep_data[0].flow_time == pytest.approx(10.0) # 100ml / 10ml/s
6870
assert prep_data[0].recipe_order == 1
6971

7072
assert prep_data[1].pin == 2
71-
assert prep_data[1].volume_flow == 10.0 # 20.0 * 0.5 (pump_speed 50%)
72-
assert prep_data[1].flow_time == 20.0 # 200ml / 10ml/s
73+
assert prep_data[1].volume_flow == pytest.approx(10.0) # 20.0 * 0.5 (pump_speed 50%)
74+
assert prep_data[1].flow_time == pytest.approx(20.0) # 200ml / 10ml/s
7375
assert prep_data[1].recipe_order == 2
7476

7577
finally:
@@ -166,8 +168,8 @@ def test_start_preparation(self, mock_time):
166168
current_time, max_time = mc._start_preparation(None, prep_data, True)
167169

168170
# Verify the method worked correctly
169-
assert max_time == 2.0 # 1.0s + 1.0s for the two ingredients
170-
assert current_time == 2.0 # Last time value from our mock
171+
assert max_time == pytest.approx(2.0) # 1.0s + 1.0s for the two ingredients
172+
assert current_time == pytest.approx(2.0) # Last time value from our mock
171173

172174
# Verify _start_pumps was called for both chunks with correct pins
173175
assert mc._start_pumps.call_count == 2

0 commit comments

Comments
 (0)