Skip to content

Commit

Permalink
wip: Get tests running again (#87)
Browse files Browse the repository at this point in the history
* Tests are not gaining full coverage, but actual test job completes now.

* wip: Get tests running again

* Add serial to requirements_test to fix workflow

* Add serial-tools for test workflow

* Change to pyserial and pyserial-asyncio
  • Loading branch information
agittins authored Jan 10, 2024
1 parent 8986642 commit b279915
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
2 changes: 2 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ pytest-homeassistant-custom-component
#==0.13.50
pre-commit
reorder-python-imports
pyserial-asyncio==0.6
pyserial==3.5
30 changes: 15 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ def skip_notifications_fixture():
# async_get_data to return None. To have the call
# return a value, we would add the `return_value=<VALUE_TO_RETURN>`
# parameter to the patch call.
# AJG - we aren't using the API, and probably won't.
# @pytest.fixture(name="bypass_get_data")
# def bypass_get_data_fixture():
# """Skip calls to get data from API."""
# with patch("custom_components.bermuda.BermudaApiClient.async_get_data"):
# yield
@pytest.fixture(name="bypass_get_data")
def bypass_get_data_fixture():
"""Skip calls to get data from API."""
# AJG: We don't implement this, so nothing to monkeypatch.
# with patch("custom_components.bermuda.BermudaApiClient.async_get_data"):
# yield


# In this fixture, we are forcing calls to async_get_data to raise
# an Exception. This is useful
# for exception handling.
# AJG - No API for us.
# @pytest.fixture(name="error_on_get_data")
# def error_get_data_fixture():
# """Simulate error when retrieving data from API."""
# with patch(
# "custom_components.bermuda.BermudaApiClient.async_get_data",
# side_effect=Exception,
# ):
# yield
@pytest.fixture(name="error_on_get_data")
def error_get_data_fixture():
"""Simulate error when retrieving data from API."""
# AJG: again we don't implement async_get_data...
# with patch(
# "custom_components.bermuda.BermudaApiClient.async_get_data",
# side_effect=Exception,
# ):
# yield
17 changes: 9 additions & 8 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Constants for Bermuda BLE Trilateration tests."""
from custom_components.bermuda.const import (
CONF_PASSWORD,
)
from custom_components.bermuda.const import (
CONF_USERNAME,
)

MOCK_CONFIG = {CONF_USERNAME: "test_username", CONF_PASSWORD: "test_password"}
# AJG: We don't use these vars in our flow. TODO: Add some we _do_ use!
# from custom_components.bermuda.const import (
# CONF_PASSWORD,
# )
# from custom_components.bermuda.const import (
# CONF_USERNAME,
# )
# MOCK_CONFIG = {CONF_USERNAME: "test_username", CONF_PASSWORD: "test_password"}
MOCK_CONFIG = {}
2 changes: 2 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

from .const import MOCK_CONFIG

# from pytest_homeassistant_custom_component.common import AsyncMock


# We can pass fixtures as defined in conftest.py to tell pytest to use the fixture
# for a given test. We can also leverage fixtures and mocks that are available in
Expand Down

0 comments on commit b279915

Please sign in to comment.