22
33import matplotlib .pyplot as plt
44import numpy as np
5- import pydantic .v1 as pydantic
65import pytest
76import tidy3d as td
7+ from pydantic import ValidationError
88from tidy3d .components .source .field import CHEB_GRID_WIDTH , DirectionalSource
99from tidy3d .exceptions import SetupError
1010
@@ -141,7 +141,7 @@ def test_dipole():
141141 # p.plot(y=2)
142142 # plt.close()
143143
144- with pytest .raises (pydantic . ValidationError ):
144+ with pytest .raises (ValidationError ):
145145 _ = td .PointDipole (size = (1 , 1 , 1 ), source_time = g , center = (1 , 2 , 3 ), polarization = "Ex" )
146146
147147
@@ -177,11 +177,11 @@ def test_FieldSource():
177177 # plt.close()
178178
179179 # test that non-planar geometry crashes plane wave and gaussian beams
180- with pytest .raises (pydantic . ValidationError ):
180+ with pytest .raises (ValidationError ):
181181 _ = td .PlaneWave (size = (1 , 1 , 1 ), source_time = g , pol_angle = np .pi / 2 , direction = "+" )
182- with pytest .raises (pydantic . ValidationError ):
182+ with pytest .raises (ValidationError ):
183183 _ = td .GaussianBeam (size = (1 , 1 , 1 ), source_time = g , pol_angle = np .pi / 2 , direction = "+" )
184- with pytest .raises (pydantic . ValidationError ):
184+ with pytest .raises (ValidationError ):
185185 _ = td .AstigmaticGaussianBeam (
186186 size = (1 , 1 , 1 ),
187187 source_time = g ,
@@ -190,14 +190,14 @@ def test_FieldSource():
190190 waist_sizes = (0.2 , 0.4 ),
191191 waist_distances = (0.1 , 0.3 ),
192192 )
193- with pytest .raises (pydantic . ValidationError ):
193+ with pytest .raises (ValidationError ):
194194 _ = td .ModeSource (size = (1 , 1 , 1 ), source_time = g , mode_spec = mode_spec )
195195
196196 tfsf = td .TFSF (size = (1 , 1 , 1 ), direction = "+" , source_time = g , injection_axis = 2 )
197197 _ = tfsf .injection_plane_center
198198
199199 # assert that TFSF must be volumetric
200- with pytest .raises (pydantic . ValidationError ):
200+ with pytest .raises (ValidationError ):
201201 _ = td .TFSF (size = (1 , 1 , 0 ), direction = "+" , source_time = g , injection_axis = 2 )
202202
203203 # s.plot(z=0)
@@ -295,11 +295,11 @@ def check_freq_grid(freq_grid, num_freqs):
295295 check_freq_grid (freq_grid , num_freqs )
296296
297297 # check validators for num_freqs
298- with pytest .raises (pydantic . ValidationError ):
298+ with pytest .raises (ValidationError ):
299299 s = td .GaussianBeam (
300300 size = (0 , 1 , 1 ), source_time = g , pol_angle = np .pi / 2 , direction = "+" , num_freqs = 200
301301 )
302- with pytest .raises (pydantic . ValidationError ):
302+ with pytest .raises (ValidationError ):
303303 s = td .AstigmaticGaussianBeam (
304304 size = (0 , 1 , 1 ),
305305 source_time = g ,
@@ -309,7 +309,7 @@ def check_freq_grid(freq_grid, num_freqs):
309309 waist_distances = (0.1 , 0.3 ),
310310 num_freqs = 100 ,
311311 )
312- with pytest .raises (pydantic . ValidationError ):
312+ with pytest .raises (ValidationError ):
313313 s = td .ModeSource (
314314 size = (0 , 1 , 1 ),
315315 direction = "+" ,
@@ -355,7 +355,7 @@ def test_custom_source_time():
355355 )
356356 cst = td .CustomSourceTime .from_values (freq0 = freq0 , fwidth = 0.1e12 , values = [0 , 1 ], dt = sim .dt )
357357 source = td .PointDipole (center = (0 , 0 , 0 ), source_time = cst , polarization = "Ex" )
358- sim = sim .updated_copy (sources = [ source ] )
358+ sim = sim .updated_copy (sources = ( source ,) )
359359 assert np .allclose (cst .amp_time (sim .tmesh [0 ]), [0 ], rtol = 0 , atol = ATOL )
360360 assert np .allclose (
361361 cst .amp_time (sim .tmesh [1 :]),
@@ -374,18 +374,18 @@ def test_custom_source_time():
374374 cst = td .CustomSourceTime (source_time_dataset = dataset , freq0 = freq0 , fwidth = 0.1e12 )
375375 source = td .PointDipole (center = (0 , 0 , 0 ), source_time = cst , polarization = "Ex" )
376376 with AssertLogLevel ("WARNING" , contains_str = "defined over a time range" ):
377- sim = sim .updated_copy (sources = [ source ] )
377+ sim = sim .updated_copy (sources = ( source ,) )
378378
379379 # test normalization warning
380380 with AssertLogLevel ("WARNING" ):
381381 sim = sim .updated_copy (normalize_index = 0 )
382382
383383 with AssertLogLevel ("WARNING" ):
384384 source = source .updated_copy (source_time = td .ContinuousWave (freq0 = freq0 , fwidth = 0.1e12 ))
385- sim = sim .updated_copy (sources = [ source ] )
385+ sim = sim .updated_copy (sources = ( source ,) )
386386
387387 # test single value validation error
388- with pytest .raises (pydantic . ValidationError ):
388+ with pytest .raises (ValidationError ):
389389 vals = td .components .data .data_array .TimeDataArray ([1 ], coords = dict (t = [0 ]))
390390 dataset = td .components .data .dataset .TimeDataset (values = vals )
391391 cst = td .CustomSourceTime (source_time_dataset = dataset , freq0 = freq0 , fwidth = 0.1e12 )
@@ -411,7 +411,7 @@ def make_custom_field_source(field_ds):
411411 with AssertLogLevel (None ):
412412 make_custom_field_source (field_dataset )
413413
414- with pytest .raises (pydantic . ValidationError ):
414+ with pytest .raises (ValidationError ):
415415 # repeat some entries so data cannot be interpolated
416416 X2 = [X [0 ]] + list (X )
417417 n_data2 = np .vstack ((n_data [0 , :, :, :].reshape (1 , Ny , Nz , Nf ), n_data ))
0 commit comments