def test_vcgencmd_only_no_max(self, _, __):
        """
        Test for `vcgencmd` output only (no sensor files).
        Only one value is retrieved, so no maximum should be displayed (see #39).
        """
        temperature = Temperature()

        output_mock = MagicMock()
        temperature.output(output_mock)

        self.assertDictEqual(
            temperature.value, {
                'temperature': 42.8,
                'max_temperature': 42.8,
                'char_before_unit': ' ',
                'unit': 'C'
            })
        self.assertEqual(output_mock.append.call_args[0][1], '42.8 C')
    def test_sensors_error_1(self, iglob_mock, _):
        """Test `sensors` (hard) failure handling and polling from files in Celsius"""
        iglob_mock.return_value = iter(
            [file.name for file in self._temp_files])

        temperature = Temperature()

        output_mock = MagicMock()
        temperature.output(output_mock)

        self.assertDictEqual(
            temperature.value, {
                'temperature': 46.7,
                'max_temperature': 50.0,
                'char_before_unit': 'o',
                'unit': 'C'
            })
        self.assertEqual(output_mock.append.call_args[0][1],
                         '46.7oC (Max. 50.0oC)')
Exemple #3
0
    def test_output(self):
        """Test `output` method"""
        output_mock = MagicMock()

        # No value --> not detected.
        Temperature.output(self.temperature_mock, output_mock)
        self.assertEqual(output_mock.append.call_args[0][1],
                         DEFAULT_CONFIG['default_strings']['not_detected'])

        output_mock.reset_mock()

        # Values --> normal behavior.
        self.temperature_mock._temps = [  # pylint: disable=protected-access
            50.0, 40.0, 50.0
        ]
        self.temperature_mock.value = {
            'temperature': 46.7,
            'max_temperature': 50.0,
            'char_before_unit': 'o',
            'unit': 'C'
        }
        Temperature.output(self.temperature_mock, output_mock)
        self.assertEqual(output_mock.append.call_args[0][1],
                         '46.7oC (Max. 50.0oC)')

        # Only one value --> no maximum.
        self.temperature_mock._temps = [42.8]  # pylint: disable=protected-access
        self.temperature_mock.value = {
            'temperature': 42.8,
            'max_temperature': 42.8,
            'char_before_unit': ' ',
            'unit': 'C'
        }
        Temperature.output(self.temperature_mock, output_mock)
        self.assertEqual(output_mock.append.call_args[0][1], '42.8 C')