def test_not_detected(self, _, __): """Check Archey does not crash when `/proc/meminfo` is not readable""" ram = RAM() output_mock = MagicMock() ram.output(output_mock) self.assertIsNone(ram.value) self.assertEqual(output_mock.append.call_args[0][1], DEFAULT_CONFIG['default_strings']['not_detected'])
def test_proc_meminfo(self, _): """Test `/proc/meminfo` parsing (when `free` is not available)""" self.assertDictEqual(RAM().value, { 'used': 3739.296875, 'total': 7403.3203125, 'unit': 'MiB' })
def test_free_dash_m_warning(self, _): """Test `free -m` output parsing for warning RAM use case""" output_mock = MagicMock() RAM(options={'warning': 33.3, 'danger': 66.7}).output(output_mock) self.assertEqual( output_mock.append.call_args[0][1], '{0}3341 MiB{1} / 7412 MiB'.format(Colors.YELLOW_NORMAL, Colors.CLEAR))
def test_free_dash_m_danger(self, _): """Test `free -m` output parsing for danger RAM use case""" output_mock = MagicMock() RAM(options={'warning': 25, 'danger': 45}).output(output_mock) self.assertEqual( output_mock.append.call_args[0][1], '{0}12341 MiB{1} / 15658 MiB'.format(Colors.RED_NORMAL, Colors.CLEAR))
def test_free_dash_m(self, _): """Test `free -m` output parsing for low RAM use case""" output_mock = MagicMock() RAM().output(output_mock) self.assertEqual( output_mock.append.call_args[0][1], '{0}2043 MiB{1} / 15658 MiB'.format( Colors.GREEN_NORMAL, Colors.CLEAR ) )
def test_various_output_configuration(self): """Test `output` overloading based on user preferences""" ram_instance_mock = HelperMethods.entry_mock(RAM) output_mock = MagicMock() with self.subTest('Output in case of non-detection.'): RAM.output(ram_instance_mock, output_mock) self.assertEqual(output_mock.append.call_args[0][1], DEFAULT_CONFIG['default_strings']['not_detected']) output_mock.reset_mock() with self.subTest('"Normal" output (green).'): ram_instance_mock.value = { 'used': 2043.0, 'total': 15658.0, 'unit': 'MiB' } ram_instance_mock.options = { 'warning_use_percent': 33.3, 'danger_use_percent': 66.7 } RAM.output(ram_instance_mock, output_mock) self.assertEqual( output_mock.append.call_args[0][1], f'{Colors.GREEN_NORMAL}2043 MiB{Colors.CLEAR} / 15658 MiB') output_mock.reset_mock() with self.subTest('"Danger" output (red).'): ram_instance_mock.value = { 'used': 7830.0, 'total': 15658.0, 'unit': 'MiB' } ram_instance_mock.options = { 'warning_use_percent': 25, 'danger_use_percent': 50 } RAM.output(ram_instance_mock, output_mock) self.assertEqual( output_mock.append.call_args[0][1], f'{Colors.RED_NORMAL}7830 MiB{Colors.CLEAR} / 15658 MiB')
def test_free_dash_m(self, _): """Test `free -m` output parsing""" ram = RAM().value self.assertTrue(all(i in ram for i in ['3341', '7412']))
def test_read_proc_meminfo(self): """Test `_read_proc_meminfo` content parsing""" self.assertTupleEqual( RAM._read_proc_meminfo(), # pylint: disable=protected-access (3739.296875, 7403.3203125))
def test_run_sysctl_and_vmstat(self, _): """Check `sysctl` and `vm_stat` parsing logic""" self.assertTupleEqual( RAM._run_sysctl_and_vmstat(), # pylint: disable=protected-access (1685.58984375, 8192.0))
def test_free_dash_m_danger(self, _, __): """Test `free -m` output parsing for danger RAM use case""" ram = RAM().value self.assertTrue( all(i in ram for i in [str(Colors.RED_NORMAL), '12341', '15658']))
def test_run_free_dash_m(self, _): """Test `_run_free_dash_m` output parsing""" self.assertTupleEqual( RAM._run_free_dash_m(), # pylint: disable=protected-access (2043.0, 15658.0))
def test_free_dash_m(self, _, __): """Test `free -m` output parsing for low RAM use case and tweaked limits""" ram = RAM().value self.assertTrue( all(i in ram for i in [str(Colors.RED_NORMAL), '3341', '7412']))
def test_free_dash_m_warning(self, _, __): """Test `free -m` output parsing for warning RAM use case""" ram = RAM().value self.assertTrue( all(i in ram for i in [str(Colors.GREEN_NORMAL), '2043', '15658']))
def test_proc_meminfo(self, _, __): """Test `/proc/meminfo` parsing (when `free` is not available)""" ram = RAM().value self.assertTrue( all(i in ram for i in [str(Colors.YELLOW_NORMAL), '3739', '7403']))
def test_proc_meminfo(self, _, __): """Test `/proc/meminfo` parsing (when `free` is not available)""" ram = RAM().value self.assertTrue(all(i in ram for i in ['\x1b[0;33m', '3556', '7412']))
def test_free_dash_m(self, _, __): """Test `free -m` output parsing for low RAM use case and tweaked limits""" ram = RAM().value self.assertTrue(all(i in ram for i in ['\x1b[0;31m', '3341', '7412']))
def test_free_dash_m_warning(self, _, __): """Test `free -m` output parsing for warning RAM use case""" ram = RAM().value self.assertTrue(all(i in ram for i in ['\x1b[0;32m', '2043', '15658']))
def test_free_dash_m_danger(self, _, __): """Test `free -m` output parsing for danger RAM use case""" ram = RAM().value self.assertTrue(all(i in ram for i in ['\x1b[0;31m', '12341', '15658']))