def test_legacy_kraken_warning(self, repo_init: KrakenRepository, mocker: MockerFixture) -> None: # arrange mocker.patch.object(DeviceSettings, '__subclasses__', return_value=[SettingsKrakenLegacy]) mocker.patch.object(Legacy690Lc, 'find_supported_devices', return_value=[Legacy690Lc('012345', 'test device')]) mocker.patch.object(Legacy690Lc, 'connect') mocker.patch.object(Legacy690Lc, 'initialize') # act with pytest.raises(LegacyKrakenWarning) as warning: repo_init.has_supported_kraken() # assert assert 'driver conflict' in str(warning.value) # act 2 - after warning has been issued to the user is_supported = repo_init.has_supported_kraken() # assert 2 assert isinstance(repo_init._driver, Legacy690Lc) assert is_supported
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
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
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
def test_has_supported_kraken_no_device_found(self, repo_init: KrakenRepository, mocker: MockerFixture) -> None: # arrange mocker.patch.object(DeviceSettings, '__subclasses__', return_value=[]) # act is_supported = repo_init.has_supported_kraken() # assert assert repo_init._driver is None assert not is_supported
def test_lighting_modes_kraken_legacy(self, repo: KrakenRepository, mocker: MockerFixture) -> None: # arrange mocker.patch.object(repo, '_driver', spec=Legacy690Lc) # act lighting_modes = repo.get_lighting_modes() # assert assert isinstance(lighting_modes, LightingModes) assert len(lighting_modes.modes_logo) == 4 assert len(lighting_modes.modes_ring) == 0
def test_has_supported_kraken_yes(self, repo_init: KrakenRepository, mocker: MockerFixture) -> None: # arrange mocker.patch.object(DeviceSettings, '__subclasses__', return_value=[SettingsKraken2]) mocker.patch.object(Kraken2, 'find_supported_devices', return_value=[Kraken2('012345', 'test device')]) mocker.patch.object(Kraken2, 'connect') mocker.patch.object(Kraken2, 'initialize') # act is_supported = repo_init.has_supported_kraken() # assert assert isinstance(repo_init._driver, Kraken2) assert is_supported
def test_has_supported_kraken_connection_error(self, repo_init: KrakenRepository, mocker: MockerFixture) -> None: # arrange mocker.patch.object(DeviceSettings, '__subclasses__', return_value=[SettingsKraken2]) mocker.patch.object(Kraken2, 'find_supported_devices', return_value=[Kraken2('012345', 'test device')]) mocker.patch.object(Kraken2, 'connect', side_effect=OSError("open failed")) mocker.patch.object(Kraken2, 'disconnect') # act is_supported = repo_init.has_supported_kraken() # assert assert repo_init._driver is None # should be reset after has_supported_kraken call assert is_supported
def test_lighting_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 ) caplog.at_level(logging.ERROR) # act lighting = repo.get_lighting_modes() # assert assert lighting is None assert 'Driver Instance is not recognized' in caplog.text
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
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()
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
def repo_init() -> KrakenRepository: return KrakenRepository()