|
|
|
|
@@ -175,13 +175,6 @@ class TestConfigWithoutEnabledFlag(unittest.TestCase):
|
|
|
|
|
class _(dm.BaseAppliance):
|
|
|
|
|
_ = "default value"
|
|
|
|
|
|
|
|
|
|
def test_annotated(self):
|
|
|
|
|
"""Testing first appliance level, and Field types (annotated one)"""
|
|
|
|
|
|
|
|
|
|
# class can be created if annotation is a string
|
|
|
|
|
class Appliance1(dm.BaseAppliance):
|
|
|
|
|
StrVar: Annotated[str, "my string"] = "default value"
|
|
|
|
|
|
|
|
|
|
def test_optionnal(self):
|
|
|
|
|
"""Testing first appliance level, and Field types (Optionnal annotations)"""
|
|
|
|
|
|
|
|
|
|
@@ -492,6 +485,7 @@ class TestConfigWithoutEnabledFlag(unittest.TestCase):
|
|
|
|
|
testVar4: "Tuple[str,...]" = ("a", "c")
|
|
|
|
|
testVar5: tuple[str, ...] = ("a", "b")
|
|
|
|
|
testVar6: "tuple[str,...]" = ("a", "b")
|
|
|
|
|
testVar7: Tuple[int, str] = (1, "b")
|
|
|
|
|
# testVar7: Tuple[Union[int, str]] = (1, 2, 3, "one", "two", "three")
|
|
|
|
|
|
|
|
|
|
app1 = Appliance1()
|
|
|
|
|
@@ -502,7 +496,7 @@ class TestConfigWithoutEnabledFlag(unittest.TestCase):
|
|
|
|
|
self.immutable_vars__test_field(app1, "testVar4", ("a", "c"), ("h", "e"))
|
|
|
|
|
self.immutable_vars__test_field(app1, "testVar5", ("a", "b"), ("h", "c"))
|
|
|
|
|
self.immutable_vars__test_field(app1, "testVar6", ("a", "b"), ("h", "c"))
|
|
|
|
|
# self.immutable_vars__test_field(app1, "testVar7", (1, 2, 3, "one", "two", "three"), ("h", "c"))
|
|
|
|
|
self.immutable_vars__test_field(app1, "testVar7", (1, "b"), (7, "h"))
|
|
|
|
|
|
|
|
|
|
# must work
|
|
|
|
|
sorted(app1.testVar)
|
|
|
|
|
@@ -527,6 +521,381 @@ class TestConfigWithoutEnabledFlag(unittest.TestCase):
|
|
|
|
|
class _(dm.BaseAppliance):
|
|
|
|
|
_: "Tuple" = (1, 2)
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(dm.InvalidFieldValue):
|
|
|
|
|
|
|
|
|
|
class _(dm.BaseAppliance):
|
|
|
|
|
_: "Tuple[int,...]" = (1, "a")
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(dm.InvalidFieldValue):
|
|
|
|
|
|
|
|
|
|
class _(dm.BaseAppliance):
|
|
|
|
|
_: "tuple[int,...]" = (1, "a")
|
|
|
|
|
|
|
|
|
|
def check_immutable_fields_schema(
|
|
|
|
|
self, appliance: dm.BaseAppliance, field_name: str, expected_value: str, expected_default_value: str, expected_type: type
|
|
|
|
|
):
|
|
|
|
|
self.assertIn(field_name, appliance.__DABSchema__)
|
|
|
|
|
self.assertIn("doc", dir(appliance.__DABSchema__[field_name]))
|
|
|
|
|
self.assertEqual(appliance.__DABSchema__[field_name].doc, "")
|
|
|
|
|
self.assertIn("annotations", dir(appliance.__DABSchema__[field_name]))
|
|
|
|
|
self.assertEqual(appliance.__DABSchema__[field_name].annotations, expected_type)
|
|
|
|
|
self.assertIn("value", dir(appliance.__DABSchema__[field_name]))
|
|
|
|
|
self.assertEqual(appliance.__DABSchema__[field_name].value, expected_value)
|
|
|
|
|
self.assertIn("default_value", dir(appliance.__DABSchema__[field_name]))
|
|
|
|
|
self.assertEqual(appliance.__DABSchema__[field_name].default_value, expected_default_value)
|
|
|
|
|
self.assertIn("constraints", dir(appliance.__DABSchema__[field_name]))
|
|
|
|
|
self.assertEqual(appliance.__DABSchema__[field_name].constraints, ())
|
|
|
|
|
|
|
|
|
|
def test_immutable_fields_schema(self):
|
|
|
|
|
"""Testing first appliance level, and Field types (annotated)"""
|
|
|
|
|
|
|
|
|
|
# class can be created
|
|
|
|
|
class Appliance1(dm.BaseAppliance):
|
|
|
|
|
StrVar: "str" = "default value"
|
|
|
|
|
StrVar2: "str" = "default value2"
|
|
|
|
|
VarInt: "int" = 12
|
|
|
|
|
VarInt2: "int" = 21
|
|
|
|
|
VarFloat: "float" = 12.1
|
|
|
|
|
VarFloat2: "float" = 21.2
|
|
|
|
|
VarComplex: "complex" = complex(3, 5)
|
|
|
|
|
VarComplex2: "complex" = complex(8, 6)
|
|
|
|
|
VarBool: "bool" = True
|
|
|
|
|
VarBool2: "bool" = False
|
|
|
|
|
VarBytes: "bytes" = bytes.fromhex("2Ef0 F1f2 ")
|
|
|
|
|
VarBytes2: "bytes" = bytes.fromhex("2ff0 F7f2 ")
|
|
|
|
|
|
|
|
|
|
app1 = Appliance1()
|
|
|
|
|
|
|
|
|
|
self.assertIn("__DABSchema__", dir(app1))
|
|
|
|
|
self.assertIn("__DABSchema__", app1.__dict__)
|
|
|
|
|
|
|
|
|
|
self.check_immutable_fields_schema(app1, "StrVar", "default value", "default value", str)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "StrVar2", "default value2", "default value2", str)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarInt", 12, 12, int)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarInt2", 21, 21, int)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarFloat", 12.1, 12.1, float)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarFloat2", 21.2, 21.2, float)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarComplex", complex(3, 5), complex(3, 5), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarComplex2", complex(8, 6), complex(8, 6), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBool", True, True, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBool2", False, False, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBytes", bytes.fromhex("2Ef0 F1f2 "), bytes.fromhex("2Ef0 F1f2 "), bytes)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBytes2", bytes.fromhex("2ff0 F7f2 "), bytes.fromhex("2ff0 F7f2 "), bytes)
|
|
|
|
|
|
|
|
|
|
def test_container_field_schema(self):
|
|
|
|
|
"""Testing first appliance level, and Field types (annotated)"""
|
|
|
|
|
|
|
|
|
|
# class can be created
|
|
|
|
|
class Appliance1(dm.BaseAppliance):
|
|
|
|
|
ListStr: list[str] = ["val1", "val2"]
|
|
|
|
|
ListStr2: "list[str]" = ["val3", "val4"]
|
|
|
|
|
Dict1: dict[int, float] = {1: 1.1, 4: 7.6, 91: 23.6}
|
|
|
|
|
Dict2: "dict[str, str]" = {"1": "1.1", "4": "7.6", "91": "23.6"}
|
|
|
|
|
Tuple1: "tuple[str,...]" = ("a", "c")
|
|
|
|
|
Tuple2: tuple[str, ...] = ("a", "b")
|
|
|
|
|
FrozenSet1: frozenset[int] = frozenset({1, 2})
|
|
|
|
|
FrozenSet2: "frozenset[int]" = frozenset({1, 2})
|
|
|
|
|
Set1: set[int] = set({1, 2})
|
|
|
|
|
Set2: "set[int]" = set({1, 2})
|
|
|
|
|
|
|
|
|
|
app1 = Appliance1()
|
|
|
|
|
|
|
|
|
|
self.assertIn("__DABSchema__", dir(app1))
|
|
|
|
|
self.assertIn("__DABSchema__", app1.__dict__)
|
|
|
|
|
|
|
|
|
|
self.check_immutable_fields_schema(app1, "ListStr", ("val1", "val2"), ("val1", "val2"), list[str])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "ListStr2", ("val3", "val4"), ("val3", "val4"), list[str])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Dict1", {1: 1.1, 4: 7.6, 91: 23.6}, {1: 1.1, 4: 7.6, 91: 23.6}, dict[int, float])
|
|
|
|
|
self.check_immutable_fields_schema(
|
|
|
|
|
app1, "Dict2", {"1": "1.1", "4": "7.6", "91": "23.6"}, {"1": "1.1", "4": "7.6", "91": "23.6"}, dict[str, str]
|
|
|
|
|
)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Tuple1", ("a", "c"), ("a", "c"), tuple[str, ...])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Tuple2", ("a", "b"), ("a", "b"), tuple[str, ...])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "FrozenSet1", frozenset({1, 2}), frozenset({1, 2}), frozenset[int])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "FrozenSet2", frozenset({1, 2}), frozenset({1, 2}), frozenset[int])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Set1", frozenset({1, 2}), frozenset({1, 2}), set[int])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Set2", frozenset({1, 2}), frozenset({1, 2}), set[int])
|
|
|
|
|
|
|
|
|
|
# same test with Typing types (list -> List ...)
|
|
|
|
|
# class can be created
|
|
|
|
|
class Appliance1(dm.BaseAppliance):
|
|
|
|
|
ListStr: List[str] = ["val1", "val2"]
|
|
|
|
|
ListStr2: "List[str]" = ["val3", "val4"]
|
|
|
|
|
Dict1: Dict[int, float] = {1: 1.1, 4: 7.6, 91: 23.6}
|
|
|
|
|
Dict2: "Dict[str, str]" = {"1": "1.1", "4": "7.6", "91": "23.6"}
|
|
|
|
|
Tuple1: "Tuple[str,...]" = ("a", "c")
|
|
|
|
|
Tuple2: Tuple[str, ...] = ("a", "b")
|
|
|
|
|
FrozenSet1: FrozenSet[int] = frozenset({1, 2})
|
|
|
|
|
FrozenSet2: "FrozenSet[int]" = frozenset({1, 2})
|
|
|
|
|
Set1: Set[int] = set({1, 2})
|
|
|
|
|
Set2: "Set[int]" = set({1, 2})
|
|
|
|
|
|
|
|
|
|
app1 = Appliance1()
|
|
|
|
|
|
|
|
|
|
self.assertIn("__DABSchema__", dir(app1))
|
|
|
|
|
self.assertIn("__DABSchema__", app1.__dict__)
|
|
|
|
|
|
|
|
|
|
self.check_immutable_fields_schema(app1, "ListStr", ("val1", "val2"), ("val1", "val2"), List[str])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "ListStr2", ("val3", "val4"), ("val3", "val4"), List[str])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Dict1", {1: 1.1, 4: 7.6, 91: 23.6}, {1: 1.1, 4: 7.6, 91: 23.6}, Dict[int, float])
|
|
|
|
|
self.check_immutable_fields_schema(
|
|
|
|
|
app1, "Dict2", {"1": "1.1", "4": "7.6", "91": "23.6"}, {"1": "1.1", "4": "7.6", "91": "23.6"}, Dict[str, str]
|
|
|
|
|
)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Tuple1", ("a", "c"), ("a", "c"), Tuple[str, ...])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Tuple2", ("a", "b"), ("a", "b"), Tuple[str, ...])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "FrozenSet1", frozenset({1, 2}), frozenset({1, 2}), FrozenSet[int])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "FrozenSet2", frozenset({1, 2}), frozenset({1, 2}), FrozenSet[int])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Set1", frozenset({1, 2}), frozenset({1, 2}), Set[int])
|
|
|
|
|
self.check_immutable_fields_schema(app1, "Set2", frozenset({1, 2}), frozenset({1, 2}), Set[int])
|
|
|
|
|
|
|
|
|
|
def test_immutable_fields_annotated(self):
|
|
|
|
|
"""Testing first appliance level, and Field types (annotated)"""
|
|
|
|
|
|
|
|
|
|
# class can be created
|
|
|
|
|
class Appliance1(dm.BaseAppliance):
|
|
|
|
|
StrVar: Annotated[str, dm.DABFieldInfo(doc="foo1")] = "default value"
|
|
|
|
|
StrVar2: Annotated[str, dm.DABFieldInfo(doc="foo2")] = "default value2"
|
|
|
|
|
VarInt: Annotated[int, dm.DABFieldInfo(doc="foo3")] = 12
|
|
|
|
|
VarInt2: Annotated[int, dm.DABFieldInfo(doc="foo4")] = 21
|
|
|
|
|
VarFloat: Annotated[float, dm.DABFieldInfo(doc="foo5")] = 12.1
|
|
|
|
|
VarFloat2: Annotated[float, dm.DABFieldInfo(doc="foo6")] = 21.2
|
|
|
|
|
VarComplex: Annotated[complex, dm.DABFieldInfo(doc="foo7")] = complex(3, 5)
|
|
|
|
|
VarComplex2: Annotated[complex, dm.DABFieldInfo(doc="foo8")] = complex(8, 6)
|
|
|
|
|
VarBool: Annotated[bool, dm.DABFieldInfo(doc="foo9")] = True
|
|
|
|
|
VarBool2: Annotated[bool, dm.DABFieldInfo(doc="foo10")] = False
|
|
|
|
|
VarBytes: Annotated[bytes, dm.DABFieldInfo(doc="foo11")] = bytes.fromhex("2Ef0 F1f2 ")
|
|
|
|
|
VarBytes2: Annotated[bytes, dm.DABFieldInfo(doc="foo12")] = bytes.fromhex("2ff0 F7f2 ")
|
|
|
|
|
|
|
|
|
|
app1 = Appliance1()
|
|
|
|
|
|
|
|
|
|
self.immutable_vars__test_field(app1, "StrVar", "default value", "test")
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["StrVar"].doc, "foo1")
|
|
|
|
|
self.immutable_vars__test_field(app1, "StrVar2", "default value2", "test2")
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["StrVar2"].doc, "foo2")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarInt", 12, 13)
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarInt"].doc, "foo3")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarInt2", 21, 22)
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarInt2"].doc, "foo4")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarFloat", 12.1, 32)
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarFloat"].doc, "foo5")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarFloat2", 21.2, 42)
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarFloat2"].doc, "foo6")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarComplex", complex(3, 5), complex(1, 2))
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarComplex"].doc, "foo7")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarComplex2", complex(8, 6), complex(3, 2))
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarComplex2"].doc, "foo8")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBool", True, False)
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarBool"].doc, "foo9")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBool2", False, True)
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarBool2"].doc, "foo10")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBytes", bytes.fromhex("2Ef0 F1f2 "), bytes.fromhex("11f0 F1f2 "))
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarBytes"].doc, "foo11")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBytes2", bytes.fromhex("2ff0 F7f2 "), bytes.fromhex("11f0 F1e2 "))
|
|
|
|
|
self.assertEqual(app1.__DABSchema__["VarBytes2"].doc, "foo12")
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(dm.InvalidFieldAnnotation):
|
|
|
|
|
|
|
|
|
|
class _(dm.BaseAppliance):
|
|
|
|
|
_: Annotated[str, "foo2"] = "default value2"
|
|
|
|
|
|
|
|
|
|
# annotation is parsed before the library can do anything, so the exception can only be TypeError
|
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
|
|
|
|
|
|
class _(dm.BaseAppliance):
|
|
|
|
|
_: Annotated[str] = "default value2"
|
|
|
|
|
|
|
|
|
|
def test_immutable_fields_inheritance(self):
|
|
|
|
|
"""Testing first appliance level, and Field types (simple)"""
|
|
|
|
|
|
|
|
|
|
# class can be created
|
|
|
|
|
class Appliance1(dm.BaseAppliance):
|
|
|
|
|
StrVar: str = "default value"
|
|
|
|
|
StrVar2: str = "default value2"
|
|
|
|
|
VarInt: int = 12
|
|
|
|
|
VarInt2: int = 21
|
|
|
|
|
VarFloat: float = 12.1
|
|
|
|
|
VarFloat2: float = 21.2
|
|
|
|
|
VarComplex: complex = complex(3, 5)
|
|
|
|
|
VarComplex2: complex = complex(8, 6)
|
|
|
|
|
VarBool: bool = True
|
|
|
|
|
VarBool2: bool = False
|
|
|
|
|
VarBytes: bytes = bytes.fromhex("2Ef0 F1f2 ")
|
|
|
|
|
VarBytes2: bytes = bytes.fromhex("2ff0 F7f2 ")
|
|
|
|
|
|
|
|
|
|
class Appliance2(Appliance1):
|
|
|
|
|
StrVar = "moded value"
|
|
|
|
|
StrVar2 = "moded value2"
|
|
|
|
|
VarInt = 54
|
|
|
|
|
VarInt2 = 23
|
|
|
|
|
VarFloat = 2.6
|
|
|
|
|
VarFloat2 = 1.5
|
|
|
|
|
VarComplex = complex(7, 1)
|
|
|
|
|
VarComplex2 = complex(3, 0)
|
|
|
|
|
VarBool = False
|
|
|
|
|
VarBool2 = True
|
|
|
|
|
VarBytes = bytes.fromhex("21f0 e1f2 ")
|
|
|
|
|
VarBytes2 = bytes.fromhex("2df0 F672 ")
|
|
|
|
|
|
|
|
|
|
app1 = Appliance1()
|
|
|
|
|
|
|
|
|
|
self.immutable_vars__test_field(app1, "StrVar", "default value", "test")
|
|
|
|
|
self.immutable_vars__test_field(app1, "StrVar2", "default value2", "test2")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarInt", 12, 13)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarInt2", 21, 22)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarFloat", 12.1, 32)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarFloat2", 21.2, 42)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarComplex", complex(3, 5), complex(1, 2))
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarComplex2", complex(8, 6), complex(3, 2))
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBool", True, False)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBool2", False, True)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBytes", bytes.fromhex("2Ef0 F1f2 "), bytes.fromhex("11f0 F1f2 "))
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBytes2", bytes.fromhex("2ff0 F7f2 "), bytes.fromhex("11f0 F1e2 "))
|
|
|
|
|
|
|
|
|
|
self.check_immutable_fields_schema(app1, "StrVar", "default value", "default value", str)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "StrVar2", "default value2", "default value2", str)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarInt", 12, 12, int)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarInt2", 21, 21, int)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarFloat", 12.1, 12.1, float)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarFloat2", 21.2, 21.2, float)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarComplex", complex(3, 5), complex(3, 5), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarComplex2", complex(8, 6), complex(8, 6), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBool", True, True, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBool2", False, False, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBytes", bytes.fromhex("2Ef0 F1f2 "), bytes.fromhex("2Ef0 F1f2 "), bytes)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBytes2", bytes.fromhex("2ff0 F7f2 "), bytes.fromhex("2ff0 F7f2 "), bytes)
|
|
|
|
|
|
|
|
|
|
app2 = Appliance2()
|
|
|
|
|
|
|
|
|
|
self.immutable_vars__test_field(app2, "StrVar", "moded value", "test")
|
|
|
|
|
self.immutable_vars__test_field(app2, "StrVar2", "moded value2", "test2")
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarInt", 54, 13)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarInt2", 23, 22)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarFloat", 2.6, 32)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarFloat2", 1.5, 42)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarComplex", complex(7, 1), complex(1, 2))
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarComplex2", complex(3, 0), complex(3, 2))
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarBool", False, False)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarBool2", True, True)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarBytes", bytes.fromhex("21f0 e1f2 "), bytes.fromhex("11f0 F1f2 "))
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarBytes2", bytes.fromhex("2df0 F672 "), bytes.fromhex("11f0 F1e2 "))
|
|
|
|
|
|
|
|
|
|
self.check_immutable_fields_schema(app2, "StrVar", "moded value", "default value", str)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "StrVar2", "moded value2", "default value2", str)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarInt", 54, 12, int)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarInt2", 23, 21, int)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarFloat", 2.6, 12.1, float)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarFloat2", 1.5, 21.2, float)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarComplex", complex(7, 1), complex(3, 5), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarComplex2", complex(3, 0), complex(8, 6), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarBool", False, True, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarBool2", True, False, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarBytes", bytes.fromhex("21f0 e1f2 "), bytes.fromhex("2Ef0 F1f2 "), bytes)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarBytes2", bytes.fromhex("2df0 F672 "), bytes.fromhex("2ff0 F7f2 "), bytes)
|
|
|
|
|
|
|
|
|
|
class Appliance3(Appliance2):
|
|
|
|
|
NewValue: str = "newval"
|
|
|
|
|
|
|
|
|
|
self.assertNotIn("NewValue", Appliance2.__DABSchema__)
|
|
|
|
|
self.assertNotIn("NewValue", app2.__DABSchema__)
|
|
|
|
|
self.assertNotIn("NewValue", Appliance1.__DABSchema__)
|
|
|
|
|
self.assertNotIn("NewValue", app1.__DABSchema__)
|
|
|
|
|
|
|
|
|
|
app3 = Appliance3()
|
|
|
|
|
self.immutable_vars__test_field(app3, "StrVar", "moded value", "test")
|
|
|
|
|
self.immutable_vars__test_field(app3, "StrVar2", "moded value2", "test2")
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarInt", 54, 13)
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarInt2", 23, 22)
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarFloat", 2.6, 32)
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarFloat2", 1.5, 42)
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarComplex", complex(7, 1), complex(1, 2))
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarComplex2", complex(3, 0), complex(3, 2))
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarBool", False, False)
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarBool2", True, True)
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarBytes", bytes.fromhex("21f0 e1f2 "), bytes.fromhex("11f0 F1f2 "))
|
|
|
|
|
self.immutable_vars__test_field(app3, "VarBytes2", bytes.fromhex("2df0 F672 "), bytes.fromhex("11f0 F1e2 "))
|
|
|
|
|
self.immutable_vars__test_field(app3, "NewValue", "newval", "test")
|
|
|
|
|
|
|
|
|
|
self.check_immutable_fields_schema(app3, "StrVar", "moded value", "default value", str)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "StrVar2", "moded value2", "default value2", str)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarInt", 54, 12, int)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarInt2", 23, 21, int)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarFloat", 2.6, 12.1, float)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarFloat2", 1.5, 21.2, float)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarComplex", complex(7, 1), complex(3, 5), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarComplex2", complex(3, 0), complex(8, 6), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarBool", False, True, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarBool2", True, False, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarBytes", bytes.fromhex("21f0 e1f2 "), bytes.fromhex("2Ef0 F1f2 "), bytes)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "VarBytes2", bytes.fromhex("2df0 F672 "), bytes.fromhex("2ff0 F7f2 "), bytes)
|
|
|
|
|
self.check_immutable_fields_schema(app3, "NewValue", "newval", "newval", str)
|
|
|
|
|
|
|
|
|
|
self.immutable_vars__test_field(app1, "StrVar", "default value", "test")
|
|
|
|
|
self.immutable_vars__test_field(app1, "StrVar2", "default value2", "test2")
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarInt", 12, 13)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarInt2", 21, 22)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarFloat", 12.1, 32)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarFloat2", 21.2, 42)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarComplex", complex(3, 5), complex(1, 2))
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarComplex2", complex(8, 6), complex(3, 2))
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBool", True, False)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBool2", False, True)
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBytes", bytes.fromhex("2Ef0 F1f2 "), bytes.fromhex("11f0 F1f2 "))
|
|
|
|
|
self.immutable_vars__test_field(app1, "VarBytes2", bytes.fromhex("2ff0 F7f2 "), bytes.fromhex("11f0 F1e2 "))
|
|
|
|
|
|
|
|
|
|
self.check_immutable_fields_schema(app1, "StrVar", "default value", "default value", str)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "StrVar2", "default value2", "default value2", str)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarInt", 12, 12, int)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarInt2", 21, 21, int)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarFloat", 12.1, 12.1, float)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarFloat2", 21.2, 21.2, float)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarComplex", complex(3, 5), complex(3, 5), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarComplex2", complex(8, 6), complex(8, 6), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBool", True, True, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBool2", False, False, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBytes", bytes.fromhex("2Ef0 F1f2 "), bytes.fromhex("2Ef0 F1f2 "), bytes)
|
|
|
|
|
self.check_immutable_fields_schema(app1, "VarBytes2", bytes.fromhex("2ff0 F7f2 "), bytes.fromhex("2ff0 F7f2 "), bytes)
|
|
|
|
|
|
|
|
|
|
self.immutable_vars__test_field(app2, "StrVar", "moded value", "test")
|
|
|
|
|
self.immutable_vars__test_field(app2, "StrVar2", "moded value2", "test2")
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarInt", 54, 13)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarInt2", 23, 22)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarFloat", 2.6, 32)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarFloat2", 1.5, 42)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarComplex", complex(7, 1), complex(1, 2))
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarComplex2", complex(3, 0), complex(3, 2))
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarBool", False, False)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarBool2", True, True)
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarBytes", bytes.fromhex("21f0 e1f2 "), bytes.fromhex("11f0 F1f2 "))
|
|
|
|
|
self.immutable_vars__test_field(app2, "VarBytes2", bytes.fromhex("2df0 F672 "), bytes.fromhex("11f0 F1e2 "))
|
|
|
|
|
|
|
|
|
|
self.check_immutable_fields_schema(app2, "StrVar", "moded value", "default value", str)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "StrVar2", "moded value2", "default value2", str)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarInt", 54, 12, int)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarInt2", 23, 21, int)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarFloat", 2.6, 12.1, float)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarFloat2", 1.5, 21.2, float)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarComplex", complex(7, 1), complex(3, 5), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarComplex2", complex(3, 0), complex(8, 6), complex)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarBool", False, True, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarBool2", True, False, bool)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarBytes", bytes.fromhex("21f0 e1f2 "), bytes.fromhex("2Ef0 F1f2 "), bytes)
|
|
|
|
|
self.check_immutable_fields_schema(app2, "VarBytes2", bytes.fromhex("2df0 F672 "), bytes.fromhex("2ff0 F7f2 "), bytes)
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(dm.ReadOnlyFieldAnnotation):
|
|
|
|
|
|
|
|
|
|
class _(Appliance1):
|
|
|
|
|
StrVar: int = 12
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(dm.ReadOnlyFieldAnnotation):
|
|
|
|
|
|
|
|
|
|
class _(Appliance3):
|
|
|
|
|
NewValue: int = 12
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(dm.ReadOnlyFieldAnnotation):
|
|
|
|
|
|
|
|
|
|
class _(Appliance3):
|
|
|
|
|
StrVar: int = 12
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- main ----------
|
|
|
|
|
|
|
|
|
|
|