Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Edge singularity correction at PEC and lossy metal edges defaults to `True`.

### Fixed
- Ensured the legacy `Env` proxy mirrors `config.web` profile switches and preserves API URL.
- More robust `Sellmeier` and `Debye` material model, and prevent very large pole parameters in `PoleResidue` material model.
- Bug in `WavePort` when more than one mode is requested in the `ModeSpec`.
- Solver error for named 2D materials with inhomogeneous substrates.
Expand Down
71 changes: 71 additions & 0 deletions tests/config/test_legacy_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from __future__ import annotations

import os
import ssl

from tidy3d.config import Env, get_manager, reload_config
from tidy3d.config import config as config_wrapper


def test_env_tracks_profile_switch(config_manager):
"""Regression: Env should mirror manager profile switches."""

del config_manager # ensure fixture runs, avoid lint for unused variable
try:
config_wrapper.switch_profile("dev")
assert config_wrapper.profile == "dev"
assert Env.current.name == "dev"
assert str(Env.current.web_api_endpoint) == str(config_wrapper.web.api_endpoint)
finally:
reload_config(profile="default")


def test_env_pending_overrides_apply_on_activation(mock_config_dir, config_manager):
"""Queued overrides should land once the corresponding profile is activated."""

del mock_config_dir
manager = config_manager
try:
config_wrapper.switch_profile("default")
assert manager.profile == "default"

Env.dev.enable_caching = False
Env.dev.ssl_version = ssl.TLSVersion.TLSv1_2

# Pending overrides should not touch the active profile yet.
default_web = manager.get_section("web")
assert default_web.enable_caching is True
assert default_web.ssl_version is None

Env.dev.active()
current_manager = get_manager()
assert current_manager.profile == "dev"
dev_web = current_manager.get_section("web")
assert dev_web.enable_caching is False
assert dev_web.ssl_version == ssl.TLSVersion.TLSv1_2
assert Env.current.enable_caching is False
assert Env.current.ssl_version == ssl.TLSVersion.TLSv1_2
finally:
reload_config(profile="default")


def test_env_vars_follow_profile_switch(mock_config_dir, monkeypatch, config_manager):
"""Environment variables applied via Env should restore previous values on switch."""

del mock_config_dir
del config_manager # ensure fixture executes without lint complaints
try:
config_wrapper.switch_profile("default")
monkeypatch.setenv("TIDY3D_TEST_VAR", "previous")

Env.default.env_vars = {"TIDY3D_TEST_VAR": "applied"}
assert os.environ["TIDY3D_TEST_VAR"] == "applied"

Env.dev.env_vars = {}
Env.dev.active()
assert os.environ["TIDY3D_TEST_VAR"] == "previous"

Env.default.active()
assert os.environ["TIDY3D_TEST_VAR"] == "applied"
finally:
reload_config(profile="default")
23 changes: 23 additions & 0 deletions tests/config/test_web_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

from tidy3d.config.sections import WebConfig


def test_build_api_url_joins_paths():
web = WebConfig(api_endpoint="https://example.com/api")
assert web.build_api_url("v1/tasks") == "https://example.com/api/v1/tasks"


def test_build_api_url_strips_leading_slashes():
web = WebConfig(api_endpoint="https://example.com/api/")
assert web.build_api_url("/v1/tasks") == "https://example.com/api/v1/tasks"


def test_build_api_url_returns_base_for_empty_path():
web = WebConfig(api_endpoint="https://example.com/api")
assert web.build_api_url("") == "https://example.com/api"


def test_build_api_url_without_base_returns_path():
web = WebConfig.model_construct(api_endpoint="")
assert web.build_api_url("/v1/tasks") == "v1/tasks"
Loading