|
3 | 3 |
|
4 | 4 | import tidy3d as td |
5 | 5 | import tidy3d.web as web |
| 6 | + |
6 | 7 | from .utils import SIM_CONVERT as sim_original |
7 | 8 | from .utils import clear_tmp |
8 | 9 |
|
9 | 10 | PATH_JSON = "tests/tmp/simulation.json" |
10 | 11 | PATH_SIM_DATA = "tests/tmp/sim_data.hdf5" |
11 | | -# each tests works on same 'task' |
12 | | -# store the task id in this list so it can be modified by tests |
| 12 | +PATH_DIR_SIM_DATA = "tests/tmp/" |
| 13 | + |
| 14 | + |
| 15 | +""" core webapi """ |
| 16 | + |
13 | 17 | task_id_global = [] |
14 | 18 |
|
15 | 19 |
|
16 | 20 | def _get_gloabl_task_id(): |
17 | 21 | """returns the task id from the list""" |
18 | 22 | return task_id_global[0] |
19 | 23 |
|
| 24 | +@clear_tmp |
| 25 | +def test_webapi_0_run(): |
| 26 | + """ test complete run""" |
| 27 | + sim_data = web.run(simulation=sim_original, task_name="test_webapi") |
20 | 28 |
|
21 | | -def test_1_upload(): |
| 29 | +def test_webapi_1_upload(): |
22 | 30 | """test that task uploads ok""" |
23 | 31 | task_id = web.upload(simulation=sim_original, task_name="test_webapi") |
24 | 32 | task_id_global.append(task_id) |
25 | 33 |
|
26 | 34 |
|
27 | | -def test_2_get_info(): |
| 35 | +def test_webapi_2_get_info(): |
28 | 36 | """test that we can grab information about task""" |
29 | 37 | task_id = _get_gloabl_task_id() |
30 | | - task_info = web.get_info(task_id) |
| 38 | + _ = web.get_info(task_id) |
31 | 39 |
|
32 | 40 |
|
33 | | -def test_3_run(): |
| 41 | +def test_webapi_3_start(): |
34 | 42 | """test that we can start running task""" |
35 | 43 | task_id = _get_gloabl_task_id() |
36 | | - web.run(task_id) |
| 44 | + web.start(task_id) |
37 | 45 |
|
38 | 46 |
|
39 | | -def test_4_monitor(): |
| 47 | +def test_webapi_4_monitor(): |
40 | 48 | """test that we can monitor task""" |
41 | 49 | task_id = _get_gloabl_task_id() |
42 | 50 | web.monitor(task_id) |
43 | 51 |
|
44 | 52 |
|
45 | 53 | @clear_tmp |
46 | | -def test_5_download(): |
| 54 | +def test_webapi_5_download(): |
47 | 55 | """download the simulation data""" |
48 | 56 | task_id = _get_gloabl_task_id() |
49 | 57 | web.download(task_id, simulation=sim_original, path=PATH_SIM_DATA) |
50 | 58 |
|
51 | 59 |
|
52 | 60 | @clear_tmp |
53 | | -def test_6_load(): |
| 61 | +def test_webapi_6_load(): |
54 | 62 | """load the results into sim_data""" |
55 | 63 | task_id = _get_gloabl_task_id() |
56 | 64 | sim_data = web.load(task_id, simulation=sim_original, path=PATH_SIM_DATA) |
57 | 65 | first_monitor_name = list(sim_original.monitors.keys())[0] |
58 | | - mon_data = sim_data[first_monitor_name] |
| 66 | + _ = sim_data[first_monitor_name] |
59 | 67 |
|
60 | 68 |
|
61 | | -def _test_7_delete(): |
| 69 | +def _test_webapi_7_delete(): |
62 | 70 | """test that we can monitor task""" |
63 | 71 | task_id = _get_gloabl_task_id() |
64 | 72 | web.delete(task_id) |
65 | | - try: |
66 | | - task_info = web.get_info(task_id) |
| 73 | + task_info = web.get_info(task_id) |
| 74 | + assert task_info.status in ("deleted", "deleting") |
| 75 | + |
| 76 | + |
| 77 | +""" Jobs """ |
| 78 | + |
| 79 | + |
| 80 | +jobs_global = [] |
| 81 | + |
| 82 | +def _get_gloabl_job(): |
| 83 | + """returns the task id from the list""" |
| 84 | + return jobs_global[0] |
| 85 | + |
| 86 | +@clear_tmp |
| 87 | +def test_job_0_run(): |
| 88 | + """ test complete run""" |
| 89 | + job = web.Job(simulation=sim_original, task_name="test_job") |
| 90 | + job.run() |
| 91 | + |
| 92 | + |
| 93 | +def test_job_1_upload(): |
| 94 | + """test that task uploads ok""" |
| 95 | + job = web.Job(simulation=sim_original, task_name="test_job") |
| 96 | + job.upload() |
| 97 | + jobs_global.append(job) |
| 98 | + |
| 99 | + |
| 100 | +def test_job_2_get_info(): |
| 101 | + """test that we can grab information about task""" |
| 102 | + job = _get_gloabl_job() |
| 103 | + _ = job.get_info() |
| 104 | + |
| 105 | + |
| 106 | +def test_job_3_start(): |
| 107 | + """test that we can start running task""" |
| 108 | + job = _get_gloabl_job() |
| 109 | + job.start() |
| 110 | + |
| 111 | + |
| 112 | +def test_job_4_monitor(): |
| 113 | + """test that we can monitor task""" |
| 114 | + job = _get_gloabl_job() |
| 115 | + job.monitor() |
| 116 | + |
| 117 | + |
| 118 | +@clear_tmp |
| 119 | +def test_job_5_download(): |
| 120 | + """download the simulation data""" |
| 121 | + job = _get_gloabl_job() |
| 122 | + job.download(path=PATH_SIM_DATA) |
| 123 | + |
| 124 | + |
| 125 | +@clear_tmp |
| 126 | +def test_job_6_load(): |
| 127 | + """load the results into sim_data""" |
| 128 | + job = _get_gloabl_job() |
| 129 | + sim_data = job.load_data(path=PATH_SIM_DATA) |
| 130 | + first_monitor_name = list(sim_original.monitors.keys())[0] |
| 131 | + _ = sim_data[first_monitor_name] |
| 132 | + |
| 133 | + |
| 134 | +def _test_job_7_delete(): |
| 135 | + """test that we can monitor task""" |
| 136 | + job = _get_gloabl_job() |
| 137 | + job.delete() |
| 138 | + task_info = job.get_info() |
| 139 | + assert task_info.status in ("deleted", "deleting") |
| 140 | + |
| 141 | + |
| 142 | +""" Batches """ |
| 143 | + |
| 144 | + |
| 145 | +batches_global = [] |
| 146 | + |
| 147 | +def _get_gloabl_batch(): |
| 148 | + """returns the task id from the list""" |
| 149 | + return batches_global[0] |
| 150 | + |
| 151 | +@clear_tmp |
| 152 | +def test_batch_0_run(): |
| 153 | + """ test complete run""" |
| 154 | + sims = 2*[sim_original] |
| 155 | + simulations = {f'task_{i}': sims[i] for i in range(len(sims))} |
| 156 | + batch = web.Batch(simulations=simulations) |
| 157 | + batch.run() |
| 158 | + |
| 159 | + |
| 160 | +def test_batch_1_upload(): |
| 161 | + """test that task uploads ok""" |
| 162 | + sims = 2*[sim_original] |
| 163 | + simulations = {f'task_{i}': sims[i] for i in range(len(sims))} |
| 164 | + batch = web.Batch(simulations=simulations) |
| 165 | + batch.upload() |
| 166 | + batches_global.append(batch) |
| 167 | + |
| 168 | + |
| 169 | +def test_batch_2_get_info(): |
| 170 | + """test that we can grab information about task""" |
| 171 | + batch = _get_gloabl_batch() |
| 172 | + _ = batch.get_info() |
| 173 | + |
| 174 | + |
| 175 | +def test_batch_3_start(): |
| 176 | + """test that we can start running task""" |
| 177 | + batch = _get_gloabl_batch() |
| 178 | + batch.start() |
| 179 | + |
| 180 | + |
| 181 | +def test_batch_4_monitor(): |
| 182 | + """test that we can monitor task""" |
| 183 | + batch = _get_gloabl_batch() |
| 184 | + batch.monitor() |
| 185 | + |
| 186 | + |
| 187 | +@clear_tmp |
| 188 | +def test_batch_5_download(): |
| 189 | + """download the simulation data""" |
| 190 | + batch = _get_gloabl_batch() |
| 191 | + batch.download(path_dir=PATH_DIR_SIM_DATA) |
| 192 | + |
| 193 | + |
| 194 | +@clear_tmp |
| 195 | +def test_batch_6_load(): |
| 196 | + """load the results into sim_data""" |
| 197 | + batch = _get_gloabl_batch() |
| 198 | + sim_data_dict = batch.load_data(path_dir=PATH_DIR_SIM_DATA) |
| 199 | + first_monitor_name = list(sim_original.monitors.keys())[0] |
| 200 | + for sim_data in sim_data_dict: |
| 201 | + _ = sim_data[first_monitor_name] |
| 202 | + |
| 203 | +def _test_batch_7_delete(): |
| 204 | + """test that we can monitor task""" |
| 205 | + batch = _get_gloabl_batch() |
| 206 | + batch.delete() |
| 207 | + for job in batch: |
| 208 | + task_info = job.get_info() |
67 | 209 | assert task_info.status in ("deleted", "deleting") |
68 | | - except Exception as e: |
69 | | - pass |
| 210 | + |
| 211 | + |
| 212 | + |
0 commit comments