From c8f4a042cda78a170385c3d7a5263afc2877188a Mon Sep 17 00:00:00 2001 From: Pim Venderbosch Date: Wed, 6 Nov 2024 15:06:33 +0100 Subject: [PATCH] Move fixtures to confeste.py --- tests/conftest.py | 28 ++++++++++++++++++++++++++++ tests/test_types.py | 25 ------------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index a891657..da182a9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,9 +2,12 @@ # functions common to every test from __future__ import annotations +from copy import deepcopy + import pytest from qadence2_ir.irast import AST +from qadence2_ir.types import Alloc, AllocQubits, Assign, Model, QuInstruct, Support @pytest.fixture @@ -26,3 +29,28 @@ def quantum_ast() -> AST: q_op = AST.quantum_op("rx", (0,), (1,), fn) return q_op + + +@pytest.fixture +def support_control_target() -> Support: + return Support((0,), (1,)) + + +@pytest.fixture +def simple_model() -> Model: + register = AllocQubits(3) + inputs = {"input1": Alloc(1, False), "input2": Alloc(4, True)} + instructions: list[Assign | QuInstruct] = [ + Assign("var1", 10), + QuInstruct("CNOT", Support((0,), (1,))), + QuInstruct("RX", Support.target_all(), 3.14), + ] + return Model(register, inputs, instructions) + + +@pytest.fixture +def model_with_directives_settings(simple_model: Model) -> Model: + new_model = deepcopy(simple_model) + new_model.directives = {"option1": 3, "option2": True} + new_model.settings = {"setting1": 18.0} + return new_model diff --git a/tests/test_types.py b/tests/test_types.py index 6b861bb..8dbcf92 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -97,11 +97,6 @@ def test_support_eq() -> None: assert Support((3,)) != "Support((3,))" -@pytest.fixture -def support_control_target() -> Support: - return Support((0,), (1,)) - - def test_qu_instruct_repr(support_control_target: Support) -> None: assert ( repr(QuInstruct("CNOT", support_control_target)) @@ -147,26 +142,6 @@ def test_alloc_qubits_eq() -> None: assert AllocQubits(3).__eq__("3-qubits") is NotImplemented -@pytest.fixture -def simple_model() -> Model: - register = AllocQubits(3) - inputs = {"input1": Alloc(1, False), "input2": Alloc(4, True)} - instructions: list[Assign | QuInstruct] = [ - Assign("var1", 10), - QuInstruct("CNOT", Support((0,), (1,))), - QuInstruct("RX", Support.target_all(), 3.14), - ] - return Model(register, inputs, instructions) - - -@pytest.fixture -def model_with_directives_settings(simple_model: Model) -> Model: - new_model = deepcopy(simple_model) - new_model.directives = {"option1": 3, "option2": True} - new_model.settings = {"setting1": 18.0} - return new_model - - def test_model_repr(simple_model: Model, model_with_directives_settings: Model) -> None: expected = f"""Model( {simple_model.register},