Skip to content

Commit 0cdf4d0

Browse files
committed
using sim.updated_copy()
1 parent f931470 commit 0cdf4d0

1 file changed

Lines changed: 28 additions & 34 deletions

File tree

tests/test_components/test_simulation.py

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,49 +3653,43 @@ def test_create_sim_multiphysics_with_incompatibilities():
36533653
def test_messages_contain_object_names():
36543654
"""Make sure that errors and warnings contain the name of the object."""
36553655
# Note: This function currently tests for out-of-bounds errors and warnings.
3656-
sim_args = {
3657-
"size": (1, 1, 1),
3658-
"grid_spec": td.GridSpec.auto(wavelength=4),
3659-
"run_time": 1e-12,
3660-
}
3656+
# Create an empty simulation.
3657+
sim = td.Simulation(
3658+
size=(1, 1, 1),
3659+
grid_spec=td.GridSpec.auto(wavelength=4),
3660+
run_time=1e-12,
3661+
)
36613662

36623663
# Test 1) Create a structure lying outside the simulation boundary.
36633664
# Check that a warning message is generated containing the structure's `name`.
3664-
structure_args = {
3665-
"geometry": td.Box(center=(1.0, 0.0, 0.0), size=(0.5, 0.5, 0.5)),
3666-
"medium": td.Medium(permittivity=2.0),
3667-
}
3668-
with AssertLogLevel("WARNING", contains_str="structure_123"):
3665+
name = "structure_123"
3666+
structure = td.Structure(
3667+
name=name,
3668+
geometry=td.Box(center=(1.0, 0.0, 0.0), size=(0.5, 0.5, 0.5)),
3669+
medium=td.Medium(permittivity=2.0),
3670+
)
3671+
with AssertLogLevel("WARNING", contains_str=name):
36693672
# Create a simulation with this structure.
3670-
_ = td.Simulation(
3671-
structures=[td.Structure(name="structure_123", **structure_args)],
3672-
**sim_args,
3673-
)
3673+
_ = sim.updated_copy(structures=[structure])
36743674

36753675
# Test 2) Create a source lying outside the simulation boundary.
36763676
# Check that an error message is generated containing the source's `name`.
3677-
source_args = {
3678-
"center": (0, -1.0, 0),
3679-
"size": (1, 0, 0.5),
3680-
"polarization": "Ex",
3681-
"source_time": td.GaussianPulse(
3682-
freq0=100e14,
3683-
fwidth=10e14,
3684-
),
3685-
}
3686-
with pytest.raises(pydantic.ValidationError, match="source_123") as e:
3677+
name = "source_123"
3678+
source = td.UniformCurrentSource(
3679+
name=name,
3680+
center=(0, -1.0, 0),
3681+
size=(1, 0, 0.5),
3682+
polarization="Ex",
3683+
source_time=td.GaussianPulse(freq0=100e14, fwidth=10e14),
3684+
)
3685+
with pytest.raises(pydantic.ValidationError, match=name) as e:
36873686
# Create a simulation with this source.
3688-
_ = td.Simulation(
3689-
sources=[td.UniformCurrentSource(name="source_123", **source_args)],
3690-
**sim_args,
3691-
)
3687+
_ = sim.updated_copy(sources=[source])
36923688

36933689
# Test 3) Create a monitor lying outside the simulation boundary.
36943690
# Check that an error message is generated containing the monitor's `name`.
3695-
monitor_args = {"center": (-1.0, 0, 0), "size": (0.5, 0, 1), "freqs": [100e14]}
3696-
with pytest.raises(pydantic.ValidationError, match="monitor_123") as e:
3691+
name = "monitor_123"
3692+
monitor = td.FieldMonitor(name=name, center=(-1.0, 0, 0), size=(0.5, 0, 1), freqs=[100e14])
3693+
with pytest.raises(pydantic.ValidationError, match=name) as e:
36973694
# Create a simulation with this monitor.
3698-
_ = td.Simulation(
3699-
monitors=[td.FieldMonitor(name="monitor_123", **monitor_args)],
3700-
**sim_args,
3701-
)
3695+
_ = sim.updated_copy(monitors=[monitor])

0 commit comments

Comments
 (0)