11"""Tests monitors."""
22
33import numpy as np
4- import pydantic . v1 as pydantic
4+ import pydantic as pd
55import pytest
66import tidy3d as td
77from tidy3d .exceptions import SetupError , ValidationError
1010
1111
1212def test_stop_start ():
13- with pytest .raises (pydantic .ValidationError ):
13+ with pytest .raises (pd .ValidationError ):
1414 td .FluxTimeMonitor (size = (1 , 1 , 0 ), name = "f" , start = 2 , stop = 1 )
1515
1616
@@ -57,13 +57,13 @@ def test_downsampled():
5757
5858
5959def test_excluded_surfaces_flat ():
60- with pytest .raises (pydantic .ValidationError ):
60+ with pytest .raises (pd .ValidationError ):
6161 _ = td .FluxMonitor (size = (1 , 1 , 0 ), name = "f" , freqs = [1e12 ], exclude_surfaces = ("x-" ,))
6262
6363
6464def test_fld_mnt_freqs_none ():
6565 """Test that validation errors if freqs=[None]."""
66- with pytest .raises (pydantic .ValidationError ):
66+ with pytest .raises (pd .ValidationError ):
6767 td .FieldMonitor (center = (0 , 0 , 0 ), size = (0 , 0 , 0 ), freqs = [None ], name = "test" )
6868
6969
@@ -147,7 +147,7 @@ def test_fieldproj_surfaces():
147147def test_fieldproj_surfaces_in_simulaiton ():
148148 # test error if all projection surfaces are outside the simulation domain
149149 M = td .FieldProjectionAngleMonitor (size = (3 , 3 , 3 ), theta = [1 ], phi = [0 ], name = "f" , freqs = [2e12 ])
150- with pytest .raises (pydantic .ValidationError ):
150+ with pytest .raises (pd .ValidationError ):
151151 _ = td .Simulation (
152152 size = (2 , 2 , 2 ),
153153 run_time = 1e-12 ,
@@ -159,13 +159,13 @@ def test_fieldproj_surfaces_in_simulaiton():
159159 _ = td .Simulation (
160160 size = (2 , 2 , 2 ),
161161 run_time = 1e-12 ,
162- monitors = [ M ] ,
162+ monitors = ( M ,) ,
163163 grid_spec = td .GridSpec .uniform (0.1 ),
164164 )
165165
166166 # error when the surfaces that are in are excluded
167- M = M .updated_copy (exclude_surfaces = [ "x-" , "x+" ] )
168- with pytest .raises (pydantic .ValidationError ):
167+ M = M .updated_copy (exclude_surfaces = ( "x-" , "x+" ) )
168+ with pytest .raises (pd .ValidationError ):
169169 _ = td .Simulation (
170170 size = (2 , 2 , 2 ),
171171 run_time = 1e-12 ,
@@ -176,11 +176,11 @@ def test_fieldproj_surfaces_in_simulaiton():
176176
177177def test_fieldproj_kspace_range ():
178178 # make sure ux, uy are in [-1, 1] for k-space projection monitors
179- with pytest .raises (pydantic .ValidationError ):
179+ with pytest .raises (pd .ValidationError ):
180180 _ = td .FieldProjectionKSpaceMonitor (
181181 size = (2 , 0 , 2 ), ux = [0.1 , 2 ], uy = [0 ], name = "f" , freqs = [2e12 ], proj_axis = 1
182182 )
183- with pytest .raises (pydantic .ValidationError ):
183+ with pytest .raises (pd .ValidationError ):
184184 _ = td .FieldProjectionKSpaceMonitor (
185185 size = (2 , 0 , 2 ), ux = [0.1 , 0.2 ], uy = [1.1 ], name = "f" , freqs = [2e12 ], proj_axis = 1
186186 )
@@ -209,12 +209,12 @@ def test_fieldproj_window():
209209 points = np .linspace (0 , 10 , 100 )
210210 _ = M .window_function (points , window_size , window_minus , window_plus , 2 )
211211 # do not allow a window size larger than 1
212- with pytest .raises (pydantic .ValidationError ):
212+ with pytest .raises (pd .ValidationError ):
213213 _ = td .FieldProjectionAngleMonitor (
214214 size = (2 , 0 , 2 ), theta = [1 , 2 ], phi = [0 ], name = "f" , freqs = [2e12 ], window_size = (0.2 , 1.1 )
215215 )
216216 # do not allow non-zero windows for volume monitors
217- with pytest .raises (pydantic .ValidationError ):
217+ with pytest .raises (pd .ValidationError ):
218218 _ = td .FieldProjectionAngleMonitor (
219219 size = (2 , 1 , 2 ), theta = [1 , 2 ], phi = [0 ], name = "f" , freqs = [2e12 ], window_size = (0.2 , 0 )
220220 )
@@ -239,7 +239,7 @@ def test_storage_sizes(proj_mnt):
239239def test_monitor_freqs_empty ():
240240 # errors when no frequencies supplied
241241
242- with pytest .raises (pydantic .ValidationError ):
242+ with pytest .raises (pd .ValidationError ):
243243 _ = td .FieldMonitor (
244244 size = (td .inf , td .inf , td .inf ),
245245 freqs = [],
@@ -323,7 +323,7 @@ def test_diffraction_validators():
323323 y = td .Boundary .periodic (),
324324 z = td .Boundary .pml (),
325325 )
326- with pytest .raises (pydantic .ValidationError ):
326+ with pytest .raises (pd .ValidationError ):
327327 _ = td .Simulation (
328328 size = (2 , 2 , 2 ),
329329 run_time = 1e-12 ,
@@ -334,7 +334,7 @@ def test_diffraction_validators():
334334 )
335335
336336 # ensure error if monitor isn't infinite in two directions
337- with pytest .raises (pydantic .ValidationError ):
337+ with pytest .raises (pd .ValidationError ):
338338 _ = td .DiffractionMonitor (size = [td .inf , 4 , 0 ], freqs = [1e12 ], name = "de" )
339339
340340
@@ -391,11 +391,11 @@ def test_monitor():
391391def test_monitor_plane ():
392392 # make sure flux, mode and diffraction monitors fail with non planar geometries
393393 for size in ((0 , 0 , 0 ), (1 , 0 , 0 ), (1 , 1 , 1 )):
394- with pytest .raises (pydantic .ValidationError ):
394+ with pytest .raises (pd .ValidationError ):
395395 td .ModeMonitor (size = size , freqs = FREQS , modes = [])
396- with pytest .raises (pydantic .ValidationError ):
396+ with pytest .raises (pd .ValidationError ):
397397 td .ModeSolverMonitor (size = size , freqs = FREQS , modes = [])
398- with pytest .raises (pydantic .ValidationError ):
398+ with pytest .raises (pd .ValidationError ):
399399 td .DiffractionMonitor (size = size , freqs = FREQS , name = "de" )
400400
401401
0 commit comments