コード例 #1
0
    def test_factory_orientation(self, mock_date, mock_sense):

        mock_show_message = MagicMock()
        mock_clear = MagicMock()
        mock_sense.return_value.show_message = mock_show_message
        mock_sense.return_value.clear = mock_clear
        mock_sense.return_value.get_temperature.return_value = "100"
        mock_sense.return_value.get_pressure.return_value = "50"
        mock_sense.return_value.get_humidity.return_value = "20"
        mock_sense.return_value.get_accelerometer_raw.return_value = "20"
        mock_sense.return_value.get_orientation.return_value = (1, 1, 1)

        date_str = "example_date"
        mock_date.return_value = date_str

        with patch.dict(
                os.environ,
            {
                "SENSE_HAT_LOG_FILE": "logger.txt",
                "LOG_DIRECTORY": self.temp_dir.path
            },
        ):
            sense = SensePi()
            data = sense.factory("ORIENTATION")

            expected_data = {
                "sensor_id": 5,
                "values": {
                    "orientation": (1, 1, 1)
                },
                "date": date_str,
            }

            self.assertDictEqual(expected_data, data)
コード例 #2
0
    def test_factory_invalid_key(self, mock_date, mock_sense):

        mock_show_message = MagicMock()
        mock_clear = MagicMock()
        mock_sense.return_value.show_message = mock_show_message
        mock_sense.return_value.clear = mock_clear

        date_str = "example_date"
        mock_date.return_value = date_str

        with patch.dict(
                os.environ,
            {
                "SENSE_HAT_LOG_FILE": "logger.txt",
                "LOG_DIRECTORY": self.temp_dir.path
            },
        ):
            sense = SensePi()
            data = sense.factory("SOME_KEY")

            expected_data = {}

            self.assertDictEqual(expected_data, data)