Skip to content

Commit 08abbec

Browse files
committed
Fixed failing tests from module move
1 parent 5bcefbf commit 08abbec

10 files changed

Lines changed: 36 additions & 26 deletions

File tree

conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
from unittest.mock import patch
2+
13
import pytest
24
from rest_framework.test import APIClient
35

46

57
@pytest.fixture
68
def client():
79
return APIClient()
10+
11+
12+
# Component Temp probe
13+
@pytest.fixture
14+
def temp_probe_path():
15+
with patch("shedpi_components.temperature_probe.Path"):
16+
yield

shedpi_components/__init__.py

Whitespace-only changes.

shedpi_components/am2302.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
Code based on: https://github.com/Gozem/am2320/blob/45a20076efb9a19e91bd50f229d1cdd53f1134d4/am2320.py#L1
3+
License: MIT https://github.com/Gozem/am2320/blob/45a20076efb9a19e91bd50f229d1cdd53f1134d4/LICENSE#L1
4+
"""

standalone_modules/temperature_module/temperature_probe.py renamed to shedpi_components/temperature_probe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
ReadingSubmissionService,
99
)
1010

11+
# TODO: Remove the submission_service from the component, it's an anti pattern
12+
1113

1214
class TempProbe:
1315
def __init__(self, submission_service: ReadingSubmissionService):

shedpi_hub_dashboard/tests/integration/test_module_reading_submission.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import pytest
55
from rest_framework import status
66

7+
from shedpi_components.temperature_probe import (
8+
TempProbe,
9+
)
710
from shedpi_hub_dashboard.models import DeviceModuleReading
811
from shedpi_hub_dashboard.tests.utils.factories import (
912
DeviceModuleFactory,
1013
)
1114
from standalone_modules.shed_pi_module_utils.data_submission import (
1215
ReadingSubmissionService,
1316
)
14-
from standalone_modules.temperature_module.temperature_probe import (
15-
TempProbe,
16-
)
1717

1818

1919
@patch("standalone_modules.temperature_module.temperature_probe.Path")

standalone_modules/shed_pi_example_device_installation/device_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import time
22

3+
from shedpi_components.temperature_probe import TempProbe
34
from standalone_modules.rpi.device import RPIDevice
45
from standalone_modules.shed_pi_module_utils.base_protocol import BaseProtocol
56
from standalone_modules.shed_pi_module_utils.data_submission import (
67
ReadingSubmissionService,
78
)
89
from standalone_modules.shed_pi_module_utils.utils import check_arch_is_arm, logger
9-
from standalone_modules.temperature_module.temperature_probe import TempProbe
1010

1111
TIME_TO_SLEEP = 60 # time in seconds
1212

standalone_modules/shed_pi_module_utils/base_protocol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from warnings import deprecated
2-
31
from standalone_modules.shed_pi_module_utils.data_submission import (
42
ReadingSubmissionService,
53
)
@@ -33,6 +31,8 @@ def shutdown(self) -> None:
3331
"""
3432
...
3533

36-
@deprecated("Deprecated run method is replaced by start")
3734
def run(self) -> None:
35+
"""
36+
@deprecated("Deprecated run method is replaced by start")
37+
"""
3838
raise NotImplementedError

standalone_modules/temperature_module/device_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import time
22

3+
from shedpi_components.temperature_probe import TempProbe
34
from standalone_modules.shed_pi_module_utils.base_protocol import BaseProtocol
45
from standalone_modules.shed_pi_module_utils.data_submission import (
56
ReadingSubmissionService,
67
)
78
from standalone_modules.shed_pi_module_utils.utils import check_arch_is_arm, logger
8-
from standalone_modules.temperature_module.temperature_probe import TempProbe
99

1010
TIME_TO_SLEEP = 60 # time in seconds
1111

standalone_modules/temperature_module/tests/integration/test_temp_module.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import json
2-
from unittest.mock import Mock, patch
2+
from unittest.mock import Mock
33

44
import pytest
55
from rest_framework import status
66

7+
from shedpi_components.temperature_probe import (
8+
TempProbe,
9+
)
710
from shedpi_hub_dashboard.models import DeviceModuleReading
811
from shedpi_hub_dashboard.tests.utils.factories import (
912
DeviceModuleFactory,
1013
)
1114
from standalone_modules.shed_pi_module_utils.data_submission import (
1215
ReadingSubmissionService,
1316
)
14-
from standalone_modules.temperature_module.temperature_probe import (
15-
TempProbe,
16-
)
1717

1818

19-
@patch("standalone_modules.temperature_module.temperature_probe.Path")
2019
@pytest.mark.django_db
21-
def test_temperature_module_reading_submission(mocked_path, live_server):
20+
def test_temperature_module_reading_submission(temp_probe_path, live_server):
2221
schema = {
2322
"$id": "https://example.com/person.schema.json",
2423
"$schema": "https://json-schema.org/draft/2020-12/schema",

standalone_modules/temperature_module/tests/unit/test_temp_module.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from unittest.mock import Mock, patch
1+
from unittest.mock import Mock
22

33
import pytest
44

5+
from shedpi_components.temperature_probe import (
6+
TempProbe,
7+
)
58
from shedpi_hub_dashboard.models import DeviceModuleReading
69
from shedpi_hub_dashboard.tests.utils.factories import (
710
DeviceModuleFactory,
@@ -10,13 +13,9 @@
1013
ReadingSubmissionService,
1114
)
1215
from standalone_modules.temperature_module.device_protocol import DeviceProtocol
13-
from standalone_modules.temperature_module.temperature_probe import (
14-
TempProbe,
15-
)
1616

1717

18-
@patch("standalone_modules.temperature_module.temperature_probe.Path")
19-
def test_temp_probe_reading_happy_path(mocked_path):
18+
def test_temp_probe_reading_happy_path(temp_probe_path):
2019
# FIXME: Get the actual readout from the modules
2120
probe = TempProbe(submission_service=Mock())
2221
probe.read_temp_raw = Mock(
@@ -30,8 +29,7 @@ def test_temp_probe_reading_happy_path(mocked_path):
3029
assert temp == 12.345
3130

3231

33-
@patch("standalone_modules.temperature_module.temperature_probe.Path")
34-
def test_temp_probe_reading_invalid_reading(mocked_path):
32+
def test_temp_probe_reading_invalid_reading(temp_probe_path):
3533
"""
3634
TODO:
3735
- Find what a real invalid reading looks like
@@ -49,8 +47,7 @@ def test_temp_probe_reading_invalid_reading(mocked_path):
4947
probe.read_temp()
5048

5149

52-
@patch("standalone_modules.temperature_module.temperature_probe.Path")
53-
def test_temp_probe_reading_invalid_reading_missing_expected_params(mocked_path):
50+
def test_temp_probe_reading_invalid_reading_missing_expected_params(temp_probe_path):
5451
"""
5552
YES is missing from the data feed
5653
"""
@@ -74,9 +71,8 @@ def test_temp_probe_reading_invalid_reading_missing_expected_params(mocked_path)
7471
probe.read_temp_raw.call_count == 2
7572

7673

77-
@patch("standalone_modules.temperature_module.temperature_probe.Path")
7874
@pytest.mark.django_db
79-
def test_temp_logger(mocked_path, live_server):
75+
def test_temp_logger(temp_probe_path, live_server):
8076
# Submission service
8177
submission_service = ReadingSubmissionService()
8278
submission_service.base_url = live_server.url

0 commit comments

Comments
 (0)