mirror of
https://github.com/OMGeeky/flucto-heisskleber.git
synced 2026-01-04 18:50:33 +01:00
* #129 AsyncTcpSource enhancements - retry connection on startup (behavior is configurable) - reconnect if data receiving fails (EOF received) - add Python logging - add unit tests * remove syncronous implementations. * WIP: Refactor packer/unpacker * Refactor type hints and topic handling in console sink. * Remove comma from tcp config enum definitions * Remove references to deleted synchronous classes. * Hopefully stable interface for Packer and Unpacker. * WIP: Working with protocols and generics * Finalized Sink, Source definition. * Rename mqtt source and sink files * Rename mqtt publisher and subscriber. * Fix start function to async. * Update documentation. * Remove recursion from udp source. * rename unpack to unpacker, stay consistent. * Renaming in tests. * Make MqttSource generic. * Configure pyproject.toml to move to uv * Add nox support. * Update documentation with myst-parser and sphinx. * Mess with autogeneration of __call__ signatures. * Add dynamic versioning to hatch * Asyncio wrapper for pyserial. * Add docstrings for serial sink and source. * Refactor config handling (#171) * Removes deprecated "verbose" and "print_std" parameters * Adds class methods for config generation from dictionary or file (yaml or json at this point) * Run-time type checking via __post_init__() function * Add serial dependency. * WIP * Move broker to bin/ * Update docs. * WIP: Need to update docstrings to make ruff happy. * Move source files to src/ * Fix tests for TcpSource. * WIP: Remove old tests. * Fix docstrings in mqtt classes. * Make default tcp unpacker json_unpacker. * No failed tests if there are no tests * Update test pipeline * Update ruff pre-commit * Updated ruff formatting * Format bin/ * Fix type hints * No type checking * Make stop() async * Only test on ubuntu for now * Don't be so strict about sphinx warnings. * Rename TestConf for pytest naming compability. * Install package in editable mode for ci tests. * Update dependencies for docs generation. * Add keepalive and will to mqtt, fixes #112. * Update readme to reflect changes in usage. * Requested fixes for console adapters. * Raise correct errors in unpacker and packer. * Correct logger name for mqtt sink. * Add config options for stopbits and parity to Serial. * Remove exception logging call from yaml parser. * Add comments to clear up very implicit test. * Rename Sink -> Sender, Source -> Receiver. * Rename sink and source in tests. * Fix tests. --------- Co-authored-by: Adrian Weiler <a.weiler@aldea.de>
56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
from dataclasses import dataclass
|
|
|
|
import pytest
|
|
|
|
from heisskleber.core import BaseConf
|
|
|
|
|
|
@dataclass
|
|
class SampleConfig(BaseConf):
|
|
name: str
|
|
age: int = 18
|
|
speed: float = 1.05
|
|
|
|
|
|
def test_config_constructor() -> None:
|
|
test_conf = SampleConfig(name="Gandalf", age=200, speed=10.0)
|
|
assert test_conf.name == "Gandalf"
|
|
assert test_conf.age == 200
|
|
assert test_conf.speed == 10.0
|
|
|
|
|
|
def test_config_from_dict() -> None:
|
|
test_dict = {"name": "Alice", "age": 30, "job": "Electrician", "speed": 1.0}
|
|
|
|
expected = SampleConfig(name="Alice", age=30, speed=1.0)
|
|
|
|
configuration = SampleConfig.from_dict(test_dict)
|
|
assert configuration == expected
|
|
|
|
|
|
def test_config_from_dict_with_default() -> None:
|
|
test_dict = {"name": "Alice"}
|
|
|
|
expected = SampleConfig(name="Alice", age=18)
|
|
|
|
configuration = SampleConfig.from_dict(test_dict)
|
|
assert configuration == expected
|
|
|
|
|
|
def test_pytest_raises_type_error() -> None:
|
|
with pytest.raises(TypeError):
|
|
SampleConfig(name=1.0) # type: ignore[arg-type]
|
|
|
|
|
|
def test_pytest_raises_type_error_from_dict() -> None:
|
|
with pytest.raises(TypeError):
|
|
SampleConfig.from_dict({"name": 1.0, "age": "monkey"})
|
|
|
|
|
|
def test_conf_from_file() -> None:
|
|
test_conf = SampleConfig.from_file("./tests/core/test_conf.yaml")
|
|
|
|
assert test_conf.name == "Frodo"
|
|
assert test_conf.age == 30
|
|
assert test_conf.speed == 0.5
|