Skip to content

Commit

Permalink
Reworked imports to the external shed pi module utils package
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiky30 committed Dec 8, 2024
1 parent 67cebaa commit 0916f50
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def client():
# Component Temp probe
@pytest.fixture
def temp_probe_path():
with patch("shedpi_components.temperature_probe.Path"):
with patch("shed_pi_module_utils.shed_pi_components.ds18b20.Path"):
yield
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from unittest.mock import Mock, patch
from unittest.mock import Mock

import pytest
from rest_framework import status
Expand All @@ -16,9 +16,8 @@
)


@patch("standalone_modules.temperature_module.temperature_probe.Path")
@pytest.mark.django_db
def test_temperature_module_reading_submission(mocked_path, live_server):
def test_temperature_module_reading_submission(temp_probe_path, live_server):
schema = {
"$id": "https://example.com/person.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
Expand Down
62 changes: 32 additions & 30 deletions standalone_modules/shedpi_module_am2320/tests/unit/test_probe.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
from unittest.mock import Mock, patch

import pytest
from shed_pi_module_utils.shedpi_components import AM2320


@patch("shedpi_components.AM2302.posix")
@patch("shedpi_components.AM2302.ioctl")
def test_probe_reading_no_reading(mocked_posix, mocked_ioctl):
probe = AM2320()

with pytest.raises(ValueError) as err:
probe.read_sensor()

assert err.value.args[0] == "First two read bytes are a mismatch"


@patch("shedpi_components.AM2302.posix")
@patch("shedpi_components.AM2302.ioctl")
def test_probe_reading_happy_path(mocked_posix, mocked_ioctl):
probe = AM2320()
# probe.read_temp_raw = Mock(
# return_value=[
# "YES",
# "t=12345",
# ]
# )

mocked_posix.read = Mock(return_value="0000000")
probe.read_sensor()
# from unittest.mock import Mock, patch
#
# import pytest
#
# # TODO: Replace with the correct module
# from shed_pi_module_utils.shed_pi_components import AM2320
#
#
# @patch("shedpi_components.AM2302.posix")
# @patch("shedpi_components.AM2302.ioctl")
# def test_probe_reading_no_reading(mocked_posix, mocked_ioctl):
# probe = AM2320()
#
# with pytest.raises(ValueError) as err:
# probe.read_sensor()
#
# assert err.value.args[0] == "First two read bytes are a mismatch"
#
#
# @patch("shedpi_components.AM2302.posix")
# @patch("shedpi_components.AM2302.ioctl")
# def test_probe_reading_happy_path(mocked_posix, mocked_ioctl):
# probe = AM2320()
# # probe.read_temp_raw = Mock(
# # return_value=[
# # "YES",
# # "t=12345",
# # ]
# # )
#
# mocked_posix.read = Mock(return_value="0000000")
# probe.read_sensor()
4 changes: 2 additions & 2 deletions standalone_modules/temperature_module/device_protocol.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import time

import requests
from shed_pi_module_utils import BaseProtocol
from shed_pi_module_utils.base_protocol import BaseProtocol
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from shed_pi_module_utils.shed_pi_components.ds18b20 import TempProbe
from shed_pi_module_utils.utils import check_arch_is_arm, logger
from shedpi_module_utils.shedpi_components.ds18b20 import TempProbe

TIME_TO_SLEEP = 60 # time in seconds

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from shed_pi_module_utils.shed_pi_components.ds18b20 import (
TempProbe,
)

from shedpi_hub_dashboard.models import DeviceModuleReading
from shedpi_hub_dashboard.tests.utils.factories import (
DeviceModuleFactory,
)
from shedpi_module_utils.shedpi_components.ds18b20 import (
TempProbe,
)


@pytest.mark.django_db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from shed_pi_module_utils.data_submission import (
ReadingSubmissionService,
)
from shed_pi_module_utils.shed_pi_components.ds18b20 import (
TempProbe,
)

from shedpi_hub_dashboard.models import DeviceModuleReading
from shedpi_hub_dashboard.tests.utils.factories import (
DeviceModuleFactory,
)
from shedpi_module_utils.shedpi_components.ds18b20 import (
TempProbe,
)
from standalone_modules.temperature_module.device_protocol import DeviceProtocol


Expand Down

0 comments on commit 0916f50

Please sign in to comment.