Skip to content

Commit c1addaa

Browse files
momchil-flextylerflex
authored andcommitted
assert_log_level fails if higher-level log than expected, string matching contains_str, AssertLogLevel context
1 parent 8be02f6 commit c1addaa

File tree

7 files changed

+260
-220
lines changed

7 files changed

+260
-220
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- `ModeData.dispersion` and `ModeSolverData.dispersion` are calculated together with the group index.
1010
- String matching feature `contains_str` to `assert_log_level` testing utility.
1111
- Warning in automatic grid generation if a structure has a non-zero size along a given direction that is too small compared to a single mesh step.
12+
- `assert_log_level` adds string matching with `contains_str` and ensures no higher log level recorded than expected.
13+
- `AssertLogLevel` context manager for testing log level and automatically clearing capture.
1214

1315
### Changed
1416
- `jax` and `jaxlib` versions bumped to `0.4.*`.

tests/test_components/test_medium.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import matplotlib.pyplot as plt
66
import tidy3d as td
77
from tidy3d.exceptions import ValidationError, SetupError
8-
from ..utils import assert_log_level, log_capture
8+
from ..utils import assert_log_level, log_capture, AssertLogLevel
99
from typing import Dict
1010

1111
MEDIUM = td.Medium()
@@ -338,11 +338,12 @@ def test_gain_medium(log_capture):
338338
_ = td.Drude(eps_inf=0.04, coeffs=[(1, -2)])
339339

340340
# anisotropic medium, warn allow_gain is ignored
341-
_ = td.AnisotropicMedium(xx=td.Medium(), yy=mL, zz=mS, allow_gain=True)
342-
assert_log_level(log_capture, "WARNING")
343341

344-
_ = td.AnisotropicMedium(xx=td.Medium(), yy=mL, zz=mS, allow_gain=False)
345-
assert_log_level(log_capture, "WARNING")
342+
with AssertLogLevel(log_capture, "WARNING"):
343+
_ = td.AnisotropicMedium(xx=td.Medium(), yy=mL, zz=mS, allow_gain=True)
344+
345+
with AssertLogLevel(log_capture, "WARNING"):
346+
_ = td.AnisotropicMedium(xx=td.Medium(), yy=mL, zz=mS, allow_gain=False)
346347

347348

348349
def test_medium2d(log_capture):

0 commit comments

Comments
 (0)