Skip to content

Commit 1d713a6

Browse files
committed
fix(config): sync legacy env proxy with manager
1 parent 0ab5fca commit 1d713a6

File tree

13 files changed

+288
-118
lines changed

13 files changed

+288
-118
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5454
- Edge singularity correction at PEC and lossy metal edges defaults to `True`.
5555

5656
### Fixed
57+
- Ensured the legacy `Env` proxy mirrors `config.web` profile switches and preserves API URL.
5758
- More robust `Sellmeier` and `Debye` material model, and prevent very large pole parameters in `PoleResidue` material model.
5859
- Bug in `WavePort` when more than one mode is requested in the `ModeSpec`.
5960
- Solver error for named 2D materials with inhomogeneous substrates.

tests/config/test_legacy_env.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import ssl
5+
6+
from tidy3d.config import Env, get_manager, reload_config
7+
from tidy3d.config import config as config_wrapper
8+
9+
10+
def test_env_tracks_profile_switch(config_manager):
11+
"""Regression: Env should mirror manager profile switches."""
12+
13+
del config_manager # ensure fixture runs, avoid lint for unused variable
14+
try:
15+
config_wrapper.switch_profile("dev")
16+
assert config_wrapper.profile == "dev"
17+
assert Env.current.name == "dev"
18+
assert str(Env.current.web_api_endpoint) == str(config_wrapper.web.api_endpoint)
19+
finally:
20+
reload_config(profile="default")
21+
22+
23+
def test_env_pending_overrides_apply_on_activation(mock_config_dir, config_manager):
24+
"""Queued overrides should land once the corresponding profile is activated."""
25+
26+
del mock_config_dir
27+
manager = config_manager
28+
try:
29+
config_wrapper.switch_profile("default")
30+
assert manager.profile == "default"
31+
32+
Env.dev.enable_caching = False
33+
Env.dev.ssl_version = ssl.TLSVersion.TLSv1_2
34+
35+
# Pending overrides should not touch the active profile yet.
36+
default_web = manager.get_section("web")
37+
assert default_web.enable_caching is True
38+
assert default_web.ssl_version is None
39+
40+
Env.dev.active()
41+
current_manager = get_manager()
42+
assert current_manager.profile == "dev"
43+
dev_web = current_manager.get_section("web")
44+
assert dev_web.enable_caching is False
45+
assert dev_web.ssl_version == ssl.TLSVersion.TLSv1_2
46+
assert Env.current.enable_caching is False
47+
assert Env.current.ssl_version == ssl.TLSVersion.TLSv1_2
48+
finally:
49+
reload_config(profile="default")
50+
51+
52+
def test_env_vars_follow_profile_switch(mock_config_dir, monkeypatch, config_manager):
53+
"""Environment variables applied via Env should restore previous values on switch."""
54+
55+
del mock_config_dir
56+
del config_manager # ensure fixture executes without lint complaints
57+
try:
58+
config_wrapper.switch_profile("default")
59+
monkeypatch.setenv("TIDY3D_TEST_VAR", "previous")
60+
61+
Env.default.env_vars = {"TIDY3D_TEST_VAR": "applied"}
62+
assert os.environ["TIDY3D_TEST_VAR"] == "applied"
63+
64+
Env.dev.env_vars = {}
65+
Env.dev.active()
66+
assert os.environ["TIDY3D_TEST_VAR"] == "previous"
67+
68+
Env.default.active()
69+
assert os.environ["TIDY3D_TEST_VAR"] == "applied"
70+
finally:
71+
reload_config(profile="default")

tests/config/test_web_config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import annotations
2+
3+
from tidy3d.config.sections import WebConfig
4+
5+
6+
def test_build_api_url_joins_paths():
7+
web = WebConfig(api_endpoint="https://example.com/api")
8+
assert web.build_api_url("v1/tasks") == "https://example.com/api/v1/tasks"
9+
10+
11+
def test_build_api_url_strips_leading_slashes():
12+
web = WebConfig(api_endpoint="https://example.com/api/")
13+
assert web.build_api_url("/v1/tasks") == "https://example.com/api/v1/tasks"
14+
15+
16+
def test_build_api_url_returns_base_for_empty_path():
17+
web = WebConfig(api_endpoint="https://example.com/api")
18+
assert web.build_api_url("") == "https://example.com/api"
19+
20+
21+
def test_build_api_url_without_base_returns_path():
22+
web = WebConfig.model_construct(api_endpoint="")
23+
assert web.build_api_url("/v1/tasks") == "v1/tasks"

0 commit comments

Comments
 (0)