Skip to content

Commit ab171aa

Browse files
committed
Handle zero elapsed time in genElapsedTime.py
Sub one second time rounds down to zero Fixes #1043 Signed-off-by: Matt Liberty <[email protected]>
1 parent eb38dc0 commit ab171aa

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

flow/test/test_genElapsedTime.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ def test_elapsed_time(self, mock_stdout):
3333
expected_output = "1_test 5400\n"
3434
self.assertEqual(mock_stdout.getvalue(), expected_output)
3535

36+
@patch("sys.stdout", new_callable=StringIO)
37+
def test_zero_time(self, mock_stdout):
38+
# create a log file with elapsed time
39+
with open(self.log_file, "w") as f:
40+
f.write("Some log entry\n")
41+
f.write("Elapsed time: 00:00:74[h:]min:sec.\n")
42+
# call the script with the test log file
43+
sys.argv = ["./genElapsedTime.py", "--logDir", str(self.tmp_dir.name)]
44+
with patch.object(sys, 'argv', sys.argv):
45+
module = importlib.import_module(self.module_name)
46+
# check if output is correct
47+
self.assertEqual(mock_stdout.getvalue(), "")
48+
3649
@patch("sys.stdout", new_callable=StringIO)
3750
def test_elapsed_time_longer_duration(self, mock_stdout):
3851
# create a log file with elapsed time

flow/util/genElapsedTime.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
parser.print_help()
2424
sys.exit(1)
2525

26+
found = False
27+
2628
# Loop on all log files in the directory
2729
for f in sorted(pathlib.Path(args.logDir).glob('**/[0-9]_*.log')):
2830
# Extract Elapsed Time line from log file
@@ -31,6 +33,7 @@
3133
elapsedTime = 0
3234

3335
if 'Elapsed time' in line:
36+
found = True
3437
# Extract the portion that has the time
3538
timePor = line.strip().replace('Elapsed time: ', '')
3639
# Remove the units from the time portion
@@ -45,11 +48,12 @@
4548
elif len(timeList) == 3:
4649
# Hours, minutes, and seconds are present
4750
elapsedTime = int(timeList[0])*3600 + int(timeList[1])*60 + int(timeList[2])
48-
if elapsedTime == 0:
51+
else:
52+
print('Elapsed time not understood in', str(line), file=sys.stderr)
53+
54+
if not found:
4955
print('No elapsed time found in', str(f), file=sys.stderr)
5056

5157
# Print the name of the step and the corresponding elapsed time
5258
if elapsedTime != 0:
5359
print('%-25s %10s' % (os.path.splitext(os.path.basename(str(f)))[0], elapsedTime))
54-
55-

0 commit comments

Comments
 (0)