def test_kraken2_backwards_modes_are_deprecated(caplog):
    modes = [
        'backwards-spectrum-wave', 'backwards-marquee-3',
        'backwards-marquee-4', 'backwards-marquee-5', 'backwards-marquee-6',
        'covering-backwards-marquee', 'backwards-moving-alternating',
        'backwards-super-wave'
    ]

    from liquidctl.driver.kraken2 import Kraken2

    for mode in modes:
        base_mode = mode.replace('backwards-', '')

        old = Kraken2(MockHidapiDevice(),
                      'Mock X62',
                      device_type=Kraken2.DEVICE_KRAKENX)
        new = Kraken2(MockHidapiDevice(),
                      'Mock X62',
                      device_type=Kraken2.DEVICE_KRAKENX)

        colors = [RADICAL_RED, MOUNTAIN_MEADOW]

        old.set_color('ring', mode, colors)
        new.set_color('ring', base_mode, colors, direction='backward')

        assert old.device.sent == new.device.sent, \
               f'{mode} != {base_mode} + direction=backward'

        assert 'deprecated mode' in caplog.text
Пример #2
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
Пример #3
0
 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
Пример #4
0
def test_construct_with_raw_pyusb_handle(monkeypatch):
    monkeypatch.setattr(hid, 'enumerate', _mock_enumerate)
    pyusb_handle = _MockPyUsbHandle(serial_number='123456789')
    liquidctl_device = Kraken2(pyusb_handle, 'Some device')
    assert liquidctl_device.device.vendor_id == pyusb_handle.idVendor, \
        '<driver instance>.device points to incorrect physical device'
    assert liquidctl_device.device.product_id == pyusb_handle.idProduct, \
        '<driver instance>.device points to incorrect physical device'
    assert liquidctl_device.device.serial_number == pyusb_handle.serial_number, \
        '<driver instance>.device points to different physical unit'
    assert isinstance(liquidctl_device.device, HidapiDevice), \
        '<driver instance>.device not properly converted to HidapiDevice instance'
Пример #5
0
 def test_driver(self, mocker: MockerFixture) -> None:
     # arrange
     description = 'test device'
     mocker.patch.object(DeviceSettings,
                         '__subclasses__',
                         return_value=[SettingsKraken2])
     mocker.patch.object(Kraken2,
                         'find_supported_devices',
                         return_value=[Kraken2('012345', description)])
     # act
     driver = INJECTOR.get(Optional[BaseDriver])
     # assert
     assert isinstance(driver, Kraken2)
     assert driver.description == description
Пример #6
0
 def test_driver_multiple(self, mocker: MockerFixture) -> None:
     # arrange
     mocker.patch.object(
         DeviceSettings,
         '__subclasses__',
         return_value=[SettingsKrakenZ3, SettingsKrakenX3, SettingsKraken2])
     mocker.patch.object(Kraken2,
                         'find_supported_devices',
                         return_value=[Kraken2('01234', 'test device')])
     mocker.patch.object(
         KrakenX3,
         'find_supported_devices',
         return_value=[KrakenX3('01234', 'test device', [], [])])
     mocker.patch.object(KrakenZ3,
                         'find_supported_devices',
                         return_value=[
                             KrakenZ3('01234', 'test device 1', [], []),
                             KrakenZ3('01234', 'test device 2', [], []),
                         ])
     # act
     driver = INJECTOR.get(Optional[BaseDriver])
     # assert should take the first found device from the first driver in the list of supported_drivers
     assert isinstance(driver, KrakenZ3)
     assert driver.description == 'test device 1'
Пример #7
0
 def _prepare(self):
     self.mock_hid = _MockKraken(fw_version=(6, 0, 2))
     self.device = Kraken2(self.mock_hid,
                           'Mock M22',
                           device_type=Kraken2.DEVICE_KRAKENM)
Пример #8
0
 def _prepare(self):
     self.mock_hid = _MockKraken(fw_version=(2, 5, 8))
     self.device = Kraken2(self.mock_hid,
                           'Mock X62',
                           device_type=Kraken2.DEVICE_KRAKENX)
Пример #9
0
def mockKrakenXDevice():
    device = _MockKrakenDevice(fw_version=(6, 0, 2))
    dev = Kraken2(device, 'Mock X62', device_type=Kraken2.DEVICE_KRAKENX)

    dev.connect()
    return dev