Skip to content

Commit b29eb73

Browse files
authored
Merge pull request #5 from gensyn/copilot/add-tests-and-workflows
Add tests, CI workflows, and homeassistant mock for task_tracker
2 parents 866a7ae + 4bbc1ac commit b29eb73

36 files changed

Lines changed: 996 additions & 13 deletions

.github/workflows/pylint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Pylint
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: read
10+
11+
strategy:
12+
matrix:
13+
python-version: ["3.14"]
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install pylint
27+
28+
- name: Analysing the code with pylint
29+
run: |
30+
pylint --fail-under=9 --max-line-length=120 --disable=import-error,wrong-import-position,wrong-import-order,too-many-instance-attributes,too-many-locals,too-many-arguments,too-few-public-methods --ignore-paths=^test/.*$ $(git ls-files '*.py')

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: read
10+
11+
strategy:
12+
matrix:
13+
python-version: ["3.14"]
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r requirements_unittests.txt
27+
28+
- name: Run tests
29+
run: |
30+
python -m unittest discover -s test -v

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__/
2+
*.pyc
3+
htmlcov/
4+
.coverage

frontend/__init__.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
"""View Assist Javascript module registration."""
1+
"""Task Tracker JavaScript module registration."""
22

33
import logging
44
import os
55
from pathlib import Path
66

77
from homeassistant.components.http import StaticPathConfig
88
from homeassistant.components.lovelace import MODE_STORAGE, LovelaceData
9-
from homeassistant.const import MAJOR_VERSION, MINOR_VERSION
109
from homeassistant.core import HomeAssistant
11-
1210
from ..const import URL_BASE, TASK_TRACKER_CARDS # noqa: TID252
1311

1412
_LOGGER = logging.getLogger(__name__)
@@ -21,10 +19,10 @@ def __init__(self, hass: HomeAssistant) -> None:
2119
"""Initialise."""
2220
self.hass = hass
2321
self.lovelace: LovelaceData = self.hass.data.get("lovelace")
24-
# Backwards compatability after/before 2026.2
25-
if MAJOR_VERSION > 2026 or (MAJOR_VERSION == 2026 and MINOR_VERSION >= 2):
22+
if hasattr(self.lovelace, "resource_mode"):
2623
self.resource_mode = self.lovelace.resource_mode
2724
else:
25+
# Backwards compatibility before 2026.2
2826
self.resource_mode = self.lovelace.mode
2927

3028
async def async_register(self):
@@ -38,7 +36,7 @@ async def _async_register_path(self):
3836
"""Register resource path if not already registered."""
3937
try:
4038
await self.hass.http.async_register_static_paths(
41-
[StaticPathConfig(URL_BASE, Path(__file__).parent, False)]
39+
[StaticPathConfig(URL_BASE, str(Path(__file__).parent), False)]
4240
)
4341
_LOGGER.debug("Registered resource path from %s", Path(__file__).parent)
4442
except RuntimeError:
@@ -66,7 +64,7 @@ async def _async_register_modules(self):
6664
card_registered = True
6765
# check version
6866
if self._get_resource_version(resource["url"]) != module.get(
69-
"version"
67+
"version"
7068
):
7169
# Update card version
7270
_LOGGER.debug(
@@ -136,10 +134,10 @@ def remove_gzip_files(self):
136134
for file in gzip_files:
137135
try:
138136
if (
139-
Path.stat(f"{path}/{file}").st_mtime
140-
< Path.stat(f"{path}/{file.replace('.gz', '')}").st_mtime
137+
Path.stat(Path(f"{path}/{file}")).st_mtime
138+
< Path.stat(Path(f"{path}/{file.replace('.gz', '')}")).st_mtime
141139
):
142140
_LOGGER.debug("Removing older gzip file - %s", file)
143-
Path.unlink(f"{path}/{file}")
141+
Path.unlink(Path(f"{path}/{file}"))
144142
except OSError:
145143
pass

options_flow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def validate_options(user_input: dict[str, Any]) -> dict[str, Any]:
9595
if user_input.get(CONF_NOTIFICATION_INTERVAL, 0) < 1:
9696
user_input[CONF_NOTIFICATION_INTERVAL] = 1
9797

98-
options = {
98+
return {
9999
CONF_ACTIVE: user_input[CONF_ACTIVE],
100100
CONF_TASK_INTERVAL_VALUE: user_input[CONF_TASK_INTERVAL_VALUE],
101101
CONF_TASK_INTERVAL_TYPE: user_input[CONF_TASK_INTERVAL_TYPE],
@@ -105,5 +105,3 @@ async def validate_options(user_input: dict[str, Any]) -> dict[str, Any]:
105105
CONF_TODO_OFFSET_DAYS: user_input[CONF_TODO_OFFSET_DAYS],
106106
CONF_NOTIFICATION_INTERVAL: user_input[CONF_NOTIFICATION_INTERVAL],
107107
}
108-
109-
return options

requirements_unittests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python-dateutil
2+
voluptuous

run_tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
coverage run --omit='test/*' -m unittest discover -s test; coverage html

test/__init__.py

Whitespace-only changes.

test/homeassistant_mock/homeassistant/__init__.py

Whitespace-only changes.

test/homeassistant_mock/homeassistant/components/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)