Skip to content

Commit 1dea0d8

Browse files
committed
Fix walltime_to_seconds convertion
There was a missing parentheses which was causing a bad conversion of "DD:HH:MM:SS" to seconds. The unit-test was also missing the same parentheses. I added a unit-test to make sure such error could not occur again.
1 parent 9fb5ab6 commit 1dea0d8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

smartdispatch/tests/test_utils.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@ def setUp(self):
2525
seconds=random.randint(0, 59))
2626

2727
def _compute_seconds(self, days=0, hours=0, minutes=0, seconds=0):
28-
return ((((days * 24) + hours) * 60) + minutes * 60) + seconds
28+
return (((((days * 24) + hours) * 60) + minutes) * 60) + seconds
29+
30+
def test_compute_seconds(self):
31+
32+
date_format = dict(
33+
days=2,
34+
hours=3,
35+
minutes=5,
36+
seconds=7)
37+
38+
total_seconds = 183907
39+
40+
self.assertEqual(self._compute_seconds(**date_format), total_seconds)
41+
self.assertEqual(utils.walltime_to_seconds(
42+
"{days}:{hours}:{minutes}:{seconds}".format(**date_format)),
43+
total_seconds)
2944

3045
def test_ddhhmmss(self):
3146
seconds = utils.walltime_to_seconds(

smartdispatch/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def walltime_to_seconds(walltime):
3030

3131
days, hours, minutes, seconds = map(int, split)
3232

33-
return ((((days * 24) + hours) * 60) + minutes * 60) + seconds
33+
return (((((days * 24) + hours) * 60) + minutes) * 60) + seconds
3434

3535

3636
def jobname_generator(jobname, job_id):

0 commit comments

Comments
 (0)