BIND 10 trac2297, updated. f48cb0979513b642ab8cea30be5a3caa10fff958 [2297] simply use timedelta.str() for update_desc().

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Oct 26 03:11:22 UTC 2012


The branch, trac2297 has been updated
       via  f48cb0979513b642ab8cea30be5a3caa10fff958 (commit)
      from  ab6215d2e93f0bc0206f4503a9e5b0ea62bf65f3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f48cb0979513b642ab8cea30be5a3caa10fff958
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Thu Oct 25 20:09:50 2012 -0700

    [2297] simply use timedelta.str() for update_desc().
    
    some of the corresponding tests were just removed because the detailed
    behavior does nto matter much any more, and in this case there can be
    margin errors.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/python/isc/sysinfo/sysinfo.py            |   14 +++-----------
 src/lib/python/isc/sysinfo/tests/sysinfo_test.py |   12 ++----------
 2 files changed, 5 insertions(+), 21 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/sysinfo/sysinfo.py b/src/lib/python/isc/sysinfo/sysinfo.py
index 6be7adc..8e4610c 100644
--- a/src/lib/python/isc/sysinfo/sysinfo.py
+++ b/src/lib/python/isc/sysinfo/sysinfo.py
@@ -97,22 +97,14 @@ class SysInfo:
     def get_uptime_desc(self):
         """Returns the uptime in human readable form.
 
-        Specifically, the format is '[DD day[s], ]hh:mm'.
-        It returns None if _uptime is None.
+        The format is the result of str() method of the standard library
+        datetime.timedelta class.  It returns None if _uptime is None.
 
         """
         if self._uptime is None:
             return None
 
-        uptime_desc = ''
-        time_delta = timedelta(seconds=self._uptime)
-        days = time_delta.days
-        if days > 0:
-            uptime_desc += ('%d day%s, ' % (days, 's' if days > 1 else ''))
-        hours = int(time_delta.seconds / 3600)
-        minutes = int((time_delta.seconds - hours * 3600) / 60)
-        uptime_desc += ('%d:%02d' % (hours, minutes))
-        return uptime_desc
+        return str(timedelta(seconds=self._uptime))
 
     def get_loadavg(self):
         """Returns the load average as 3 floating point values in an array."""
diff --git a/src/lib/python/isc/sysinfo/tests/sysinfo_test.py b/src/lib/python/isc/sysinfo/tests/sysinfo_test.py
index 9f1dd8f..8f11df0 100644
--- a/src/lib/python/isc/sysinfo/tests/sysinfo_test.py
+++ b/src/lib/python/isc/sysinfo/tests/sysinfo_test.py
@@ -294,7 +294,7 @@ class SysInfoTest(unittest.TestCase):
         self.assertFalse(s.get_platform_is_smp())
         self.assertEqual(131072, s.get_uptime())
         # We check that we do NOT add 's' to 'day' (because it's singular):
-        self.assertEqual('1 day, 12:24', s.get_uptime_desc())
+        self.assertEqual('1 day, 12:24:32', s.get_uptime_desc())
         self.assertEqual(None, s.get_loadavg())
         self.assertEqual(None, s.get_mem_total())
         self.assertEqual(None, s.get_mem_free())
@@ -329,7 +329,7 @@ class SysInfoTest(unittest.TestCase):
         self.assertEqual(172801, s.get_uptime())
         # We check that we add 's' to 'day', and that the mm part has an
         # additional 0, i.e., not '0:0' but '0:00':
-        self.assertEqual('2 days, 0:00', s.get_uptime_desc())
+        self.assertEqual('2 days, 0:00:01', s.get_uptime_desc())
         self.assertEqual((0.1, 0.2, 0.3), s.get_loadavg())
         self.assertEqual(3157884928, s.get_mem_total())
         self.assertEqual(891383808, s.get_mem_free())
@@ -435,14 +435,6 @@ class SysInfoTest(unittest.TestCase):
         self.assertEqual(1037533184, s.get_mem_swap_total())
         self.assertEqual(1037533184, s.get_mem_swap_free())
 
-        # One more untested case so far: get_uptime_desc() should omit the
-        # "days" field.
-        faked_process_output['boottime-sysctl'] = bytes(
-            '{ sec = ' + str(int(time.time() - 4200)) +
-                     ', usec = 0 }\n', 'utf-8')
-        s = SysInfoFromFactory()
-        self.assertEqual('1:10', s.get_uptime_desc())
-
     def test_sysinfo_osx(self):
         """Tests the OS X implementation of SysInfo. Note that this
         tests deep into the implementation, and not just the



More information about the bind10-changes mailing list