Skip to content

Commit

Permalink
tests(refactor): use default factory of Field class instead of []
Browse files Browse the repository at this point in the history
Usage of `[]` can cause issues because of closure
  • Loading branch information
maxim-v4s committed Oct 21, 2024
1 parent b26726d commit 2348b1d
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 131 deletions.
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pytest
from pydantic import Field

from qualibrate import NodeParameters, QualibrationNode


@pytest.fixture
def node():
class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)

str_value: str = "test"
int_value: int = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pydantic import Field

from qualibrate import NodeParameters, QualibrationNode


class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)


node = QualibrationNode("basic_node", parameters=Parameters())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import ClassVar

from pydantic import Field

from qualibrate import NodeParameters, QualibrationNode
from qualibrate.models.outcome import Outcome


class Parameters(NodeParameters):
targets_name: ClassVar[str] = "qubits"
qubits: list[str] = ["q0", "q1", "q2"]
qubits: list[str] = Field(default_factory=lambda: ["q0", "q1", "q2"])


node = QualibrationNode("node_part_outcome", parameters=Parameters())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pydantic import Field

from qualibrate import NodeParameters, QualibrationNode
from qualibrate.models.outcome import Outcome


class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)

str_value: str = "test"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pydantic import Field

from qualibrate import NodeParameters, QualibrationNode
from qualibrate.models.outcome import Outcome


class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)

float_value: float = 1.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pydantic import Field

from qualibrate import NodeParameters, QualibrationNode


class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)

int_value: int = 2

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pydantic import Field

from qualibrate import QualibrationNode, NodeParameters


class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)

sampling_points: int = 100

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Generator

import pytest
from pydantic import Field

from qualibrate.models.execution_history import ExecutionHistoryItem
from qualibrate.models.node_status import NodeStatus
Expand All @@ -24,7 +25,9 @@ def qualibration_lib() -> Generator[QualibrationLibrary, None, None]:
@pytest.fixture
def graph_params() -> GraphParameters:
class GP(GraphParameters):
qubits: list[str] = ["q1", "q2", "q3", "q4"]
qubits: list[str] = Field(
default_factory=lambda: ["q1", "q2", "q3", "q4"]
)
retries: int = 2

return GP()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pydantic import Field

from qualibrate import NodeParameters, QualibrationNode


class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)
str_value: str = "test"
int_value: int = 1
float_value: float = 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pydantic import Field

from qualibrate import NodeParameters, QualibrationNode


class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)

str_value: str = "test"
float_value: float = 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pydantic import Field

from qualibrate import QualibrationNode, NodeParameters
from quam.components import *
import numpy as np
Expand All @@ -6,7 +8,7 @@


class Parameters(NodeParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)

resonator: str = "q1.resonator"
sampling_points: int = 100
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_qualibration_graph/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Generator, Sequence

import pytest
from pydantic import Field

from qualibrate.orchestration.qualibration_orchestrator import (
QualibrationOrchestrator,
Expand All @@ -23,7 +24,7 @@ def qualibration_lib() -> Generator[QualibrationLibrary, None, None]:
@pytest.fixture
def graph_params() -> GraphParameters:
class GP(GraphParameters):
qubits: list[str] = []
qubits: list[str] = Field(default_factory=list)
retries: int = 2

return GP(retries=1)
Expand Down
Loading

0 comments on commit 2348b1d

Please sign in to comment.