@@ -270,60 +270,77 @@ def test_get_elapsed_time_negative(self):
270
270
271
271
def test_elapsed_time_to_string (self ):
272
272
for elapsed , expected in [(0 , '00:00:00.000' ),
273
- (0.1 , '00:00:00.000' ),
274
- (0.5 , '00:00:00.000' ),
275
- (0.501 , '00:00:00.001' ),
276
- (1 , '00:00:00.001' ),
277
- (1.5 , '00:00:00.002' ),
278
- (42 , '00:00:00.042' ),
279
- (999 , '00:00:00.999' ),
280
- (999.9 , '00:00:01.000' ),
281
- (1000 , '00:00:01.000' ),
282
- (1001 , '00:00:01.001' ),
283
- (60000 , '00:01:00.000' ),
284
- (600000 , '00:10:00.000' ),
285
- (654321 , '00:10:54.321' ),
286
- (660000 , '00:11:00.000' ),
287
- (3600000 , '01:00:00.000' ),
288
- (36000000 , '10:00:00.000' ),
289
- (360000000 , '100:00:00.000' ),
290
- (360000000 + 36000000 + 3600000 + 660000 + 11111 ,
273
+ (0.0001 , '00:00:00.000' ),
274
+ (0.00049 , '00:00:00.000' ),
275
+ (0.00050 , '00:00:00.001' ),
276
+ (0.00051 , '00:00:00.001' ),
277
+ (0.001 , '00:00:00.001' ),
278
+ (0.0015 , '00:00:00.002' ),
279
+ (0.042 , '00:00:00.042' ),
280
+ (0.999 , '00:00:00.999' ),
281
+ (0.9999 , '00:00:01.000' ),
282
+ (1.0 , '00:00:01.000' ),
283
+ (1 , '00:00:01.000' ),
284
+ (1.001 , '00:00:01.001' ),
285
+ (60 , '00:01:00.000' ),
286
+ (600 , '00:10:00.000' ),
287
+ (654.321 , '00:10:54.321' ),
288
+ (660 , '00:11:00.000' ),
289
+ (3600 , '01:00:00.000' ),
290
+ (36000 , '10:00:00.000' ),
291
+ (360000 , '100:00:00.000' ),
292
+ (360000 + 36000 + 3600 + 660 + 11.111 ,
291
293
'111:11:11.111' )]:
292
- td = timedelta (seconds = elapsed / 1000 )
293
- assert_equal (elapsed_time_to_string (elapsed ), expected , elapsed )
294
- assert_equal (elapsed_time_to_string (td ), expected , elapsed )
295
- if expected != '00:00:00.000' :
296
- assert_equal (elapsed_time_to_string (- 1 * elapsed ),
294
+ assert_equal (elapsed_time_to_string (elapsed , seconds = True ),
295
+ expected , elapsed )
296
+ assert_equal (elapsed_time_to_string (timedelta (seconds = elapsed )),
297
+ expected , elapsed )
298
+ if elapsed != 0 :
299
+ assert_equal (elapsed_time_to_string (- elapsed , seconds = True ),
300
+ '-' + expected , elapsed )
301
+ assert_equal (elapsed_time_to_string (timedelta (seconds = - elapsed )),
297
302
'-' + expected , elapsed )
298
303
299
304
def test_elapsed_time_to_string_without_millis (self ):
300
305
for elapsed , expected in [(0 , '00:00:00' ),
301
- (1 , '00:00:00' ),
302
- (500 , '00:00:00' ),
303
- (500.001 , '00:00:01' ),
304
- (999 , '00:00:01' ),
305
- (1000 , '00:00:01' ),
306
- (1499.999 , '00:00:01' ),
307
- (1500 , '00:00:02' ),
308
- (59499.9 , '00:00:59' ),
309
- (59500.0 , '00:01:00' ),
310
- (59999 , '00:01:00' ),
311
- (60000 , '00:01:00' ),
312
- (654321 , '00:10:54' ),
313
- (654500 , '00:10:54' ),
314
- (654501 , '00:10:55' ),
315
- (3599999 , '01:00:00' ),
316
- (3600000 , '01:00:00' ),
317
- (359999999 , '100:00:00' ),
318
- (360000000 , '100:00:00' ),
319
- (360000500 , '100:00:00' ),
320
- (360000500.001 , '100:00:01' )]:
321
- assert_equal (elapsed_time_to_string (elapsed , include_millis = False ),
306
+ (0.001 , '00:00:00' ),
307
+ (0.5 , '00:00:00' ),
308
+ (0.501 , '00:00:01' ),
309
+ (0.999 , '00:00:01' ),
310
+ (1.0 , '00:00:01' ),
311
+ (1 , '00:00:01' ),
312
+ (1.4999 , '00:00:01' ),
313
+ (1.500 , '00:00:02' ),
314
+ (59.4999 , '00:00:59' ),
315
+ (59.5 , '00:01:00' ),
316
+ (59.999 , '00:01:00' ),
317
+ (60 , '00:01:00' ),
318
+ (654.321 , '00:10:54' ),
319
+ (654.500 , '00:10:54' ),
320
+ (654.501 , '00:10:55' ),
321
+ (3599.999 , '01:00:00' ),
322
+ (3600 , '01:00:00' ),
323
+ (359999.999 , '100:00:00' ),
324
+ (360000 , '100:00:00' ),
325
+ (360000.5 , '100:00:00' ),
326
+ (360000.501 , '100:00:01' )]:
327
+ assert_equal (elapsed_time_to_string (elapsed , include_millis = False ,
328
+ seconds = True ),
322
329
expected , elapsed )
323
330
if expected != '00:00:00' :
324
- assert_equal (elapsed_time_to_string (- 1 * elapsed , False ),
331
+ assert_equal (elapsed_time_to_string (- 1 * elapsed , False , True ),
325
332
'-' + expected , elapsed )
326
333
334
+ def test_elapsed_time_default_input_is_deprecated (self ):
335
+ with warnings .catch_warnings (record = True ) as w :
336
+ assert_equal (elapsed_time_to_string (1000 ), '00:00:01.000' )
337
+ assert_equal (str (w [0 ].message ),
338
+ "'robot.utils.elapsed_time_to_string' currently accepts input "
339
+ "as milliseconds, but that will be changed to seconds in "
340
+ "Robot Framework 8.0. Use 'seconds=True' to change the behavior "
341
+ "already now and to avoid this warning. Alternatively pass "
342
+ "the elapsed time as a 'timedelta'." )
343
+
327
344
def test_parse_timestamp (self ):
328
345
for timestamp in ['2023-09-08 23:34:45.123456' ,
329
346
'2023-09-08T23:34:45.123456' ,
0 commit comments