99
1010import pytest
1111from faker import Faker
12- from models_library .basic_types import IDStr
1312from models_library .progress_bar import ProgressReport , ProgressStructuredMessage
1413from pydantic import ValidationError
1514from pytest_mock import MockerFixture
@@ -55,7 +54,7 @@ async def test_progress_bar_progress_report_cb(
5554 num_steps = outer_num_steps ,
5655 progress_report_cb = mocked_cb ,
5756 progress_unit = "Byte" ,
58- description = IDStr ( faker .pystr () ),
57+ description = faker .pystr (),
5958 ) as root :
6059 assert root .num_steps == outer_num_steps
6160 assert root .step_weights is None # i.e. all steps have equal weight
@@ -97,7 +96,7 @@ async def test_progress_bar_progress_report_cb(
9796 # 2nd step is a sub progress bar of 10 steps
9897 inner_num_steps_step2 = 100
9998 async with root .sub_progress (
100- steps = inner_num_steps_step2 , description = IDStr ( faker .pystr () )
99+ steps = inner_num_steps_step2 , description = faker .pystr ()
101100 ) as sub :
102101 assert sub ._current_steps == pytest .approx (0 ) # noqa: SLF001
103102 assert root ._current_steps == pytest .approx (1 ) # noqa: SLF001
@@ -126,7 +125,7 @@ async def test_progress_bar_progress_report_cb(
126125 # 3rd step is another subprogress of 50 steps
127126 inner_num_steps_step3 = 50
128127 async with root .sub_progress (
129- steps = inner_num_steps_step3 , description = IDStr ( faker .pystr () )
128+ steps = inner_num_steps_step3 , description = faker .pystr ()
130129 ) as sub :
131130 assert sub ._current_steps == pytest .approx (0 ) # noqa: SLF001
132131 assert root ._current_steps == pytest .approx (2 ) # noqa: SLF001
@@ -148,7 +147,7 @@ async def test_progress_bar_progress_report_cb(
148147def test_creating_progress_bar_with_invalid_unit_fails (faker : Faker ):
149148 with pytest .raises (ValidationError ):
150149 ProgressBarData (
151- num_steps = 321 , progress_unit = "invalid" , description = IDStr ( faker .pystr () )
150+ num_steps = 321 , progress_unit = "invalid" , description = faker .pystr ()
152151 )
153152
154153
@@ -159,7 +158,7 @@ async def test_progress_bar_always_reports_0_on_creation_and_1_on_finish(
159158 progress_bar = ProgressBarData (
160159 num_steps = num_steps ,
161160 progress_report_cb = mocked_progress_bar_cb ,
162- description = IDStr ( faker .pystr () ),
161+ description = faker .pystr (),
163162 )
164163 assert progress_bar ._current_steps == _INITIAL_VALUE # noqa: SLF001
165164 async with progress_bar as root :
@@ -207,7 +206,7 @@ async def test_progress_bar_always_reports_1_on_finish(
207206 progress_bar = ProgressBarData (
208207 num_steps = num_steps ,
209208 progress_report_cb = mocked_progress_bar_cb ,
210- description = IDStr ( faker .pystr () ),
209+ description = faker .pystr (),
211210 )
212211 assert progress_bar ._current_steps == _INITIAL_VALUE # noqa: SLF001
213212 async with progress_bar as root :
@@ -249,7 +248,7 @@ async def test_progress_bar_always_reports_1_on_finish(
249248
250249
251250async def test_set_progress (caplog : pytest .LogCaptureFixture , faker : Faker ):
252- async with ProgressBarData (num_steps = 50 , description = IDStr ( faker .pystr () )) as root :
251+ async with ProgressBarData (num_steps = 50 , description = faker .pystr ()) as root :
253252 assert root ._current_steps == pytest .approx (0 ) # noqa: SLF001
254253 assert root .num_steps == 50
255254 assert root .step_weights is None
@@ -264,7 +263,7 @@ async def test_set_progress(caplog: pytest.LogCaptureFixture, faker: Faker):
264263
265264
266265async def test_reset_progress (caplog : pytest .LogCaptureFixture , faker : Faker ):
267- async with ProgressBarData (num_steps = 50 , description = IDStr ( faker .pystr () )) as root :
266+ async with ProgressBarData (num_steps = 50 , description = faker .pystr ()) as root :
268267 assert root ._current_steps == pytest .approx (0 ) # noqa: SLF001
269268 assert root .num_steps == 50
270269 assert root .step_weights is None
@@ -292,43 +291,41 @@ async def test_reset_progress(caplog: pytest.LogCaptureFixture, faker: Faker):
292291
293292async def test_concurrent_progress_bar (faker : Faker ):
294293 async def do_something (root : ProgressBarData ):
295- async with root .sub_progress (steps = 50 , description = IDStr ( faker .pystr () )) as sub :
294+ async with root .sub_progress (steps = 50 , description = faker .pystr ()) as sub :
296295 assert sub .num_steps == 50
297296 assert sub .step_weights is None
298297 assert sub ._current_steps == 0 # noqa: SLF001
299298 for n in range (50 ):
300299 await sub .update ()
301300 assert sub ._current_steps == (n + 1 ) # noqa: SLF001
302301
303- async with ProgressBarData (num_steps = 12 , description = IDStr ( faker .pystr () )) as root :
302+ async with ProgressBarData (num_steps = 12 , description = faker .pystr ()) as root :
304303 assert root ._current_steps == pytest .approx (0 ) # noqa: SLF001
305304 assert root .step_weights is None
306305 await asyncio .gather (* [do_something (root ) for n in range (12 )])
307306 assert root ._current_steps == pytest .approx (12 ) # noqa: SLF001
308307
309308
310309async def test_too_many_sub_progress_bars_raises (faker : Faker ):
311- async with ProgressBarData (num_steps = 2 , description = IDStr ( faker .pystr () )) as root :
310+ async with ProgressBarData (num_steps = 2 , description = faker .pystr ()) as root :
312311 assert root .num_steps == 2
313312 assert root .step_weights is None
314- async with root .sub_progress (steps = 50 , description = IDStr ( faker .pystr () )) as sub :
313+ async with root .sub_progress (steps = 50 , description = faker .pystr ()) as sub :
315314 for _ in range (50 ):
316315 await sub .update ()
317- async with root .sub_progress (steps = 50 , description = IDStr ( faker .pystr () )) as sub :
316+ async with root .sub_progress (steps = 50 , description = faker .pystr ()) as sub :
318317 for _ in range (50 ):
319318 await sub .update ()
320319
321320 with pytest .raises (RuntimeError ):
322- async with root .sub_progress (
323- steps = 50 , description = IDStr (faker .pystr ())
324- ) as sub :
321+ async with root .sub_progress (steps = 50 , description = faker .pystr ()) as sub :
325322 ...
326323
327324
328325async def test_too_many_updates_does_not_raise_but_show_warning_with_stack (
329326 caplog : pytest .LogCaptureFixture , faker : Faker
330327):
331- async with ProgressBarData (num_steps = 2 , description = IDStr ( faker .pystr () )) as root :
328+ async with ProgressBarData (num_steps = 2 , description = faker .pystr ()) as root :
332329 assert root .num_steps == 2
333330 assert root .step_weights is None
334331 await root .update ()
@@ -344,7 +341,7 @@ async def test_weighted_progress_bar(mocked_progress_bar_cb: mock.Mock, faker: F
344341 num_steps = outer_num_steps ,
345342 step_weights = [1 , 3 , 1 ],
346343 progress_report_cb = mocked_progress_bar_cb ,
347- description = IDStr ( faker .pystr () ),
344+ description = faker .pystr (),
348345 ) as root :
349346 mocked_progress_bar_cb .assert_called_once_with (
350347 ProgressReport (
@@ -399,7 +396,7 @@ async def test_weighted_progress_bar_with_weighted_sub_progress(
399396 num_steps = outer_num_steps ,
400397 step_weights = [1 , 3 , 1 ],
401398 progress_report_cb = mocked_progress_bar_cb ,
402- description = IDStr ( faker .pystr () ),
399+ description = faker .pystr (),
403400 ) as root :
404401 mocked_progress_bar_cb .assert_called_once_with (
405402 ProgressReport (
@@ -426,7 +423,7 @@ async def test_weighted_progress_bar_with_weighted_sub_progress(
426423
427424 # 2nd step is a sub progress bar of 5 steps
428425 async with root .sub_progress (
429- steps = 5 , step_weights = [2 , 5 , 1 , 2 , 3 ], description = IDStr ( faker .pystr () )
426+ steps = 5 , step_weights = [2 , 5 , 1 , 2 , 3 ], description = faker .pystr ()
430427 ) as sub :
431428 assert sub .step_weights == [2 / 13 , 5 / 13 , 1 / 13 , 2 / 13 , 3 / 13 , 0 ]
432429 assert sub ._current_steps == pytest .approx (0 ) # noqa: SLF001
@@ -487,7 +484,7 @@ async def test_weighted_progress_bar_with_weighted_sub_progress(
487484async def test_weighted_progress_bar_wrong_num_weights_raises (faker : Faker ):
488485 with pytest .raises (RuntimeError ):
489486 async with ProgressBarData (
490- num_steps = 3 , step_weights = [3 , 1 ], description = IDStr ( faker .pystr () )
487+ num_steps = 3 , step_weights = [3 , 1 ], description = faker .pystr ()
491488 ):
492489 ...
493490
@@ -496,7 +493,7 @@ async def test_weighted_progress_bar_with_0_weights_is_equivalent_to_standard_pr
496493 faker : Faker ,
497494):
498495 async with ProgressBarData (
499- num_steps = 3 , step_weights = [0 , 0 , 0 ], description = IDStr ( faker .pystr () )
496+ num_steps = 3 , step_weights = [0 , 0 , 0 ], description = faker .pystr ()
500497 ) as root :
501498 assert root .step_weights == [1 , 1 , 1 , 0 ]
502499
@@ -509,13 +506,13 @@ async def test_concurrent_sub_progress_update_correct_sub_progress(
509506 num_steps = 3 ,
510507 step_weights = [3 , 1 , 2 ],
511508 progress_report_cb = mocked_progress_bar_cb ,
512- description = IDStr ( faker .pystr () ),
509+ description = faker .pystr (),
513510 ) as root :
514- sub_progress1 = root .sub_progress (23 , description = IDStr ( faker .pystr () ))
511+ sub_progress1 = root .sub_progress (23 , description = faker .pystr ())
515512 assert sub_progress1 ._current_steps == _INITIAL_VALUE # noqa: SLF001
516- sub_progress2 = root .sub_progress (45 , description = IDStr ( faker .pystr () ))
513+ sub_progress2 = root .sub_progress (45 , description = faker .pystr ())
517514 assert sub_progress2 ._current_steps == _INITIAL_VALUE # noqa: SLF001
518- sub_progress3 = root .sub_progress (12 , description = IDStr ( faker .pystr () ))
515+ sub_progress3 = root .sub_progress (12 , description = faker .pystr ())
519516 assert sub_progress3 ._current_steps == _INITIAL_VALUE # noqa: SLF001
520517
521518 # NOTE: in a gather call there is no control on which step finishes first
0 commit comments