@@ -27,15 +27,18 @@ def test_check_run_initialised_decorator() -> None:
27
27
getattr (run , method_name )()
28
28
assert "Simvue Run must be initialised" in str (e .value )
29
29
30
+
30
31
@pytest .mark .run
31
32
@pytest .mark .parametrize ("overload_buffer" , (True , False ), ids = ("overload" , "normal" ))
32
- @pytest .mark .parametrize ("visibility" , ("bad_option" , "tenant" , "public" , ["ciuser01" ], None ))
33
+ @pytest .mark .parametrize (
34
+ "visibility" , ("bad_option" , "tenant" , "public" , ["ciuser01" ], None )
35
+ )
33
36
def test_log_metrics (
34
37
overload_buffer : bool ,
35
38
setup_logging : "CountingLogHandler" ,
36
39
mocker ,
37
40
request : pytest .FixtureRequest ,
38
- visibility : typing .Union [typing .Literal ["public" , "tenant" ], list [str ], None ]
41
+ visibility : typing .Union [typing .Literal ["public" , "tenant" ], list [str ], None ],
39
42
) -> None :
40
43
METRICS = {"a" : 10 , "b" : 1.2 }
41
44
@@ -50,17 +53,23 @@ def test_log_metrics(
50
53
with pytest .raises (RuntimeError ):
51
54
run .init (
52
55
name = f"test_run_{ str (uuid .uuid4 ()).split ('-' , 1 )[0 ]} " ,
53
- tags = ["simvue_client_unit_tests" , request .node .name .replace ("[" , "_" ).replace ("]" , "_" )],
56
+ tags = [
57
+ "simvue_client_unit_tests" ,
58
+ request .node .name .replace ("[" , "_" ).replace ("]" , "_" ),
59
+ ],
54
60
folder = "/simvue_unit_testing" ,
55
61
retention_period = "1 hour" ,
56
62
visibility = visibility ,
57
- resources_metrics_interval = 1
63
+ resources_metrics_interval = 1 ,
58
64
)
59
65
return
60
66
61
67
run .init (
62
68
name = f"test_run_{ str (uuid .uuid4 ()).split ('-' , 1 )[0 ]} " ,
63
- tags = ["simvue_client_unit_tests" , request .node .name .replace ("[" , "_" ).replace ("]" , "_" )],
69
+ tags = [
70
+ "simvue_client_unit_tests" ,
71
+ request .node .name .replace ("[" , "_" ).replace ("]" , "_" ),
72
+ ],
64
73
folder = "/simvue_unit_testing" ,
65
74
visibility = visibility ,
66
75
resources_metrics_interval = 1 ,
@@ -146,7 +155,9 @@ def test_update_metadata_offline(
146
155
147
156
@pytest .mark .run
148
157
@pytest .mark .parametrize ("multi_threaded" , (True , False ), ids = ("multi" , "single" ))
149
- def test_runs_multiple_parallel (multi_threaded : bool , request : pytest .FixtureRequest ) -> None :
158
+ def test_runs_multiple_parallel (
159
+ multi_threaded : bool , request : pytest .FixtureRequest
160
+ ) -> None :
150
161
N_RUNS : int = 2
151
162
if multi_threaded :
152
163
@@ -155,7 +166,10 @@ def thread_func(index: int) -> tuple[int, list[dict[str, typing.Any]], str]:
155
166
run .config (suppress_errors = False )
156
167
run .init (
157
168
name = f"test_runs_multiple_{ index + 1 } " ,
158
- tags = ["simvue_client_unit_tests" , request .node .name .replace ("[" , "_" ).replace ("]" , "_" )],
169
+ tags = [
170
+ "simvue_client_unit_tests" ,
171
+ request .node .name .replace ("[" , "_" ).replace ("]" , "_" ),
172
+ ],
159
173
folder = "/simvue_unit_testing" ,
160
174
retention_period = "1 hour" ,
161
175
)
@@ -192,7 +206,10 @@ def thread_func(index: int) -> tuple[int, list[dict[str, typing.Any]], str]:
192
206
run_1 .config (suppress_errors = False )
193
207
run_1 .init (
194
208
name = "test_runs_multiple_unthreaded_1" ,
195
- tags = ["simvue_client_unit_tests" , request .node .name .replace ("[" , "_" ).replace ("]" , "_" )],
209
+ tags = [
210
+ "simvue_client_unit_tests" ,
211
+ request .node .name .replace ("[" , "_" ).replace ("]" , "_" ),
212
+ ],
196
213
folder = "/simvue_unit_testing" ,
197
214
retention_period = "1 hour" ,
198
215
)
@@ -246,7 +263,10 @@ def test_runs_multiple_series(request: pytest.FixtureRequest) -> None:
246
263
run .config (suppress_errors = False )
247
264
run .init (
248
265
name = f"test_runs_multiple_series_{ index } " ,
249
- tags = ["simvue_client_unit_tests" , request .node .name .replace ("[" , "_" ).replace ("]" , "_" )],
266
+ tags = [
267
+ "simvue_client_unit_tests" ,
268
+ request .node .name .replace ("[" , "_" ).replace ("]" , "_" ),
269
+ ],
250
270
folder = "/simvue_unit_testing" ,
251
271
retention_period = "1 hour" ,
252
272
)
@@ -296,8 +316,11 @@ def test_suppressed_errors(
296
316
run .init (
297
317
name = "test_suppressed_errors" ,
298
318
folder = "/simvue_unit_testing" ,
299
- tags = ["simvue_client_unit_tests" , request .node .name .replace ("[" , "_" ).replace ("]" , "_" )],
300
- retention_period = "1 hour"
319
+ tags = [
320
+ "simvue_client_unit_tests" ,
321
+ request .node .name .replace ("[" , "_" ).replace ("]" , "_" ),
322
+ ],
323
+ retention_period = "1 hour" ,
301
324
)
302
325
303
326
run .config (suppress_errors = True )
@@ -321,9 +344,12 @@ def test_bad_run_arguments() -> None:
321
344
322
345
def test_set_folder_details (request : pytest .FixtureRequest ) -> None :
323
346
with sv_run .Run () as run :
324
- folder_name : str = "/simvue_unit_tests"
347
+ folder_name : str = "/simvue_unit_tests"
325
348
description : str = "test description"
326
- tags : list [str ] = ["simvue_client_unit_tests" , request .node .name .replace ("[" , "_" ).replace ("]" , "_" )]
349
+ tags : list [str ] = [
350
+ "simvue_client_unit_tests" ,
351
+ request .node .name .replace ("[" , "_" ).replace ("]" , "_" ),
352
+ ]
327
353
run .init (folder = folder_name )
328
354
run .set_folder_details (path = folder_name , tags = tags , description = description )
329
355
@@ -333,8 +359,12 @@ def test_set_folder_details(request: pytest.FixtureRequest) -> None:
333
359
334
360
335
361
@pytest .mark .run
336
- @pytest .mark .parametrize ("valid_mimetype" , (True , False ), ids = ("valid_mime" , "invalid_mime" ))
337
- @pytest .mark .parametrize ("preserve_path" , (True , False ), ids = ("preserve_path" , "modified_path" ))
362
+ @pytest .mark .parametrize (
363
+ "valid_mimetype" , (True , False ), ids = ("valid_mime" , "invalid_mime" )
364
+ )
365
+ @pytest .mark .parametrize (
366
+ "preserve_path" , (True , False ), ids = ("preserve_path" , "modified_path" )
367
+ )
338
368
@pytest .mark .parametrize ("name" , ("test_file" , None ), ids = ("named" , "nameless" ))
339
369
@pytest .mark .parametrize ("allow_pickle" , (True , False ), ids = ("pickled" , "unpickled" ))
340
370
@pytest .mark .parametrize ("empty_file" , (True , False ), ids = ("empty" , "content" ))
@@ -345,19 +375,17 @@ def test_save_file(
345
375
name : typing .Optional [str ],
346
376
allow_pickle : bool ,
347
377
empty_file : bool ,
348
- capfd
378
+ capfd ,
349
379
) -> None :
350
380
simvue_run , _ = create_plain_run
351
- file_type : str = ' text/plain' if valid_mimetype else ' text/text'
381
+ file_type : str = " text/plain" if valid_mimetype else " text/text"
352
382
with tempfile .TemporaryDirectory () as tempd :
353
383
with open (
354
- (
355
- out_name := pathlib .Path (tempd ).joinpath ("test_file.txt" )
356
- ),
384
+ (out_name := pathlib .Path (tempd ).joinpath ("test_file.txt" )),
357
385
"w" ,
358
386
) as out_f :
359
387
out_f .write ("test data entry" if not empty_file else "" )
360
-
388
+
361
389
if valid_mimetype :
362
390
simvue_run .save_file (
363
391
out_name ,
@@ -372,14 +400,43 @@ def test_save_file(
372
400
out_name ,
373
401
category = "input" ,
374
402
filetype = file_type ,
375
- preserve_path = preserve_path
403
+ preserve_path = preserve_path ,
376
404
)
377
405
return
378
-
406
+
379
407
variable = capfd .readouterr ()
380
408
with capfd .disabled ():
381
409
if empty_file :
382
- assert variable .out == "WARNING: saving zero-sized files not currently supported\n "
410
+ assert (
411
+ variable .out
412
+ == "WARNING: saving zero-sized files not currently supported\n "
413
+ )
414
+
415
+
416
+ @pytest .mark .run
417
+ def test_update_tags (
418
+ create_plain_run : typing .Tuple [sv_run .Run , dict ],
419
+ request : pytest .FixtureRequest ,
420
+ ) -> None :
421
+ simvue_run , _ = create_plain_run
422
+
423
+ tags = [
424
+ "simvue_client_unit_tests" ,
425
+ request .node .name .replace ("[" , "_" ).replace ("]" , "_" ),
426
+ ]
427
+
428
+ simvue_run .set_tags (tags )
429
+
430
+ time .sleep (1 )
431
+ client = sv_cl .Client ()
432
+ run_data = client .get_run (simvue_run ._id )
433
+ assert run_data ["tags" ] == tags
434
+
435
+ simvue_run .update_tags (["additional" ])
436
+
437
+ time .sleep (1 )
438
+ run_data = client .get_run (simvue_run ._id )
439
+ assert sorted (run_data ["tags" ]) == sorted (tags + ["additional" ])
383
440
384
441
385
442
@pytest .mark .run
0 commit comments