Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
daquintero committed Aug 15, 2024
1 parent 1beb550 commit 52013e2
Show file tree
Hide file tree
Showing 30 changed files with 1,262 additions and 21 deletions.
15 changes: 12 additions & 3 deletions piel/experimental/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from .cables import rg164, generic_sma, generic_banana
from .cables import rg164, generic_sma, generic_banana, cryo_cable
from .multimeter import DMM6500
from .rf_passives import create_power_splitter_1to2
from .rf_passives import (
create_power_splitter_1to2,
create_bias_tee,
create_attenuator,
Picosecond5575A104,
)
from .rf_calibration import (
open_85052D,
short_85052D,
load_85052D,
through_85052D,
)
from .sourcemeter import SMU2450
from .sourcemeter import (
SMU2450,
create_dc_sweep_configuration,
create_dc_operating_point_configuration,
)
from .oscilloscope import create_two_port_oscilloscope, DPO73304
from .waveform_generator import (
create_one_port_square_wave_waveform_generator,
Expand Down
9 changes: 3 additions & 6 deletions piel/experimental/models/rf_passives.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create_power_splitter_1to2(name: Optional[str] = None):
)


def create_bias_tee(name: Optional[str] = None):
def create_bias_tee(name: Optional[str] = None, **kwargs):
if name is None:
name = "bias_tee"

Expand All @@ -53,13 +53,10 @@ def create_bias_tee(name: Optional[str] = None):
),
]

return BiasTee(
name=name,
ports=ports,
)
return BiasTee(name=name, ports=ports, **kwargs)


def create_attenuator(name: Optional[str] = None):
def create_attenuator(name: Optional[str] = None, **kwargs):
if name is None:
name = "attenuator"

Expand Down
1 change: 1 addition & 0 deletions piel/experimental/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from .measurements.data.frequency import (
VNASParameterMeasurementData,
VNASParameterMeasurementDataCollection,
VNAPowerSweepMeasurementData,
)
from .measurements.data.propagation import (
PropagationDelayMeasurementData,
Expand Down
1 change: 1 addition & 0 deletions piel/experimental/types/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Device(PhysicalComponent):
"""

configuration: Optional[DeviceConfiguration] = None
serial_number: str = ""


class MeasurementDevice(Device):
Expand Down
20 changes: 19 additions & 1 deletion piel/experimental/visual/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..analysis.operating_point import (
create_experiment_data_collection_from_unique_parameters,
)
from ...file_system import return_path


def auto_plot_from_measurement_data(
Expand All @@ -31,6 +32,7 @@ def auto_plot_from_measurement_data(
def auto_plot_from_measurement_data_collection(
measurement_data_collection: MeasurementDataCollectionTypes,
plot_output_directory: PathTypes = None,
extra_plot_output_directories: list[PathTypes] = None,
measurement_data_collection_to_plot_map: dict = measurement_data_collection_to_plot_map,
measurement_data_collection_to_plot_prefix_map: dict = measurement_data_collection_to_plot_suffix_map,
**kwargs,
Expand All @@ -42,6 +44,8 @@ def auto_plot_from_measurement_data_collection(
"""
plots = []
plot_path_list = []
extra_plot_file_paths = []
plot_output_directory = return_path(plot_output_directory)

# This creates the mapping between measureemnt collection and the corresponding plots
plot_methods = measurement_data_collection_to_plot_map[
Expand All @@ -58,7 +62,21 @@ def auto_plot_from_measurement_data_collection(
file_name = f"{plot_prefix[i]}_{measurement_data_collection.name}"
plot_file_i = plot_output_directory / f"{file_name}.png"

plot_i = plot_method_i(measurement_data_collection, path=plot_file_i, **kwargs)
if extra_plot_output_directories is not None:
extra_plot_file_paths = []
for extra_plot_output_directory_i in extra_plot_output_directories:
extra_plot_output_directory_i = return_path(
extra_plot_output_directory_i
)
extra_plot_file_i = extra_plot_output_directory_i / f"{file_name}.png"
extra_plot_file_paths.append(extra_plot_file_i)

plot_i = plot_method_i(
measurement_data_collection,
path=plot_file_i,
paths=extra_plot_file_paths,
**kwargs,
)
plots.append(plot_i)
plot_path_list.append(plot_file_i)
i += 1
Expand Down
3 changes: 1 addition & 2 deletions piel/types/connectivity/physical.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Optional
from .abstract import Port, Connection, Component
from ..core import PielBaseModel
from ..environment import Environment
Expand All @@ -10,7 +9,7 @@ class PhysicalPort(Port):
This refers to any form of physical port which can be connected to. The socket refers to the corresponding physical location where such a port is connected to.
"""

domain: Optional[ElectricalSignalDomains] = None
domain: ElectricalSignalDomains | None = None
connector: str = ""
manifold: str = ""

Expand Down
3 changes: 2 additions & 1 deletion piel/types/frequency.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import skrf
from .connectivity.physical import PhysicalComponent
from typing import Any

FrequencyNetworkModel = (
skrf.Network | None
skrf.Network | Any | None
) # TODO temporary nonetype till reserialization
"""
Corresponds to a container that contains a s-parameter representation.
Expand Down
7 changes: 3 additions & 4 deletions piel/types/signal/time_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ class DataTimeSignalData(PielBaseModel):
Sources could be both experimental and simulation.
"""

time_s: ArrayTypes
data: ArrayTypes
data_name: Optional[str]
time_s: ArrayTypes = []
data: ArrayTypes = []
data_name: str = ""


MultiDataTimeSignal = list[DataTimeSignalData, ...]
"""
Collection of DataTimeSignals that can be used to analyse a set of signals together in a particular files flow.
"""

2 changes: 1 addition & 1 deletion piel/types/signal/time_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class PulseSource(PielBaseModel):
voltage_1_V: float = Field(..., description="Initial voltage level (V1) in volts")
voltage_1_V: float = Field(0, description="Initial voltage level (V1) in volts")
voltage_2_V: float = Field(..., description="Pulsed voltage level (V2) in volts")
delay_time_s: float = Field(..., description="Delay time (TD) in seconds")
rise_time_s: float = Field(..., description="Rise time (TR) in seconds")
Expand Down
Empty file added tests/experimental/__init__.py
Empty file.
Empty file.
Empty file.
52 changes: 52 additions & 0 deletions tests/experimental/measurements/data/test_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from piel.experimental.types import (
ExperimentData,
ExperimentDataCollection,
Experiment,
PropagationDelayMeasurementDataCollection,
)
from piel.types import Instance


# Test ExperimentData
def test_experiment_data_initialization():
experiment = Experiment(name="Test Experiment")
measurement_data = (
PropagationDelayMeasurementDataCollection()
) # Use appropriate mock or actual type

experiment_data = ExperimentData(experiment=experiment, data=measurement_data)

assert isinstance(experiment_data, Instance)
assert experiment_data.experiment == experiment
assert experiment_data.data == measurement_data


def test_experiment_data_default_initialization():
experiment_data = ExperimentData()

assert isinstance(experiment_data, Instance)
assert experiment_data.experiment is None
assert experiment_data.data is None


# Test ExperimentDataCollection
def test_experiment_data_collection_initialization():
experiment_data_1 = ExperimentData()
experiment_data_2 = ExperimentData()

data_collection = ExperimentDataCollection(
collection=[experiment_data_1, experiment_data_2]
)

assert isinstance(data_collection, Instance)
assert data_collection.collection == [experiment_data_1, experiment_data_2]


def test_experiment_data_collection_default_initialization():
data_collection = ExperimentDataCollection()

assert isinstance(data_collection, Instance)
assert data_collection.collection == []


# Add more tests as needed for validators, edge cases, and behaviors.
87 changes: 87 additions & 0 deletions tests/experimental/measurements/data/test_frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from piel.experimental.types import (
VNASParameterMeasurementData,
VNASParameterMeasurementDataCollection,
VNAPowerSweepMeasurementData,
MeasurementData,
MeasurementDataCollection,
)


# Test VNASParameterMeasurementData
def test_vna_sparameter_measurement_data_initialization():
measurement_data = VNASParameterMeasurementData()

assert isinstance(measurement_data, MeasurementData)
assert measurement_data.type == "VNASParameterMeasurementData"
assert measurement_data.network is None


def test_vna_sparameter_measurement_data_default_initialization():
measurement_data = VNASParameterMeasurementData()

assert isinstance(measurement_data, MeasurementData)
assert measurement_data.type == "VNASParameterMeasurementData"
assert measurement_data.network is None


# Test VNAPowerSweepMeasurementData
def test_vna_power_sweep_measurement_data_initialization():
network = None
measurement_data = VNAPowerSweepMeasurementData(network=network)

assert isinstance(measurement_data, MeasurementData)
assert measurement_data.type == "VNAPowerSweepMeasurementData"
assert measurement_data.network is None


def test_vna_power_sweep_measurement_data_default_initialization():
measurement_data = VNAPowerSweepMeasurementData()

assert isinstance(measurement_data, MeasurementData)
assert measurement_data.type == "VNAPowerSweepMeasurementData"
assert measurement_data.network is None


# Test VNASParameterMeasurementDataCollection
def test_vna_sparameter_measurement_data_collection_initialization():
measurement_data_1 = VNASParameterMeasurementData()
measurement_data_2 = VNASParameterMeasurementData()

data_collection = VNASParameterMeasurementDataCollection(
collection=[measurement_data_1, measurement_data_2]
)

assert isinstance(data_collection, MeasurementDataCollection)
assert data_collection.type == "VNASParameterMeasurementDataCollection"
assert data_collection.collection == [measurement_data_1, measurement_data_2]


def test_vna_sparameter_measurement_data_collection_default_initialization():
data_collection = VNASParameterMeasurementDataCollection()

assert isinstance(data_collection, MeasurementDataCollection)
assert data_collection.type == "VNASParameterMeasurementDataCollection"
assert data_collection.collection == []


# Test FrequencyMeasurementDataCollection with mixed types
def test_frequency_measurement_data_collection_initialization():
sparam_data = VNASParameterMeasurementData()
power_sweep_data = VNAPowerSweepMeasurementData()

data_collection = VNASParameterMeasurementDataCollection()

assert isinstance(data_collection, MeasurementDataCollection)
assert data_collection.type == "VNASParameterMeasurementDataCollection"
assert data_collection.collection == []


def test_frequency_measurement_data_collection_default_initialization():
data_collection = VNASParameterMeasurementDataCollection()

assert isinstance(data_collection, MeasurementDataCollection)
assert data_collection.type == "VNASParameterMeasurementDataCollection"
assert data_collection.collection == []


# Add more tests as needed for additional methods, edge cases, and behaviors.
64 changes: 64 additions & 0 deletions tests/experimental/measurements/data/test_propagation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from piel.experimental.types import (
PropagationDelayMeasurementData,
PropagationDelayMeasurementDataCollection,
MeasurementData,
MeasurementDataCollection,
)
from piel.types import (
DataTimeSignalData,
SignalMetricsMeasurementCollection,
)


# Test PropagationDelayMeasurementData
def test_propagation_delay_measurement_data_initialization():
signal_metrics = SignalMetricsMeasurementCollection()
dut_waveform = DataTimeSignalData()
reference_waveform = DataTimeSignalData()

measurement_data = PropagationDelayMeasurementData(
measurements=signal_metrics,
dut_waveform=dut_waveform,
reference_waveform=reference_waveform,
)

assert isinstance(measurement_data, MeasurementData)
assert measurement_data.type == "PropagationDelayMeasurementData"
assert measurement_data.measurements == signal_metrics
assert measurement_data.dut_waveform == dut_waveform
assert measurement_data.reference_waveform == reference_waveform


def test_propagation_delay_measurement_data_default_initialization():
measurement_data = PropagationDelayMeasurementData()

assert isinstance(measurement_data, MeasurementData)
assert measurement_data.type == "PropagationDelayMeasurementData"
assert measurement_data.measurements is None
assert measurement_data.dut_waveform is None
assert measurement_data.reference_waveform is None


# Test PropagationDelayMeasurementDataCollection
def test_propagation_delay_measurement_data_collection_initialization():
data_1 = PropagationDelayMeasurementData()
data_2 = PropagationDelayMeasurementData()

data_collection = PropagationDelayMeasurementDataCollection(
collection=[data_1, data_2]
)

assert isinstance(data_collection, MeasurementDataCollection)
assert data_collection.type == "PropagationDelayMeasurementDataCollection"
assert data_collection.collection == [data_1, data_2]


def test_propagation_delay_measurement_data_collection_default_initialization():
data_collection = PropagationDelayMeasurementDataCollection()

assert isinstance(data_collection, MeasurementDataCollection)
assert data_collection.type == "PropagationDelayMeasurementDataCollection"
assert data_collection.collection == []


# Add more tests as needed for additional methods, edge cases, and behaviors.
Loading

0 comments on commit 52013e2

Please sign in to comment.