41
41
f , AX = plt .subplots ()
42
42
43
43
44
+ @pytest .fixture
45
+ def unique_project_name (tmp_path ):
46
+ """Generate unique project name using tmp_path's unique directory."""
47
+ # tmp_path.name gives us something like 'test_upload0'
48
+ return f"default_{ tmp_path .name } "
49
+
50
+
44
51
def make_mode_sim ():
45
52
"""Simple mode solver"""
46
53
@@ -73,13 +80,13 @@ def set_api_key(monkeypatch):
73
80
74
81
75
82
@pytest .fixture
76
- def mock_upload (monkeypatch , set_api_key ):
83
+ def mock_upload (monkeypatch , set_api_key , unique_project_name ):
77
84
"""Mocks webapi.upload."""
78
85
responses .add (
79
86
responses .GET ,
80
87
f"{ Env .current .web_api_endpoint } /tidy3d/project" ,
81
- match = [matchers .query_param_matcher ({"projectName" : PROJECT_NAME })],
82
- json = {"data" : {"projectId" : FOLDER_ID , "projectName" : PROJECT_NAME }},
88
+ match = [matchers .query_param_matcher ({"projectName" : unique_project_name })],
89
+ json = {"data" : {"projectId" : FOLDER_ID , "projectName" : unique_project_name }},
83
90
status = 200 ,
84
91
)
85
92
@@ -274,21 +281,21 @@ def mock_webapi(
274
281
275
282
276
283
@responses .activate
277
- def test_upload (monkeypatch , mock_upload , mock_get_info , mock_metadata ):
284
+ def test_upload (monkeypatch , mock_upload , mock_get_info , mock_metadata , unique_project_name ):
278
285
sim = make_mode_sim ()
279
286
assert sim != get_reduced_simulation (sim , reduce_simulation = True )
280
- assert upload (sim , TASK_NAME , PROJECT_NAME , reduce_simulation = True )
287
+ assert upload (sim , TASK_NAME , unique_project_name , reduce_simulation = True )
281
288
282
289
283
290
@pytest .mark .parametrize ("reduce_simulation" , [True , False ])
284
291
@responses .activate
285
292
def test_upload_with_reduction_parameter (
286
- monkeypatch , mock_upload , mock_get_info , mock_metadata , reduce_simulation
293
+ monkeypatch , mock_upload , mock_get_info , mock_metadata , reduce_simulation , unique_project_name
287
294
):
288
295
"""Test that simulation reduction is properly applied before upload based on reduce_simulation parameter."""
289
296
sim = make_mode_sim ()
290
297
291
- upload (sim , TASK_NAME , PROJECT_NAME , reduce_simulation = reduce_simulation )
298
+ upload (sim , TASK_NAME , unique_project_name , reduce_simulation = reduce_simulation )
292
299
293
300
if reduce_simulation :
294
301
expected_sim = get_reduced_simulation (sim , reduce_simulation = True )
@@ -346,13 +353,13 @@ def mock_download(*args, **kwargs):
346
353
347
354
348
355
@responses .activate
349
- def test_run (mock_webapi , monkeypatch , tmp_path ):
356
+ def test_run (mock_webapi , monkeypatch , tmp_path , unique_project_name ):
350
357
sim = make_mode_sim ()
351
358
monkeypatch .setattr (f"{ api_path } .load" , lambda * args , ** kwargs : True )
352
359
assert run (
353
360
sim ,
354
361
task_name = TASK_NAME ,
355
- folder_name = PROJECT_NAME ,
362
+ folder_name = unique_project_name ,
356
363
path = str (tmp_path / "web_test_tmp.json" ),
357
364
)
358
365
@@ -380,10 +387,10 @@ def test_abort_task(set_api_key, mock_get_info):
380
387
381
388
382
389
@responses .activate
383
- def test_job (mock_webapi , monkeypatch , tmp_path ):
390
+ def test_job (mock_webapi , monkeypatch , tmp_path , unique_project_name ):
384
391
monkeypatch .setattr ("tidy3d.web.api.container.Job.load" , lambda * args , ** kwargs : True )
385
392
sim = make_mode_sim ()
386
- j = Job (simulation = sim , task_name = TASK_NAME , folder_name = PROJECT_NAME )
393
+ j = Job (simulation = sim , task_name = TASK_NAME , folder_name = unique_project_name )
387
394
388
395
_ = j .run (path = str (tmp_path / "web_test_tmp.json" ))
389
396
_ = j .status
@@ -400,13 +407,13 @@ def mock_job_status(monkeypatch):
400
407
401
408
402
409
@responses .activate
403
- def test_batch (mock_webapi , mock_job_status , tmp_path , monkeypatch ):
410
+ def test_batch (mock_webapi , mock_job_status , tmp_path , monkeypatch , unique_project_name ):
404
411
# monkeypatch.setattr("tidy3d.web.api.container.Batch.monitor", lambda self: time.sleep(0.1))
405
412
# monkeypatch.setattr("tidy3d.web.api.container.Job.status", property(lambda self: "success"))
406
413
monkeypatch .setattr (f"{ api_path } .load" , lambda * args , ** kwargs : True )
407
414
408
415
sims = {TASK_NAME : make_mode_sim ()}
409
- b = Batch (simulations = sims , folder_name = PROJECT_NAME )
416
+ b = Batch (simulations = sims , folder_name = unique_project_name )
410
417
b .estimate_cost ()
411
418
_ = b .run (path_dir = str (tmp_path ))
412
419
assert b .real_cost () == FLEX_UNIT * len (sims )
@@ -416,16 +423,16 @@ def test_batch(mock_webapi, mock_job_status, tmp_path, monkeypatch):
416
423
417
424
418
425
@responses .activate
419
- def test_async (mock_webapi , mock_job_status , monkeypatch ):
426
+ def test_async (mock_webapi , mock_job_status , monkeypatch , unique_project_name ):
420
427
# monkeypatch.setattr("tidy3d.web.api.container.Job.status", property(lambda self: "success"))
421
428
monkeypatch .setattr (f"{ api_path } .load" , lambda * args , ** kwargs : True )
422
429
423
430
sims = {TASK_NAME : make_mode_sim ()}
424
- _ = run_async (sims , folder_name = PROJECT_NAME )
431
+ _ = run_async (sims , folder_name = unique_project_name )
425
432
426
433
427
434
@responses .activate
428
- def test_patch_data (mock_webapi , monkeypatch , tmp_path ):
435
+ def test_patch_data (mock_webapi , monkeypatch , tmp_path , unique_project_name ):
429
436
"""Test that mode solver is patched with remote data after run"""
430
437
431
438
def get_sim_and_data ():
@@ -454,7 +461,7 @@ def check_patched(result, sim, data_local, data_remote):
454
461
result = run (
455
462
sim ,
456
463
task_name = TASK_NAME ,
457
- folder_name = PROJECT_NAME ,
464
+ folder_name = unique_project_name ,
458
465
path = str (tmp_path / "web_test_tmp.json" ),
459
466
)
460
467
@@ -464,7 +471,7 @@ def check_patched(result, sim, data_local, data_remote):
464
471
465
472
sim , data_local , data_remote = get_sim_and_data ()
466
473
467
- j = Job (simulation = sim , task_name = TASK_NAME , folder_name = PROJECT_NAME )
474
+ j = Job (simulation = sim , task_name = TASK_NAME , folder_name = unique_project_name )
468
475
469
476
result = j .run (path = str (tmp_path / "web_test_tmp.json" ))
470
477
@@ -475,7 +482,7 @@ def check_patched(result, sim, data_local, data_remote):
475
482
sim , data_local , data_remote = get_sim_and_data ()
476
483
477
484
sims = {TASK_NAME : sim }
478
- b = Batch (simulations = sims , folder_name = PROJECT_NAME )
485
+ b = Batch (simulations = sims , folder_name = unique_project_name )
479
486
result = b .run (path_dir = str (tmp_path ))
480
487
481
488
check_patched (result [TASK_NAME ], sim , data_local , data_remote )
0 commit comments