From 491d994ced36e56bd1bc039efe6dfbe98817d513 Mon Sep 17 00:00:00 2001 From: Serwan Asaad Date: Wed, 11 Dec 2024 16:31:07 +0100 Subject: [PATCH 1/2] Fix: Referencing issues in Quam Root --- CHANGELOG.md | 4 +++ quam/core/quam_classes.py | 3 -- .../referencing/test_quam_root_referencing.py | 36 +++++++++++++++++++ tests/{ => quam_base}/test_quam_get_attrs.py | 0 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/quam_base/referencing/test_quam_root_referencing.py rename tests/{ => quam_base}/test_quam_get_attrs.py (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8860f11..a1468336 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [Unreleased] +### Fixed +- Fixed issues with parameters being references in a QuamRoot object + ## [0.3.8] ### Added - Added time tagging to channels diff --git a/quam/core/quam_classes.py b/quam/core/quam_classes.py index 296c3e91..f3235ebf 100644 --- a/quam/core/quam_classes.py +++ b/quam/core/quam_classes.py @@ -682,9 +682,6 @@ def generate_config(self) -> Dict[str, Any]: return qua_config - def get_unreferenced_value(self, attr: str): - return getattr(self, attr) - class QuamComponent(QuamBase): """Base class for any QuAM component class. diff --git a/tests/quam_base/referencing/test_quam_root_referencing.py b/tests/quam_base/referencing/test_quam_root_referencing.py new file mode 100644 index 00000000..37d3f31f --- /dev/null +++ b/tests/quam_base/referencing/test_quam_root_referencing.py @@ -0,0 +1,36 @@ +from quam import QuamRoot, QuamComponent, quam_dataclass +import pytest + + +@quam_dataclass +class Component(QuamComponent): + y: int = 2 + + +@quam_dataclass +class Root(QuamRoot): + a: Component + b: Component = "#/a" + + +def test_quam_root_reference(): + with pytest.warns(None) as record: + root = Root(a=Component()) + assert root.a is root.b + + # Ensure no warnings were raised + assert len(record) == 0 + + +def test_quam_root_reference_to_dict(): + with pytest.warns(None) as record: + root = Root(a="#/b", b=Component()) + d = root.to_dict() + assert d == { + "a": "#/b", + "b": {}, + "__class__": "test_quam_root_referencing.Root", + } + + # Ensure no warnings were raised + assert len(record) == 0 diff --git a/tests/test_quam_get_attrs.py b/tests/quam_base/test_quam_get_attrs.py similarity index 100% rename from tests/test_quam_get_attrs.py rename to tests/quam_base/test_quam_get_attrs.py From 80dcca59566dab6b318812e6eaf5cacef6d7ef73 Mon Sep 17 00:00:00 2001 From: Serwan Asaad Date: Wed, 11 Dec 2024 17:07:33 +0100 Subject: [PATCH 2/2] change warning catch --- .../referencing/test_quam_root_referencing.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/quam_base/referencing/test_quam_root_referencing.py b/tests/quam_base/referencing/test_quam_root_referencing.py index 37d3f31f..25fbfeb8 100644 --- a/tests/quam_base/referencing/test_quam_root_referencing.py +++ b/tests/quam_base/referencing/test_quam_root_referencing.py @@ -1,5 +1,5 @@ from quam import QuamRoot, QuamComponent, quam_dataclass -import pytest +import warnings @quam_dataclass @@ -14,16 +14,15 @@ class Root(QuamRoot): def test_quam_root_reference(): - with pytest.warns(None) as record: + with warnings.catch_warnings(): + warnings.simplefilter("error") root = Root(a=Component()) assert root.a is root.b - # Ensure no warnings were raised - assert len(record) == 0 - def test_quam_root_reference_to_dict(): - with pytest.warns(None) as record: + with warnings.catch_warnings(): + warnings.simplefilter("error") root = Root(a="#/b", b=Component()) d = root.to_dict() assert d == { @@ -31,6 +30,3 @@ def test_quam_root_reference_to_dict(): "b": {}, "__class__": "test_quam_root_referencing.Root", } - - # Ensure no warnings were raised - assert len(record) == 0