Skip to content

Commit

Permalink
diversion: Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag committed Apr 21, 2024
1 parent 3794a63 commit a65976f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/logitech_receiver/test_diversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from logitech_receiver import diversion
from logitech_receiver.diversion import Key
from logitech_receiver.diversion import KeyPress
from logitech_receiver.diversion import Rule


def test_diversion_rule():
args = [
{
"Rule": [ # Implement problematic keys for Craft and MX Master
{"Rule": [{"Key": ["Brightness Down", "pressed"]}, {"KeyPress": "XF86_MonBrightnessDown"}]},
{"Rule": [{"Key": ["Brightness Up", "pressed"]}, {"KeyPress": "XF86_MonBrightnessUp"}]},
]
},
]

rule = diversion.Rule(args)

assert len(rule.components) == 1
root_rule = rule.components[0]
assert isinstance(root_rule, Rule)

assert len(root_rule.components) == 2
for component in root_rule.components:
assert isinstance(component, Rule)
assert len(component.components) == 2

key = component.components[0]
assert isinstance(key, Key)
key = component.components[1]
assert isinstance(key, KeyPress)


def test_keysym_to_keycode():
expected_keycode = 56
expected_level = 0
keysym_shift_l = 65505

keycode, level = diversion.keysym_to_keycode(keysym_shift_l, None)

assert keycode == expected_keycode
assert level == expected_level

0 comments on commit a65976f

Please sign in to comment.