| Index: infra/services/sysmon/test/system_metrics_test.py
|
| diff --git a/infra/services/sysmon/test/system_metrics_test.py b/infra/services/sysmon/test/system_metrics_test.py
|
| index ccce512b5d1e9b488f15947116c3d63671385699..99294f314520c7c941b467142deb7ed7231398cd 100644
|
| --- a/infra/services/sysmon/test/system_metrics_test.py
|
| +++ b/infra/services/sysmon/test/system_metrics_test.py
|
| @@ -157,3 +157,191 @@ class SystemMetricsTest(unittest.TestCase):
|
| system_metrics.get_unix_time()
|
| self.assertTrue(
|
| 1464000000000 < system_metrics.unix_time.get() < 9464000000000)
|
| +
|
| + # this first patch doesn't need to be an arg
|
| + @mock.patch('sys.maxsize', 9223372036854775807)
|
| + # NB: remaining patches must be in reverse order of arguments
|
| + @mock.patch('platform.machine')
|
| + @mock.patch('platform.mac_ver')
|
| + @mock.patch('platform.system')
|
| + def test_os_info_mac_10115_64_64(self,
|
| + platform_system_mock,
|
| + platform_mac_ver_mock,
|
| + platform_machine_mock):
|
| + platform_system_mock.return_value = 'Darwin'
|
| + platform_mac_ver_mock.return_value = ('10.11.5', ('', '', ''), 'x86_64')
|
| + platform_machine_mock.return_value = 'x86_64'
|
| +
|
| + system_metrics.get_os_info()
|
| +
|
| + platform_system_mock.assert_called_once_with()
|
| + platform_mac_ver_mock.assert_called_once_with()
|
| + platform_machine_mock.assert_called_once_with()
|
| +
|
| + self.assertEqual('mac', system_metrics.os_name.get())
|
| + self.assertEqual('10.11.5', system_metrics.os_version.get())
|
| + self.assertEqual('x86_64', system_metrics.os_arch.get())
|
| + self.assertEqual('64', system_metrics.python_arch.get())
|
| +
|
| + # this first patch doesn't need to be an arg
|
| + @mock.patch('sys.maxsize', 9223372036854775807)
|
| + # NB: remaining patches must be in reverse order of arguments
|
| + @mock.patch('platform.machine')
|
| + @mock.patch('platform.mac_ver')
|
| + @mock.patch('platform.system')
|
| + def test_os_info_empty_info(self,
|
| + platform_system_mock,
|
| + platform_mac_ver_mock,
|
| + platform_machine_mock):
|
| + # this test is to hit the 'impossible' else case for a system
|
| + # this is to check that the fallback/error handling code behaves
|
| +
|
| + platform_system_mock.return_value = ''
|
| + platform_mac_ver_mock.return_value = ('', ('', '', ''), '')
|
| + platform_machine_mock.return_value = ''
|
| +
|
| + system_metrics.get_os_info()
|
| +
|
| + platform_system_mock.assert_called_once_with()
|
| + platform_mac_ver_mock.assert_called_once_with()
|
| + platform_machine_mock.assert_called_once_with()
|
| +
|
| + self.assertEqual('', system_metrics.os_name.get())
|
| + self.assertEqual('', system_metrics.os_version.get())
|
| + self.assertEqual('', system_metrics.os_arch.get())
|
| + self.assertEqual('64', system_metrics.python_arch.get())
|
| +
|
| + # this first patch doesn't need to be an arg
|
| + @mock.patch('sys.maxsize', 2147483647)
|
| + # NB: remaining patches must be in reverse order of arguments
|
| + @mock.patch('platform.machine')
|
| + @mock.patch('platform.release')
|
| + @mock.patch('platform.system')
|
| + def test_os_info_clear(self,
|
| + platform_system_mock,
|
| + platform_release_mock,
|
| + platform_machine_mock):
|
| + platform_system_mock.return_value = 'Windows'
|
| + platform_release_mock.return_value = '7'
|
| + platform_machine_mock.return_value = 'x86'
|
| +
|
| + system_metrics.get_os_info()
|
| +
|
| + platform_system_mock.assert_called_once_with()
|
| + platform_release_mock.assert_called_once_with()
|
| + platform_machine_mock.assert_called_once_with()
|
| +
|
| + self.assertEqual('windows', system_metrics.os_name.get())
|
| + self.assertEqual('7', system_metrics.os_version.get())
|
| + self.assertEqual('x86', system_metrics.os_arch.get())
|
| + self.assertEqual('32', system_metrics.python_arch.get())
|
| +
|
| + # test that clearing the metrics keeps them emtpy on subsequent runs
|
| + system_metrics.clear_os_info()
|
| +
|
| + self.assertEqual(None, system_metrics.os_name.get())
|
| + self.assertEqual(None, system_metrics.os_version.get())
|
| + self.assertEqual(None, system_metrics.os_arch.get())
|
| + self.assertEqual(None, system_metrics.python_arch.get())
|
| +
|
| + # this first patch doesn't need to be an arg
|
| + @mock.patch('sys.maxsize', 2147483647)
|
| + # NB: remaining patches must be in reverse order of arguments
|
| + @mock.patch('platform.machine')
|
| + @mock.patch('platform.release')
|
| + @mock.patch('platform.system')
|
| + def test_os_info_windows_7_32_32(self,
|
| + platform_system_mock,
|
| + platform_release_mock,
|
| + platform_machine_mock):
|
| + platform_system_mock.return_value = 'Windows'
|
| + platform_release_mock.return_value = '7'
|
| + platform_machine_mock.return_value = 'x86'
|
| +
|
| + system_metrics.get_os_info()
|
| +
|
| + platform_system_mock.assert_called_once_with()
|
| + platform_release_mock.assert_called_once_with()
|
| + platform_machine_mock.assert_called_once_with()
|
| +
|
| + self.assertEqual('windows', system_metrics.os_name.get())
|
| + self.assertEqual('7', system_metrics.os_version.get())
|
| + self.assertEqual('x86', system_metrics.os_arch.get())
|
| + self.assertEqual('32', system_metrics.python_arch.get())
|
| +
|
| + # this first patch doesn't need to be an arg
|
| + @mock.patch('sys.maxsize', 2147483647)
|
| + # NB: remaining patches must be in reverse order of arguments
|
| + @mock.patch('platform.machine')
|
| + @mock.patch('platform.dist')
|
| + @mock.patch('platform.system')
|
| + def test_os_info_ubuntu_1404_32_32(self,
|
| + platform_system_mock,
|
| + platform_dist_mock,
|
| + platform_machine_mock):
|
| + platform_system_mock.return_value = 'Linux'
|
| + platform_dist_mock.return_value = ('Ubuntu', '14.04', 'trusty')
|
| + platform_machine_mock.return_value = 'i686'
|
| +
|
| + system_metrics.get_os_info()
|
| +
|
| + platform_system_mock.assert_called_once_with()
|
| + platform_dist_mock.assert_called_once_with()
|
| + platform_machine_mock.assert_called_once_with()
|
| +
|
| + self.assertEqual('ubuntu', system_metrics.os_name.get())
|
| + self.assertEqual('14.04', system_metrics.os_version.get())
|
| + self.assertEqual('i686', system_metrics.os_arch.get())
|
| + self.assertEqual('32', system_metrics.python_arch.get())
|
| +
|
| + # this first patch doesn't need to be an arg
|
| + @mock.patch('sys.maxsize', 2147483647)
|
| + # NB: remaining patches must be in reverse order of arguments
|
| + @mock.patch('platform.machine')
|
| + @mock.patch('platform.dist')
|
| + @mock.patch('platform.system')
|
| + def test_os_info_ubuntu_1404_64_32(self,
|
| + platform_system_mock,
|
| + platform_dist_mock,
|
| + platform_machine_mock):
|
| + platform_system_mock.return_value = 'Linux'
|
| + platform_dist_mock.return_value = ('Ubuntu', '14.04', 'trusty')
|
| + platform_machine_mock.return_value = 'x86_64'
|
| +
|
| + system_metrics.get_os_info()
|
| +
|
| + platform_system_mock.assert_called_once_with()
|
| + platform_dist_mock.assert_called_once_with()
|
| + platform_machine_mock.assert_called_once_with()
|
| +
|
| + self.assertEqual('ubuntu', system_metrics.os_name.get())
|
| + self.assertEqual('14.04', system_metrics.os_version.get())
|
| + self.assertEqual('x86_64', system_metrics.os_arch.get())
|
| + self.assertEqual('32', system_metrics.python_arch.get())
|
| +
|
| + # this first patch doesn't need to be an arg
|
| + @mock.patch('sys.maxsize', 9223372036854775807)
|
| + # NB: remaining patches must be in reverse order of arguments
|
| + @mock.patch('platform.machine')
|
| + @mock.patch('platform.dist')
|
| + @mock.patch('platform.system')
|
| + def test_os_info_ubuntu_1404_64_64(self,
|
| + platform_system_mock,
|
| + platform_dist_mock,
|
| + platform_machine_mock):
|
| + platform_system_mock.return_value = 'Linux'
|
| + platform_dist_mock.return_value = ('Ubuntu', '14.04', 'trusty')
|
| + platform_machine_mock.return_value = 'x86_64'
|
| +
|
| + system_metrics.get_os_info()
|
| +
|
| + platform_system_mock.assert_called_once_with()
|
| + platform_dist_mock.assert_called_once_with()
|
| + platform_machine_mock.assert_called_once_with()
|
| +
|
| + self.assertEqual('ubuntu', system_metrics.os_name.get())
|
| + self.assertEqual('14.04', system_metrics.os_version.get())
|
| + self.assertEqual('x86_64', system_metrics.os_arch.get())
|
| + self.assertEqual('64', system_metrics.python_arch.get())
|
| +
|
| +
|
|
|