From 1dea0d8288d898f8c8997379f2fa3606d1457aad Mon Sep 17 00:00:00 2001 From: Xavier Bouthillier Date: Tue, 17 Oct 2017 16:21:00 -0400 Subject: [PATCH] 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. --- smartdispatch/tests/test_utils.py | 17 ++++++++++++++++- smartdispatch/utils.py | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/smartdispatch/tests/test_utils.py b/smartdispatch/tests/test_utils.py index d4303a5..9306faa 100644 --- a/smartdispatch/tests/test_utils.py +++ b/smartdispatch/tests/test_utils.py @@ -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( diff --git a/smartdispatch/utils.py b/smartdispatch/utils.py index f3abb34..a0598d3 100644 --- a/smartdispatch/utils.py +++ b/smartdispatch/utils.py @@ -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):