From: JINMEI Tatuya Date: Thu, 25 Oct 2012 03:39:40 +0000 (-0700) Subject: [2297] added one more test case for get_uptime_desc X-Git-Tag: trac2487_base~32^2~2^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dbabdcc3c8c103a56a6da5187a97f2748adfa467;p=thirdparty%2Fkea.git [2297] added one more test case for get_uptime_desc --- diff --git a/src/lib/python/isc/sysinfo/tests/sysinfo_test.py b/src/lib/python/isc/sysinfo/tests/sysinfo_test.py index d08d6dd482..aeeee1542e 100644 --- a/src/lib/python/isc/sysinfo/tests/sysinfo_test.py +++ b/src/lib/python/isc/sysinfo/tests/sysinfo_test.py @@ -171,11 +171,14 @@ def _my_freebsd_os_sysconf(key): def _my_freebsd_platform_uname(): return ('FreeBSD', 'freebsd', '8.2-RELEASE', '', 'i386') -def _my_freebsd_osx_subprocess_check_output(command): +def _my_freebsd_osx_subprocess_check_output(command, faked_output={}): '''subprocess output shared for freebsd and osx''' assert type(command) == list, 'command argument is not a list' if command == ['sysctl', '-n', 'kern.boottime']: - return bytes('{ sec = ' + str(int(time.time() - 76632)) + ', usec = 0 }\n', 'utf-8') + if 'boottime-sysctl' in faked_output: + return faked_output['boottime-sysctl'] + return bytes('{ sec = ' + str(int(time.time() - 76632)) + + ', usec = 0 }\n', 'utf-8') elif command == ['sysctl', '-n', 'vm.loadavg']: return b'{ 0.2 0.4 0.6 }\n' else: @@ -193,7 +196,8 @@ def _my_freebsd_subprocess_check_output(command, faked_output): elif command == ['swapctl', '-s', '-k']: return b'Total: 1013216 0\n' else: - freebsd_osx_output = _my_freebsd_osx_subprocess_check_output(command) + freebsd_osx_output = \ + _my_freebsd_osx_subprocess_check_output(command, faked_output) if freebsd_osx_output is not None: return freebsd_osx_output else: @@ -431,6 +435,14 @@ 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