-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Run Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install -r requirements-dev.txt || true | ||
- name: Set PYTHONPATH | ||
run: echo "PYTHONPATH=$(pwd)" >> $GITHUB_ENV | ||
|
||
- name: Run tests | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Testing dependencies | ||
pytest | ||
pytest-cov | ||
|
||
# Linting dependencies | ||
flake8 | ||
black | ||
isort | ||
|
||
# Optional: Type checking | ||
mypy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
homeassistant==2024.9.3 | ||
homeassistant==2024.12.5 | ||
aiodiscover==2.1.0 | ||
pyspeex-noise==1.0.2 | ||
pyspeex-noise==1.0.2 | ||
opentelemetry-sdk | ||
grpcio | ||
opentelemetry-exporter-otlp-proto-http | ||
opentelemetry-exporter-otlp-proto-grpc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import unittest | ||
from unittest.mock import patch, AsyncMock | ||
from custom_components.oig_cloud.api.oig_cloud_api import OigCloudApi | ||
|
||
class TestOigCloudApi(unittest.TestCase): | ||
def setUp(self): | ||
self.api = OigCloudApi("username", "password", False, None) | ||
|
||
@patch("custom_components.oig_cloud.api.oig_cloud_api.aiohttp.ClientSession") | ||
@patch("custom_components.oig_cloud.api.oig_cloud_api.datetime") | ||
@patch("custom_components.oig_cloud.api.oig_cloud_api.tracer") | ||
async def test_get_stats(self, mock_tracer, mock_datetime, mock_session): | ||
mock_datetime.datetime.now.return_value = mock_datetime.datetime(2025, 1, 27, 8, 34, 57) | ||
mock_response = AsyncMock() | ||
mock_response.status = 200 | ||
mock_response.json.return_value = {"key": "value"} | ||
mock_session.return_value.__aenter__.return_value.get.return_value = mock_response | ||
|
||
result = await self.api.get_stats() | ||
self.assertEqual(result, {"key": "value"}) | ||
self.assertEqual(self.api.last_state, {"key": "value"}) | ||
self.assertEqual(self.api.box_id, "key") | ||
|
||
@patch("custom_components.oig_cloud.api.oig_cloud_api.aiohttp.ClientSession") | ||
@patch("custom_components.oig_cloud.api.oig_cloud_api.datetime") | ||
@patch("custom_components.oig_cloud.api.oig_cloud_api.tracer") | ||
async def test_get_stats_cache(self, mock_tracer, mock_datetime, mock_session): | ||
mock_datetime.datetime.now.return_value = mock_datetime.datetime(2025, 1, 27, 8, 34, 57) | ||
self.api._last_update = mock_datetime.datetime(2025, 1, 27, 8, 34, 30) | ||
self.api.last_state = {"cached_key": "cached_value"} | ||
|
||
result = await self.api.get_stats() | ||
self.assertEqual(result, {"cached_key": "cached_value"}) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |