Skip to content

Commit 59ada6c

Browse files
marcorudolphflexmahlau-flex
authored andcommitted
fix(tidy3d): FXC-5094-fix-deprecation-warnings-in-tests
1 parent c17299a commit 59ada6c

98 files changed

Lines changed: 425 additions & 359 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/config/test_legacy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
def test_legacy_logging_level(config_manager):
1111
cfg = reload_config(profile=config_manager.profile)
12-
cfg.logging_level = "DEBUG"
12+
with pytest.warns(
13+
DeprecationWarning,
14+
match=r"config\.logging_level.*deprecated",
15+
):
16+
cfg.logging_level = "DEBUG"
1317
manager = get_manager()
1418
assert manager.get_section("logging").level == "DEBUG"
1519

tests/config/test_legacy_env.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
from __future__ import annotations
22

3+
import importlib
34
import os
45
import ssl
56
import warnings
67

8+
import pytest
9+
710
from tidy3d.config import Env, get_manager, reload_config
811
from tidy3d.config import config as config_wrapper
912

1013

14+
@pytest.fixture
15+
def suppress_legacy_env_deprecated_warning(monkeypatch):
16+
"""Patch Env deprecation helper to a no-op for tests that don't want the warning."""
17+
legacy_module = importlib.import_module("tidy3d.config.legacy")
18+
monkeypatch.setattr(legacy_module, "_warn_env_deprecated", lambda: None)
19+
20+
1121
def test_env_tracks_profile_switch(config_manager):
1222
"""Regression: Env should mirror manager profile switches."""
1323

@@ -21,7 +31,11 @@ def test_env_tracks_profile_switch(config_manager):
2131
reload_config(profile="default")
2232

2333

24-
def test_env_pending_overrides_apply_on_activation(mock_config_dir, config_manager):
34+
def test_env_pending_overrides_apply_on_activation(
35+
mock_config_dir,
36+
config_manager,
37+
suppress_legacy_env_deprecated_warning,
38+
):
2539
"""Queued overrides should land once the corresponding profile is activated."""
2640

2741
del mock_config_dir
@@ -50,7 +64,12 @@ def test_env_pending_overrides_apply_on_activation(mock_config_dir, config_manag
5064
reload_config(profile="default")
5165

5266

53-
def test_env_vars_follow_profile_switch(mock_config_dir, monkeypatch, config_manager):
67+
def test_env_vars_follow_profile_switch(
68+
mock_config_dir,
69+
monkeypatch,
70+
config_manager,
71+
suppress_legacy_env_deprecated_warning,
72+
):
5473
"""Environment variables applied via Env should restore previous values on switch."""
5574

5675
del mock_config_dir

tests/test_components/autograd/test_autograd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ def test_custom_sellmeier(monkeypatch):
21572157
def eps_from(B, C):
21582158
return 1.0 + B * lam2 / (lam2 - C)
21592159

2160-
eps_arr = eps_from(B1.values, C1.values) + eps_from(B2.values, C2.values)
2160+
eps_arr = eps_from(B1.values, C1.values) + eps_from(B2.values, C2.values) + 0j
21612161
dJ = np.conj(ag.holomorphic_grad(lambda e: anp.sum(anp.abs(e)))(eps_arr))
21622162

21632163
_patch_cmp_custom_to_const(monkeypatch, td.CustomSellmeier, dJ)

tests/test_components/autograd/test_autograd_custom_dispersive_vjps.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def test_custom_sellmeier_vjp():
8080

8181
freq = 2.5e14
8282
lam2 = (C_0 / freq) ** 2
83-
eps_arr = 1.0 + B1.values * lam2 / (lam2 - C1.values) + B2.values * lam2 / (lam2 - C2.values)
83+
eps_arr = (
84+
1.0 + B1.values * lam2 / (lam2 - C1.values) + B2.values * lam2 / (lam2 - C2.values) + 0j
85+
)
8486
dJ = np.conj(ag.holomorphic_grad(_J)(eps_arr))
8587

8688
# Monkeypatch derivative provider
@@ -131,7 +133,7 @@ def test_custom_lorentz_vjp():
131133
eps_inf.values
132134
+ (de1.values * (f01.values**2)) / den1
133135
+ (de2.values * (f02.values**2)) / den2
134-
)
136+
) + 0j
135137
dJ = np.conj(ag.holomorphic_grad(_J)(eps_arr))
136138

137139
from tidy3d.components import medium as medium_mod
@@ -188,7 +190,7 @@ def test_custom_drude_vjp():
188190

189191
den1 = Drude._den(freq, dl1.values)
190192
den2 = Drude._den(freq, dl2.values)
191-
eps_arr = eps_inf.values - (fp1.values**2) / den1 - (fp2.values**2) / den2
193+
eps_arr = eps_inf.values - (fp1.values**2) / den1 - (fp2.values**2) / den2 + 0j
192194
dJ = np.conj(ag.holomorphic_grad(_J)(eps_arr))
193195

194196
from tidy3d.components import medium as medium_mod
@@ -239,7 +241,7 @@ def test_custom_debye_vjp():
239241

240242
den1 = Debye._den(freq, tau1.values)
241243
den2 = Debye._den(freq, tau2.values)
242-
eps_arr = eps_inf.values + de1.values / den1 + de2.values / den2
244+
eps_arr = eps_inf.values + de1.values / den1 + de2.values / den2 + 0j
243245
dJ = np.conj(ag.holomorphic_grad(_J)(eps_arr))
244246

245247
from tidy3d.components import medium as medium_mod

tests/test_components/autograd/test_autograd_rf_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import tidy3d as td
1212
import tidy3d.web as web
1313

14-
td.config.logging_level = "ERROR"
14+
td.config.logging.level = "ERROR"
1515

1616
PLOT_FD_ADJ_COMPARISON = False
1717
NUM_BOXES_PER_FD_TESTS = 1

tests/test_components/autograd/test_autograd_rf_polyslab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import tidy3d as td
1212
import tidy3d.web as web
1313

14-
td.config.logging_level = "ERROR"
14+
td.config.logging.level = "ERROR"
1515

1616
PLOT_FD_ADJ_COMPARISON = False
1717
NUM_VERTICES_PER_FD_TESTS = 10

tests/test_components/test_heat_charge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ def test_heat_conduction_simulations():
24592459
# test error if structures aren't conducting
24602460
with pytest.raises(ValidationError):
24612461
struct_error = struct1.updated_copy(
2462-
medium=struct1.medium.updated_copy(charge=td.ChargeInsulatorMedium)
2462+
medium=struct1.medium.updated_copy(charge=td.ChargeInsulatorMedium())
24632463
)
24642464
_ = sim.updated_copy(structures=[struct_error])
24652465

tests/test_components/test_microwave.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,15 @@ def test_composite_current_integral_validation():
564564

565565
current_spec = td.AxisAlignedCurrentIntegralSpec(center=(1, 2, 3), size=(0, 1, 1), sign="-")
566566
voltage_spec = td.AxisAlignedVoltageIntegralSpec(center=(1, 2, 3), size=(0, 0, 1), sign="-")
567-
path_spec = td.CompositeCurrentIntegralSpec(path_specs=[current_spec], sum_spec="sum")
568-
567+
path_spec = td.CompositeCurrentIntegralSpec(path_specs=(current_spec,), sum_spec="sum")
569568
with pytest.raises(pd.ValidationError):
570569
path_spec.updated_copy(path_specs=[])
571-
572-
with pytest.raises(pd.ValidationError):
573-
path_spec.updated_copy(path_specs=[voltage_spec])
570+
with pytest.warns(
571+
UserWarning,
572+
match=r"(?s)Pydantic serializer warnings:.*path_specs.*",
573+
):
574+
with pytest.raises(pd.ValidationError):
575+
path_spec.updated_copy(path_specs=[voltage_spec])
574576

575577

576578
def test_composite_current_integral_bounds():

tests/test_components/test_mode_interp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,11 +967,11 @@ def test_mode_solver_data_stored_freqs(num_freqs, num_points, reduce_data, expec
967967
)
968968

969969
if rf:
970-
mode_spec = td.MicrowaveModeSpec(**mode_spec.dict(exclude={"type"}))
970+
mode_spec = td.MicrowaveModeSpec(**mode_spec.model_dump(exclude={"type"}))
971971
monitor = td.MicrowaveModeSolverMonitor(
972-
**monitor.dict(exclude={"type", "mode_spec"}), mode_spec=mode_spec
972+
**monitor.model_dump(exclude={"type", "mode_spec"}), mode_spec=mode_spec
973973
)
974-
data = td.ModeSolverData(**data.dict(exclude={"type", "monitor"}), monitor=monitor)
974+
data = td.ModeSolverData(**data.model_dump(exclude={"type", "monitor"}), monitor=monitor)
975975

976976
# Check _stored_freqs length
977977
assert len(data.monitor._stored_freqs) == expected_stored_len, (

tests/test_components/test_scene.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_get_structure_plot_params():
146146
pp = SCENE_FULL._get_structure_eps_plot_params(
147147
medium=SCENE_FULL.medium, freq=1, eps_min=1, eps_max=2
148148
)
149-
expected_color = mpl.cm.get_cmap(STRUCTURE_EPS_CMAP)(0.0)
149+
expected_color = plt.get_cmap(STRUCTURE_EPS_CMAP)(0.0)
150150
assert np.allclose(pp.facecolor, expected_color)
151151
pp = SCENE_FULL._get_structure_eps_plot_params(medium=td.PEC, freq=1, eps_min=1, eps_max=2)
152152
assert pp.facecolor == "gold"
@@ -165,7 +165,7 @@ def test_structure_eps_color_mapping():
165165
norm=norm,
166166
reverse=False,
167167
)
168-
expected_min = mpl.cm.get_cmap(STRUCTURE_EPS_CMAP)(norm(1.0))
168+
expected_min = plt.get_cmap(STRUCTURE_EPS_CMAP)(norm(1.0))
169169
assert np.allclose(pp_min.facecolor, expected_min)
170170

171171
pp_max = SCENE_FULL._get_structure_eps_plot_params(
@@ -176,7 +176,7 @@ def test_structure_eps_color_mapping():
176176
norm=norm,
177177
reverse=False,
178178
)
179-
expected_max = mpl.cm.get_cmap(STRUCTURE_EPS_CMAP)(norm(5.0))
179+
expected_max = plt.get_cmap(STRUCTURE_EPS_CMAP)(norm(5.0))
180180
assert np.allclose(pp_max.facecolor, expected_max)
181181

182182
pp_min_reverse = SCENE_FULL._get_structure_eps_plot_params(
@@ -187,7 +187,7 @@ def test_structure_eps_color_mapping():
187187
norm=norm,
188188
reverse=True,
189189
)
190-
expected_min_reverse = mpl.cm.get_cmap(STRUCTURE_EPS_CMAP_R)(norm(1.0))
190+
expected_min_reverse = plt.get_cmap(STRUCTURE_EPS_CMAP_R)(norm(1.0))
191191
assert np.allclose(pp_min_reverse.facecolor, expected_min_reverse)
192192

193193
pp_max_reverse = SCENE_FULL._get_structure_eps_plot_params(
@@ -198,7 +198,7 @@ def test_structure_eps_color_mapping():
198198
norm=norm,
199199
reverse=True,
200200
)
201-
expected_max_reverse = mpl.cm.get_cmap(STRUCTURE_EPS_CMAP_R)(norm(5.0))
201+
expected_max_reverse = plt.get_cmap(STRUCTURE_EPS_CMAP_R)(norm(5.0))
202202
assert np.allclose(pp_max_reverse.facecolor, expected_max_reverse)
203203

204204

0 commit comments

Comments
 (0)