Skip to content

Commit 40853f2

Browse files
authored
Add initial test suite setup (#27)
* Add initial test suite setup * Update ruff config
1 parent fb04b79 commit 40853f2

File tree

10 files changed

+66
-43
lines changed

10 files changed

+66
-43
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ jobs:
1414
run: pipx install hatch
1515
- name: Lint and typecheck
1616
run: |
17-
hatch run lint-check
17+
hatch fmt --linter
1818
- name: Test
1919
run: |
2020
hatch test --all
2121
2222
- uses: codecov/codecov-action@v5
2323
with:
2424
token: ${{ secrets.CODECOV_TOKEN }}
25-
fail_ci_if_error: true
25+
fail_ci_if_error: false
2626
verbose: true
2727

2828
release:

pyproject.toml

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dynamic = ["version"]
88
description = "Simple Python wrapper for Uptime Kuma"
99
readme = "README.md"
1010
license = "MIT"
11-
requires-python = ">=3.8.0"
11+
requires-python = ">=3.12"
1212
authors = [
1313
{ name = "Manfred Dennerlein Rodelo", email = "[email protected]" },
1414
{ name = "Jayakorn Karikan", email = "[email protected]" },
@@ -40,32 +40,18 @@ include = [
4040
"/pythonkuma",
4141
]
4242

43-
[tool.ruff]
44-
target-version = "py312"
45-
line-length = 88
46-
47-
[tool.ruff.lint]
48-
preview = true
49-
ignore = ["TRY003", "N818"]
50-
51-
52-
[tool.ruff.lint.isort]
53-
force-sort-within-sections = true
54-
known-first-party = ["pythonkuma"]
55-
combine-as-imports = true
56-
split-on-trailing-comma = false
57-
58-
[tool.ruff.lint.pydocstyle]
59-
convention = "numpy"
60-
61-
[tool.ruff.format]
62-
preview = true
63-
quote-style = "double"
64-
indent-style = "space"
65-
66-
[tool.ruff.lint.mccabe]
67-
max-complexity = 25
68-
69-
[tool.ruff.lint.flake8-tidy-imports]
70-
ban-relative-imports = "parents"
71-
43+
[tool.hatch.envs.hatch-static-analysis]
44+
dependencies = ["ruff==0.11.13"]
45+
config-path = "ruff.toml"
46+
47+
[tool.pytest.ini_options]
48+
addopts = "--cov=pythonkuma/ --cov-report=term-missing"
49+
asyncio_mode = "auto"
50+
asyncio_default_fixture_loop_scope="module"
51+
testpaths = ["tests"]
52+
pythonpath = ["pythonkuma"]
53+
54+
[tool.hatch.envs.hatch-test]
55+
extra-dependencies = [
56+
"pytest-cov"
57+
]

pythonkuma/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Python API wrapper for Uptime Kuma."""
2+
23
from .exceptions import (
34
UptimeKumaAuthenticationException,
45
UptimeKumaConnectionException,

pythonkuma/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Uptime Kuma constants."""
2+
23
from logging import Logger, getLogger
34

45
LOGGER: Logger = getLogger(__package__)

pythonkuma/decorator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Decorator for Uptime Kuma"""
2+
23
from __future__ import annotations
34

45
from typing import TYPE_CHECKING
@@ -44,9 +45,7 @@ async def wrapper(*args, **kwargs):
4445
) from exception
4546

4647
except TimeoutError:
47-
raise exceptions.UptimeKumaConnectionException(
48-
f"Request timeout for '{url}'"
49-
) from None
48+
raise exceptions.UptimeKumaConnectionException(f"Request timeout for '{url}'") from None
5049

5150
except exceptions.UptimeKumaConnectionException as exception:
5251
raise exceptions.UptimeKumaConnectionException(exception) from exception

pythonkuma/models.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Uptime Kuma models"""
2+
23
from __future__ import annotations
34

45
from dataclasses import dataclass
@@ -87,20 +88,14 @@ def from_prometheus(data: dict[str, Any]) -> UptimeKumaApiResponse:
8788
for sample in family.samples:
8889
if sample.name.startswith("monitor"):
8990
existed = next(
90-
(
91-
i
92-
for i, x in enumerate(monitors)
93-
if x["monitor_name"] == sample.labels["monitor_name"]
94-
),
91+
(i for i, x in enumerate(monitors) if x["monitor_name"] == sample.labels["monitor_name"]),
9592
None,
9693
)
9794
if existed is None:
9895
temp = {**sample.labels, sample.name: sample.value}
9996
monitors.append(temp)
10097
else:
10198
monitors[existed][sample.name] = sample.value
102-
obj["data"] = [
103-
UptimeKumaMonitor.from_dict(monitor) for monitor in monitors
104-
]
99+
obj["data"] = [UptimeKumaMonitor.from_dict(monitor) for monitor in monitors]
105100

106101
return UptimeKumaApiResponse(**obj)

pythonkuma/uptimekuma.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Uptime Kuma client."""
2+
23
from aiohttp import ClientSession
34

45
from .decorator import api_request

ruff.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
line-length = 120
2+
3+
[format]
4+
docstring-code-format = true
5+
docstring-code-line-length = 80
6+
quote-style = "double"
7+
indent-style = "space"
8+
9+
[lint]
10+
11+
[lint.per-file-ignores]
12+
"**/scripts/*" = [
13+
"INP001",
14+
"T201",
15+
]
16+
"**/tests/**/*" = [
17+
"PLC1901",
18+
"PLR2004",
19+
"PLR6301",
20+
"S",
21+
"TID252",
22+
]
23+
24+
[lint.flake8-tidy-imports]
25+
ban-relative-imports = "parents"
26+
27+
[lint.isort]
28+
known-first-party = ["pyuptimekuma"]
29+
force-sort-within-sections = true
30+
combine-as-imports = true
31+
split-on-trailing-comma = false
32+
33+
[lint.flake8-pytest-style]
34+
fixture-parentheses = false
35+
mark-parentheses = false
36+
37+
[lint.pydocstyle]
38+
convention = "numpy"

tests/__init__.py

Whitespace-only changes.

tests/test_dummy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_dummy():
2+
pass

0 commit comments

Comments
 (0)