Skip to content

Commit

Permalink
test config with Optional of dict
Browse files Browse the repository at this point in the history
  • Loading branch information
vuffiraa72 committed Feb 16, 2023
1 parent ab0f9c4 commit 28718b5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
6 changes: 3 additions & 3 deletions data/config/openwb_local.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# openwb-version:3
listener 1886 localhost
# openwb-version:4
listener 1886 127.0.0.1
allow_anonymous true

connection bridge-01
address localhost:1883
address 127.0.0.1:1883
topic openWB/set/# both 2

topic openWB/vehicle/+/name out 2
Expand Down
19 changes: 19 additions & 0 deletions packages/RPi/GPIO.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BOARD = 1
OUT = 1
IN = 1


def setmode(a):
pass


def setup(a, b, c):
pass


def input(a):
pass


def cleanup():
pass
Empty file added packages/RPi/__init__.py
Empty file.
26 changes: 25 additions & 1 deletion packages/dataclass_utils/_dataclass_from_dict_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Type, TypeVar, Generic
from typing import Generic, Optional, Type, TypeVar

import pytest

Expand Down Expand Up @@ -29,6 +29,12 @@ def __init__(self, a: str):
super().__init__(a)


class Optionals:
def __init__(self, a: str, o: Optional[dict] = None):
self.a = a
self.o = o


def test_from_dict_simple():
# execution
actual = dataclass_from_dict(SimpleSample, {"b": "bValue", "a": "aValue"})
Expand Down Expand Up @@ -86,3 +92,21 @@ def test_from_dict_fails_on_invalid_properties(type: Type[T], invalid_parameter:
dataclass_from_dict(type, {"invalid": "dict"})
assert str(e.value) == "Cannot determine value for parameter " + invalid_parameter + \
": not given in {'invalid': 'dict'} and no default value specified"


def test_from_dict_wit_optional():
# execution
actual = dataclass_from_dict(Optionals, {"a": "aValue", "o": {"b": "bValue"}})

# evaluation
assert actual.a == "aValue"
assert actual.o == {"b": "bValue"}


def test_from_dict_without_optional():
# execution
actual = dataclass_from_dict(Optionals, {"a": "aValue"})

# evaluation
assert actual.a == "aValue"
assert actual.o is None

0 comments on commit 28718b5

Please sign in to comment.