Skip to content

Commit

Permalink
Move fixtures to confeste.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pimvenderbosch committed Nov 6, 2024
1 parent c0db241 commit c8f4a04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
28 changes: 28 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
25 changes: 0 additions & 25 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit c8f4a04

Please sign in to comment.