File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 2323 parser .print_help ()
2424 sys .exit (1 )
2525
26+ found = False
27+
2628# Loop on all log files in the directory
2729for f in sorted (pathlib .Path (args .logDir ).glob ('**/[0-9]_*.log' )):
2830 # Extract Elapsed Time line from log file
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
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-
You can’t perform that action at this time.
0 commit comments