Skip to content

Commit 731da0b

Browse files
committed
Fix unit test for genElapsedTime.py for header change
Signed-off-by: Matt Liberty <[email protected]>
1 parent 3617d02 commit 731da0b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

flow/test/test_genElapsedTime.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def test_elapsed_time(self, mock_stdout):
2626
f.write("Some log entry\n")
2727
f.write("Elapsed time: 01:30:00[h:]min:sec.\n")
2828
# call the script with the test log file
29-
sys.argv = ["./genElapsedTime.py", "--logDir", str(self.tmp_dir.name)]
29+
sys.argv = ["./genElapsedTime.py", "--logDir", str(self.tmp_dir.name),
30+
"--noHeader"]
3031
with patch.object(sys, 'argv', sys.argv):
3132
module = importlib.import_module(self.module_name)
3233
# check if output is correct
@@ -40,7 +41,8 @@ def test_zero_time(self, mock_stdout):
4041
f.write("Some log entry\n")
4142
f.write("Elapsed time: 00:00:74[h:]min:sec.\n")
4243
# call the script with the test log file
43-
sys.argv = ["./genElapsedTime.py", "--logDir", str(self.tmp_dir.name)]
44+
sys.argv = ["./genElapsedTime.py", "--logDir", str(self.tmp_dir.name),
45+
"--noHeader"]
4446
with patch.object(sys, 'argv', sys.argv):
4547
module = importlib.import_module(self.module_name)
4648
# check if output is correct
@@ -53,7 +55,8 @@ def test_elapsed_time_longer_duration(self, mock_stdout):
5355
f.write("Some log entry\n")
5456
f.write("Elapsed time: 12:24.14[h:]min:sec. CPU time: user 5081.82 sys 170.18 (705%). Peak memory: 9667132KB.\n")
5557
# call the script with the test log file
56-
sys.argv = ["util/genElapsedTime.py", "--logDir", str(self.tmp_dir.name)]
58+
sys.argv = ["util/genElapsedTime.py", "--logDir", str(self.tmp_dir.name),
59+
"--noHeader"]
5760
with patch.object(sys, 'argv', sys.argv):
5861
module = importlib.import_module(self.module_name)
5962
importlib.reload(module)
@@ -72,7 +75,9 @@ def test_missing_arg(self):
7275
def test_no_elapsed_time(self):
7376
with open(self.log_file, "w") as f:
7477
f.write('Other log message')
75-
with patch('sys.argv', ["util/genElapsedTime.py", "--logDir", str(self.tmp_dir.name)]):
78+
with patch('sys.argv', ["util/genElapsedTime.py",
79+
"--logDir", str(self.tmp_dir.name),
80+
"--noHeader"]):
7681
with patch('sys.stderr', new=StringIO()) as fake_err_output:
7782
module = importlib.import_module(self.module_name)
7883
importlib.reload(module)

flow/util/genElapsedTime.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
description='Print elapsed time for every step in the flow')
1616
parser.add_argument('--logDir', '-d', required=True,
1717
help='Log files directory')
18+
parser.add_argument('--noHeader', action='store_true',
19+
help='Skip the header')
1820
args = parser.parse_args()
1921

2022
if not args.logDir:
@@ -57,7 +59,7 @@
5759

5860
# Print the name of the step and the corresponding elapsed time
5961
if elapsedTime != 0:
60-
if first:
62+
if first and not args.noHeader:
6163
print("%-25s %10s" % ("Log", "Elapsed seconds"))
6264
first = False
6365
print('%-25s %10s' % (os.path.splitext(os.path.basename(str(f)))[0], elapsedTime))

0 commit comments

Comments
 (0)