mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Rewrite openhardwaremonitor tests to pytest style test functions (#41157)
This commit is contained in:
parent
226a6f7584
commit
5e98bdb19c
@ -1,55 +1,36 @@
|
|||||||
"""The tests for the Open Hardware Monitor platform."""
|
"""The tests for the Open Hardware Monitor platform."""
|
||||||
import unittest
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
import requests_mock
|
from tests.common import load_fixture
|
||||||
|
|
||||||
from homeassistant.setup import setup_component
|
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant, load_fixture
|
|
||||||
|
|
||||||
|
|
||||||
class TestOpenHardwareMonitorSetup(unittest.TestCase):
|
async def test_setup(hass, requests_mock):
|
||||||
"""Test the Open Hardware Monitor platform."""
|
"""Test for successfully setting up the platform."""
|
||||||
|
config = {
|
||||||
def setUp(self):
|
"sensor": {
|
||||||
"""Initialize values for this testcase class."""
|
"platform": "openhardwaremonitor",
|
||||||
self.hass = get_test_home_assistant()
|
"host": "localhost",
|
||||||
self.config = {
|
"port": 8085,
|
||||||
"sensor": {
|
|
||||||
"platform": "openhardwaremonitor",
|
|
||||||
"host": "localhost",
|
|
||||||
"port": 8085,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.addCleanup(self.tear_down_cleanup)
|
}
|
||||||
|
|
||||||
def tear_down_cleanup(self):
|
requests_mock.get(
|
||||||
"""Stop everything that was started."""
|
"http://localhost:8085/data.json",
|
||||||
self.hass.stop()
|
text=load_fixture("openhardwaremonitor.json"),
|
||||||
|
)
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
await async_setup_component(hass, "sensor", config)
|
||||||
def test_setup(self, mock_req):
|
await hass.async_block_till_done()
|
||||||
"""Test for successfully setting up the platform."""
|
|
||||||
mock_req.get(
|
|
||||||
"http://localhost:8085/data.json",
|
|
||||||
text=load_fixture("openhardwaremonitor.json"),
|
|
||||||
)
|
|
||||||
|
|
||||||
assert setup_component(self.hass, "sensor", self.config)
|
entities = hass.states.async_entity_ids("sensor")
|
||||||
self.hass.block_till_done()
|
assert len(entities) == 38
|
||||||
entities = self.hass.states.async_entity_ids("sensor")
|
|
||||||
assert len(entities) == 38
|
|
||||||
|
|
||||||
state = self.hass.states.get(
|
state = hass.states.get("sensor.test_pc_intel_core_i7_7700_temperatures_cpu_core_1")
|
||||||
"sensor.test_pc_intel_core_i7_7700_temperatures_cpu_core_1"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "31.0"
|
assert state.state == "31.0"
|
||||||
|
|
||||||
state = self.hass.states.get(
|
state = hass.states.get("sensor.test_pc_intel_core_i7_7700_temperatures_cpu_core_2")
|
||||||
"sensor.test_pc_intel_core_i7_7700_temperatures_cpu_core_2"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "30.0"
|
assert state.state == "30.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user