-
Notifications
You must be signed in to change notification settings - Fork 22
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
1 parent
e4b8973
commit a91eb84
Showing
58 changed files
with
423 additions
and
222 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
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
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,69 @@ | ||
|
||
line-length = 120 | ||
indent-width = 4 | ||
|
||
target-version = "py38" | ||
src = ["src", "test"] | ||
|
||
# https://docs.astral.sh/ruff/settings/#ignore-init-module-imports | ||
ignore-init-module-imports = true | ||
|
||
extend-exclude = ["__init__.py"] | ||
|
||
select = [ | ||
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w | ||
"I", # https://docs.astral.sh/ruff/rules/#isort-i | ||
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up | ||
|
||
"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a | ||
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async | ||
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 | ||
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em | ||
"FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix | ||
"INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp | ||
"ISC", # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc | ||
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie | ||
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt | ||
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth | ||
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret | ||
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim | ||
"SLOT", # https://docs.astral.sh/ruff/rules/#flake8-slots-slot | ||
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10 | ||
"TCH", # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tch | ||
"TD", # https://docs.astral.sh/ruff/rules/#flake8-todos-td | ||
|
||
"TRY", # https://docs.astral.sh/ruff/rules/#tryceratops-try | ||
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly | ||
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf | ||
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf | ||
|
||
# "PL", # https://docs.astral.sh/ruff/rules/#pylint-pl | ||
# "FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb | ||
] | ||
|
||
ignore = [ | ||
"RET501", # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501 | ||
"TRY400", # https://docs.astral.sh/ruff/rules/error-instead-of-exception/ | ||
|
||
"A003", # https://docs.astral.sh/ruff/rules/builtin-attribute-shadowing/ | ||
] | ||
|
||
|
||
[format] | ||
# Use single quotes for non-triple-quoted strings. | ||
quote-style = "single" | ||
|
||
|
||
|
||
[lint.flake8-builtins] | ||
builtins-ignorelist = ["id", "input"] | ||
|
||
|
||
[lint.per-file-ignores] | ||
"docs/conf.py" = ["INP001", "A001"] | ||
"setup.py" = ["PTH123"] | ||
|
||
|
||
[lint.isort] | ||
# https://docs.astral.sh/ruff/settings/#isort-lines-after-imports | ||
lines-after-imports = 2 |
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
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
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
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
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
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
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
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,47 +1,66 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import datetime, timedelta | ||
from typing import Final, Any | ||
|
||
from HABApp.openhab.definitions.helpers import OpenhabPersistenceData | ||
from HABApp.openhab.items import NumberItem | ||
from HABAppTests import TestBaseRule | ||
|
||
|
||
class TestPersistence(TestBaseRule): | ||
|
||
def __init__(self): | ||
class TestPersistenceBase(TestBaseRule): | ||
def __init__(self, service_name: str, item_name: str): | ||
super().__init__() | ||
self.item = 'RRD4J_Item' | ||
|
||
self.add_test('RRD4J configured', self.test_configured) | ||
self.add_test('RRD4J get', self.test_get) | ||
self.config.skip_on_failure = True | ||
self.item_name: Final = item_name | ||
self.service_name: Final = service_name | ||
|
||
self.add_test(f'Persistence {service_name} available', self.test_service_available) | ||
|
||
def set_up(self): | ||
i = NumberItem.get_item(self.item) | ||
i.oh_post_update(i.value + 1 if i.value < 10 else 0) | ||
i = NumberItem.get_item(self.item_name) | ||
i.oh_post_update(int(i.value) + 1 if i.value < 10 else 0) | ||
|
||
def test_configured(self): | ||
def test_service_available(self): | ||
for cfg in self.oh.get_persistence_services(): | ||
if cfg.id == 'rrd4j': | ||
if cfg.id == self.service_name: | ||
break | ||
else: | ||
raise ValueError('rrd4j not found!') | ||
raise ValueError(f'Persistence service "{self.service_name}" not found!') | ||
|
||
def set_persistence_data(self, time: datetime, state: Any): | ||
return self.openhab.set_persistence_data(self.item_name, self.service_name, time, state) | ||
|
||
def get_persistence_data(self, start_time: datetime | None, end_time: datetime | None) -> OpenhabPersistenceData: | ||
return self.openhab.get_persistence_data(self.item_name, self.service_name, start_time, end_time) | ||
|
||
|
||
class TestRRD4j(TestPersistenceBase): | ||
|
||
def __init__(self): | ||
super().__init__('rrd4j', 'RRD4J_Item') | ||
self.add_test('RRD4J get', self.test_get) | ||
|
||
def test_get(self): | ||
now = datetime.now() | ||
d = self.openhab.get_persistence_data(self.item, 'rrd4j', now - timedelta(seconds=60), now) | ||
d = self.get_persistence_data(now - timedelta(seconds=60), now) | ||
assert d.get_data() | ||
|
||
# def test_set(self): | ||
# now = datetime.now() | ||
# d = self.openhab.get_persistence_data(self.item, 'mapdb', now - timedelta(seconds=5), now) | ||
# was = d.get_data() | ||
# | ||
# assert list(was.values()) == [1] | ||
# | ||
# self.openhab.set_persistence_data(self.item, 'mapdb', now, 2) | ||
# | ||
# d = self.openhab.get_persistence_data(self.item, 'mapdb', now - timedelta(seconds=5), | ||
# now + timedelta(seconds=5)) | ||
# ist = d.get_data() | ||
# assert list(ist.values()) == [2], ist | ||
|
||
|
||
TestPersistence() | ||
|
||
TestRRD4j() | ||
|
||
|
||
class TestMapDB(TestPersistenceBase): | ||
|
||
def __init__(self): | ||
super().__init__('mapdb', 'RRD4J_Item') | ||
self.add_test('MapDB get', self.test_get) | ||
|
||
def test_get(self): | ||
now = datetime.now() | ||
d = self.get_persistence_data(now - timedelta(seconds=60), now) | ||
assert d.get_data() | ||
|
||
|
||
TestMapDB() |
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
Oops, something went wrong.