예제 #1
0
    def test_run_sensors_ko_exec(self, _):
        """Test `sensors` (hard) failure handling"""
        # pylint: disable=protected-access
        Temperature._run_sensors(self.temperature_mock)
        self.assertListEmpty(self.temperature_mock._temps)

        Temperature._run_sensors(self.temperature_mock)
        self.assertListEmpty(self.temperature_mock._temps)
예제 #2
0
    def test_run_sensors_ko_output(self, run_mock):
        """Test `sensors` (soft) failure handling"""
        # JSON decoding from `sensors` will fail...
        run_mock.return_value.stdout = """\
{
    "Is this JSON valid ?": [
        "You", "should", "look", "twice.",
    ]
}
"""
        # pylint: disable=protected-access
        Temperature._run_sensors(self.temperature_mock)
        self.assertListEmpty(self.temperature_mock._temps)
예제 #3
0
    def test_run_sensors_ok_multiple_chipsets(self, run_mock):
        """Test `sensors` when multiple chipsets names have been passed"""
        run_mock.side_effect = [
            Mock(stdout="""\
{
   "who-cares-about":{
      "temp1":{
         "temp1_input": 45.000,
         "temp1_crit": 128.000
      },
      "temp2":{
         "temp2_input": 0.000,
         "temp2_crit": 128.000
      },
      "temp3":{
         "temp3_input": 38.000,
         "temp3_crit": 128.000
      }
   }
}
""",
                 stderr=None),
            Mock(stdout="""\
{
   "the-chipsets-names":{
      "what-are":{
         "temp1_input": 45.000,
         "temp1_max": 100.000,
         "temp1_crit": 100.000,
         "temp1_crit_alarm": 0.000
      }
    }
}
""",
                 stderr=None)
        ]

        sensors_chipsets = ['who-cares-about', 'the-chipsets-names']

        # pylint: disable=protected-access
        Temperature._run_sensors(self.temperature_mock, sensors_chipsets)
        self.assertListEqual(self.temperature_mock._temps, [45.0, 38.0, 45.0])
        # pylint: enable=protected-access

        # Check that our `run` mock has been called up to the number of passed chipsets.
        self.assertEqual(run_mock.call_count, len(sensors_chipsets))
예제 #4
0
    def test_run_sensors_ok_excluded_subfeatures(self, run_mock):
        """Test `sensors` when chipset subfeatures have been excluded"""
        run_mock.side_effect = [
            Mock(stdout="""\
{
   "k10temp-pci-00c3":{
      "Tctl":{
         "temp1_input": 42.000
      },
      "Tdie":{
         "temp2_input": 32.000
      }
   }
}
""",
                 stderr=None)
        ]

        # pylint: disable=protected-access
        Temperature._run_sensors(self.temperature_mock,
                                 excluded_subfeatures=["Tctl"])
        self.assertListEqual(self.temperature_mock._temps, [32.0])
예제 #5
0
    def test_run_sensors_ok(self, run_mock):
        """Test computations around `sensors` output"""
        run_mock.return_value.stdout = """\
{
   "who-cares-about":{
      "temp1":{
         "temp1_input": 45.000,
         "temp1_crit": 128.000
      },
      "temp2":{
         "temp2_input": 0.000,
         "temp2_crit": 128.000
      },
      "temp3":{
         "temp3_input": 38.000,
         "temp3_crit": 128.000
      },
      "temp4":{
         "temp4_input": 39.000,
         "temp4_crit": 128.000
      },
      "temp5":{
         "temp5_input": 0.000,
         "temp5_crit": 128.000
      },
      "temp6":{
         "temp6_input": 114.000,
         "temp6_crit": 128.000
      }
   },
   "the-chipsets-names":{
      "what-are":{
         "temp1_input": 45.000,
         "temp1_max": 100.000,
         "temp1_crit": 100.000,
         "temp1_crit_alarm": 0.000
      },
      "those":{
         "temp2_input": 43.000,
         "temp2_max": 100.000,
         "temp2_crit": 100.000,
         "temp2_crit_alarm": 0.000
      },
      "identifiers":{
         "temp3_input": 44.000,
         "temp3_max": 100.000,
         "temp3_crit": 100.000,
         "temp3_crit_alarm": 0.000
      }
   },
   "crap-a-fan-chip":{
      "fan1":{
         "fan1_input": 3386.000
      }
   }
}
"""
        # pylint: disable=protected-access
        Temperature._run_sensors(self.temperature_mock)
        self.assertListEqual(self.temperature_mock._temps,
                             [45.0, 38.0, 39.0, 114.0, 45.0, 43.0, 44.0])