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_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')