Skip to content

Commit

Permalink
Merge pull request #12 from qua-platform/fix/tests-3.11
Browse files Browse the repository at this point in the history
Fix/tests 3.11
  • Loading branch information
nulinspiratie authored Feb 16, 2024
2 parents 961b17a + 1897af6 commit 27061f7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/instantiation/test_instantiate_explicit_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class QuamComponentTest(QuamComponent):


def test_instantiate_from_class():
quam_component = QuamComponentTest("hi")
quam_component = QuamComponentTest(str_val="hi")
loaded_component = instantiate_quam_class(
QuamComponentTest, quam_component.to_dict()
)
Expand Down
26 changes: 18 additions & 8 deletions tests/quam_base/test_quam_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class C:
with pytest.raises(TypeError):
c = C()

c = C(1)
c = C(int_val=1)
assert is_dataclass(c)
assert c.int_val == 1

Expand All @@ -50,7 +50,7 @@ class C:
with pytest.raises(TypeError):
c = C()

c = C(2)
c = C(int_val=2)
assert is_dataclass(c)
assert c.int_val == 2
assert c.int_val_optional == 42
Expand All @@ -75,7 +75,7 @@ class DerivedClass(BaseClass):
with pytest.raises(TypeError):
d = DerivedClass(42)

d = DerivedClass(42, 43)
d = DerivedClass(int_val=42, int_val2=43)

f = fields(d)
assert len(f) == 2
Expand All @@ -94,8 +94,10 @@ class DerivedClass(BaseClass):

with pytest.raises(TypeError):
d = DerivedClass()
with pytest.raises(TypeError):
d = DerivedClass(int_val2=42)

d = DerivedClass(42)
d = DerivedClass(int_val=42)

assert d.int_val == 42
assert d.int_val2 == 43
Expand All @@ -104,7 +106,7 @@ class DerivedClass(BaseClass):
assert f[0].name == "int_val"
assert f[1].name == "int_val2"

d = DerivedClass(42, 44)
d = DerivedClass(int_val=42, int_val2=44)

assert d.int_val == 42
assert d.int_val2 == 44
Expand All @@ -131,12 +133,18 @@ class DerivedClass(BaseClass):
with pytest.raises(TypeError):
d = DerivedClass(43)

d = DerivedClass(43, 45)
with pytest.raises(TypeError):
d = DerivedClass(int_val=43)

with pytest.raises(TypeError):
d = DerivedClass(int_val3=43)

d = DerivedClass(int_val=43, int_val2=45)
assert d.int_val == 43
assert d.int_val2 == 45
assert d.int_val3 == 44

d = DerivedClass(43, 45, 46)
d = DerivedClass(int_val=43, int_val2=45, int_val3=46)
assert d.int_val == 43
assert d.int_val2 == 45
assert d.int_val3 == 46
Expand Down Expand Up @@ -187,8 +195,10 @@ class C:
assert is_dataclass(C)
with pytest.raises(TypeError):
c = C()
with pytest.raises(TypeError):
c = C(int_val_optional=42)

c = C(2)
c = C(int_val=2)
assert is_dataclass(c)
assert c.int_val == 2
assert c.int_val_optional == 42
Expand Down
6 changes: 3 additions & 3 deletions tests/quam_base/test_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class QuamTest(QuamComponent):


def test_list_with_component_to_dict():
c = QuamTest(42)
c = QuamTest(int_val=42)
quam_list = QuamList([c])
assert quam_list.to_dict() == [
{"int_val": 42, "__class__": "test_to_dict.QuamTest"}
Expand All @@ -37,7 +37,7 @@ def test_basic_dict_to_dict():


def test_dict_with_component_to_dict():
c = QuamTest(42)
c = QuamTest(int_val=42)
quam_dict = QuamDict({"a": c})
assert quam_dict.to_dict() == {
"a": {"int_val": 42, "__class__": "test_to_dict.QuamTest"}
Expand Down Expand Up @@ -141,4 +141,4 @@ class QuamBasicComponent(QuamComponent):
assert quam_component.to_dict() == {}

quam_component = QuamBasicComponent(l=[1, 2, 3])
assert quam_component.to_dict() == {"l": [1, 2, 3]}
assert quam_component.to_dict() == {"l": [1, 2, 3]}
12 changes: 8 additions & 4 deletions tests/quam_base/test_val_matches_attr_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class QuamTest(QuamComponent):


def test_attr_type_nonexisting():
test_quam = QuamTest(1, "test")
test_quam = QuamTest(int_val=1, str_val="test")
assert not test_quam._val_matches_attr_annotation("nonexisting", None)
assert not test_quam._val_matches_attr_annotation("nonexisting", 123)


def test_attr_type_basic():
test_quam = QuamTest(1, "test")
test_quam = QuamTest(int_val=1, str_val="test")
assert test_quam._val_matches_attr_annotation("int_val", 1)
assert test_quam._val_matches_attr_annotation("str_val", "hi")
assert not test_quam._val_matches_attr_annotation("int_val", "hi")
Expand All @@ -33,15 +33,19 @@ class QuamTest2(QuamComponent):


def test_attr_type_dict():
test_quam = QuamTest2(1, "test", [1, 2, 3], [1, 2, 3], {"a": 1}, {"a": 1})
test_quam = QuamTest2(
int_val=1, str_val="test", l1=[1, 2, 3], l2=[1, 2, 3], d1={"a": 1}, d2={"a": 1}
)
assert test_quam._val_matches_attr_annotation("d1", {})
assert test_quam._val_matches_attr_annotation("d2", {})
assert not test_quam._val_matches_attr_annotation("d1", 42)
assert not test_quam._val_matches_attr_annotation("d2", 42)


def test_attr_type_list():
test_quam = QuamTest2(1, "test", [1, 2, 3], [1, 2, 3], {"a": 1}, {"a": 1})
test_quam = QuamTest2(
int_val=1, str_val="test", l1=[1, 2, 3], l2=[1, 2, 3], d1={"a": 1}, d2={"a": 1}
)
assert test_quam._val_matches_attr_annotation("l1", [])
assert test_quam._val_matches_attr_annotation("l2", [])
assert not test_quam._val_matches_attr_annotation("l1", 42)
Expand Down
6 changes: 3 additions & 3 deletions tests/quam_base/test_value_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestQuam(QuamComponent):
int_val: int
str_val: str

test_quam = TestQuam(1, "test")
test_quam = TestQuam(int_val=1, str_val="test")
assert _get_value_annotation(test_quam, "nonexisting") is None
assert _get_value_annotation(test_quam, "int_val") is None
assert _get_value_annotation(test_quam, "str_val") is None
Expand All @@ -24,7 +24,7 @@ class TestQuam(QuamComponent):
d1: dict
d2: Dict[str, int]

test_quam = TestQuam(1, "test", {"a": 1}, {"a": 1})
test_quam = TestQuam(int_val=1, str_val="test", d1={"a": 1}, d2={"a": 1})
assert _get_value_annotation(test_quam, "d1") is None
assert _get_value_annotation(test_quam, "str_val") is None
assert _get_value_annotation(test_quam, "d2") == int
Expand All @@ -38,7 +38,7 @@ class TestQuam(QuamComponent):
l1: list
l2: List[int]

test_quam = TestQuam(1, "test", [1, 2, 3], [1, 2, 3])
test_quam = TestQuam(int_val=1, str_val="test", l1=[1, 2, 3], l2=[1, 2, 3])
assert _get_value_annotation(test_quam, "l1") is None
assert _get_value_annotation(test_quam, "str_val") is None
assert _get_value_annotation(test_quam, "l2") == int
Expand Down

0 comments on commit 27061f7

Please sign in to comment.