Skip to content

Commit

Permalink
Fix walltime_to_seconds convertion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bouthilx committed Oct 17, 2017
1 parent 9fb5ab6 commit 1dea0d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion smartdispatch/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,22 @@ def setUp(self):
seconds=random.randint(0, 59))

def _compute_seconds(self, days=0, hours=0, minutes=0, seconds=0):
return ((((days * 24) + hours) * 60) + minutes * 60) + seconds
return (((((days * 24) + hours) * 60) + minutes) * 60) + seconds

def test_compute_seconds(self):

date_format = dict(
days=2,
hours=3,
minutes=5,
seconds=7)

total_seconds = 183907

self.assertEqual(self._compute_seconds(**date_format), total_seconds)
self.assertEqual(utils.walltime_to_seconds(
"{days}:{hours}:{minutes}:{seconds}".format(**date_format)),
total_seconds)

def test_ddhhmmss(self):
seconds = utils.walltime_to_seconds(
Expand Down
2 changes: 1 addition & 1 deletion smartdispatch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def walltime_to_seconds(walltime):

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

return ((((days * 24) + hours) * 60) + minutes * 60) + seconds
return (((((days * 24) + hours) * 60) + minutes) * 60) + seconds


def jobname_generator(jobname, job_id):
Expand Down

0 comments on commit 1dea0d8

Please sign in to comment.