Exemplo n.º 1
0
 def test_get_none_status_when_driver_none(self, repo: KrakenRepository, mocker: MockerFixture) -> None:
     # arrange
     mocker.patch.object(
         repo, '_driver', spec=None
     )
     # act & assert
     assert repo.get_status() is None
Exemplo n.º 2
0
 def test_get_status_kraken_x3(
     self,
     repo: KrakenRepository,
     mocker: MockerFixture,
     temp: float,
     pump_rpm: Optional[int],
     pump_duty: Optional[int],
 ) -> None:
     # arrange
     driver_type = KrakenX3
     mocker.patch.object(repo, '_driver', spec=driver_type)
     mocker.patch.object(repo._driver, 'description', TEST_DESCRIPTION)
     mocker.patch.object(repo._driver,
                         'get_status',
                         return_value=[('Liquid temperature', temp, '°C'),
                                       ('Pump speed', pump_rpm, 'rpm'),
                                       ('Pump duty', pump_duty, '%')])
     # act
     status = repo.get_status()
     # assert
     assert isinstance(status, Status)
     assert status.driver_type == driver_type
     assert status.liquid_temperature == temp
     assert status.fan_rpm is None
     assert status.fan_duty is None
     assert status.pump_rpm == pump_rpm
     assert status.pump_duty == pump_duty
     assert status.firmware_version == ''
     assert status.device_description == TEST_DESCRIPTION
Exemplo n.º 3
0
 def test_get_status_kraken_2_firmware_in_init_response(
         self, repo: KrakenRepository, mocker: MockerFixture) -> None:
     # arrange
     temp = 30
     rpm = 800
     firmware = '1.2.3'
     driver_type = Kraken2
     mocker.patch.object(repo, '_driver', spec=driver_type)
     mocker.patch.object(repo, '_init_firmware_version', firmware)
     mocker.patch.object(repo._driver, 'description', TEST_DESCRIPTION)
     mocker.patch.object(repo._driver,
                         'get_status',
                         return_value=[('Liquid temperature', temp, '°C'),
                                       ('Fan speed', rpm, 'rpm'),
                                       ('Pump speed', rpm, 'rpm')])
     # act
     status = repo.get_status()
     # assert
     assert isinstance(status, Status)
     assert status.driver_type == driver_type
     assert status.liquid_temperature == temp
     assert status.fan_rpm == rpm
     assert status.fan_duty is None
     assert status.pump_rpm == rpm
     assert status.pump_duty is None
     assert status.firmware_version == firmware
     assert status.device_description == TEST_DESCRIPTION
Exemplo n.º 4
0
 def test_get_status_kraken_2_fail(self, repo: KrakenRepository,
                                   mocker: MockerFixture, temp: float,
                                   fan_rpm: Optional[int],
                                   pump_rpm: Optional[int],
                                   firmware: str) -> None:
     # arrange
     driver_type = Kraken2
     mocker.patch.object(repo, '_driver', spec=driver_type)
     mocker.patch.object(repo._driver,
                         'get_status',
                         return_value=[('Liquid temperature', temp, '°C'),
                                       ('Fan speed', fan_rpm, 'rpm'),
                                       ('Pump speed', pump_rpm, 'rpm'),
                                       ('Firmware version', firmware, '')])
     # act & assert
     assert repo.get_status() is None
Exemplo n.º 5
0
 def test_driver_can_not_get_status(self, repo: KrakenRepository, mocker: MockerFixture, caplog: LogCaptureFixture
                                    ) -> None:
     # arrange
     error_message = 'USB Communication Error'
     mocker.patch.object(
         repo, '_driver', spec=KrakenX3
     )
     mocker.patch.object(
         repo._driver, 'get_status', side_effect=OSError(error_message)
     )
     mocker.patch.object(repo, 'cleanup')
     caplog.at_level(logging.ERROR)
     # act
     status = repo.get_status()
     # assert
     assert status is None
     assert f'Error getting the status: {error_message}' in caplog.text
     repo.cleanup.assert_called_once()
Exemplo n.º 6
0
 def test_status_unknown_driver_type(self, repo: KrakenRepository, mocker: MockerFixture, caplog: LogCaptureFixture
                                     ) -> None:
     # arrange
     mocker.patch.object(
         repo, '_driver',
         # will likely never be supported by gkraken:
         spec=CorsairHidPsu
     )
     mocker.patch.object(
         repo._driver, 'get_status', return_value=[
             ('Fan Speed', 238, 'rpm')
         ]
     )
     caplog.at_level(logging.ERROR)
     # act
     status = repo.get_status()
     # assert
     assert status is None
     assert 'Driver Instance is not recognized' in caplog.text