File tree Expand file tree Collapse file tree 3 files changed +31
-13
lines changed
tests/tests_app/utilities Expand file tree Collapse file tree 3 files changed +31
-13
lines changed Original file line number Diff line number Diff line change 25
25
from lightning_app .cli .core import Formatable
26
26
from lightning_app .utilities .network import LightningClient
27
27
from lightning_app .utilities .openapi import create_openapi_object , string2dict
28
+ from lightning_app .utilities .string_formatting import duration_seconds
28
29
29
30
CLUSTER_STATE_CHECKING_TIMEOUT = 60
30
31
MAX_CLUSTER_WAIT_TIME = 5400
@@ -313,19 +314,7 @@ def echo_cluster_status_long(
313
314
message = f"Cluster { cluster_id } has been deleted."
314
315
315
316
if seconds_in_current_state :
316
- message += f" [{ format_seconds (seconds_in_current_state )} ]"
317
+ message += f" [{ duration_seconds (seconds_in_current_state )} ]"
317
318
318
319
click .echo (message )
319
320
320
-
321
- def format_seconds (seconds : int ) -> str :
322
- """Generates a duration string in 00h00m00s format."""
323
- mins , seconds = divmod (seconds , 60 )
324
- hours , mins = divmod (mins , 60 )
325
-
326
- duration = f"{ seconds :02} s"
327
- if mins :
328
- duration = f"{ mins :02} m" + duration
329
- if hours :
330
- duration = f"{ hours :02} h" + duration
331
- return duration
Original file line number Diff line number Diff line change
1
+
2
+ def duration_seconds (seconds : int ) -> str :
3
+ """Generates a duration string in 00h00m00s format."""
4
+ mins , seconds = divmod (seconds , 60 )
5
+ hours , mins = divmod (mins , 60 )
6
+
7
+ duration = f"{ seconds :02} s"
8
+ if mins :
9
+ duration = f"{ mins :02} m" + duration
10
+ if hours :
11
+ duration = f"{ hours :02} h" + duration
12
+ return duration
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from lightning_app .utilities .string_formatting import duration_seconds
4
+
5
+
6
+ @pytest .mark .parametrize ("seconds,want_string" , [
7
+ (0 , "00s" ),
8
+ (0.1 , "0.1s" ),
9
+ (5 , "05s" ),
10
+ (50 , "50s" ),
11
+ (60 , "01m00s" ),
12
+ (60 * 60 , "01h00s" ),
13
+ (60 * 60 + 60 , "01h01m00s" ),
14
+ (60 * 60 * 25 , "25h00s" ),
15
+ ])
16
+ def test_duration_seconds (seconds , want_string ):
17
+ assert want_string == duration_seconds (seconds )
You can’t perform that action at this time.
0 commit comments