Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
user202729 committed Jul 5, 2023
1 parent ab3bd59 commit f3144b5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def config(self, options):
lambda: ('"log_file_name":"c:/whatever/morestrokes.log"', "c:/whatever/morestrokes.log"),
lambda: ('"enabled_extensions":[]', set()),
lambda: ('"machine_type":"Keyboard"', "Keyboard"),
lambda: ('"machine_specific_options":{"arpeggiate":True}', {"arpeggiate": True}),
lambda: ('"machine_specific_options":{"arpeggiate":True}', {"arpeggiate": True, "first_up_chord_send": False}),
lambda: ('"system_keymap":'+str(DEFAULT_KEYMAP), DEFAULT_KEYMAP),
lambda: ('"dictionaries":("user.json","main.json")', list(map(DictionaryConfig, ("user.json", "main.json")))),
)
Expand Down
4 changes: 3 additions & 1 deletion test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_config_dict():
'enabled_extensions': set(),
'auto_start': False,
'machine_type': 'Keyboard',
'machine_specific_options': { 'arpeggiate': False },
'machine_specific_options': { 'arpeggiate': False, 'first_up_chord_send': False },
'system_name': config.DEFAULT_SYSTEM_NAME,
'system_keymap': DEFAULT_KEYMAP,
'dictionaries': [DictionaryConfig(p) for p in english_stenotype.DEFAULT_DICTIONARIES]
Expand Down Expand Up @@ -249,11 +249,13 @@ def test_config_dict():
{
'machine_specific_options': {
'arpeggiate': True,
'first_up_chord_send': False,
}
},
'''
[Keyboard]
arpeggiate = True
first_up_chord_send = False
'''
),

Expand Down
22 changes: 18 additions & 4 deletions test/test_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ def capture():
with mock.patch('plover.machine.keyboard.KeyboardCapture', new=lambda: capture):
yield capture

@pytest.fixture(params=[False])
@pytest.fixture(params=[{'arpeggiate': False, 'first_up_chord_send': False}])
def machine(request, capture):
machine = Keyboard({'arpeggiate': request.param})
machine = Keyboard(request.param)
keymap = Keymap(Keyboard.KEYS_LAYOUT.split(),
system.KEYS + Keyboard.ACTIONS)
keymap.set_mappings(system.KEYMAPS['Keyboard'])
machine.set_keymap(keymap)
return machine

def arpeggiate(func):
return pytest.mark.parametrize('machine', [True], indirect=True)(func)
arpeggiate = pytest.mark.parametrize('machine', [{'arpeggiate': True, 'first_up_chord_send': False}], indirect=True)
first_up_chord_send = pytest.mark.parametrize('machine', [{'arpeggiate': False, 'first_up_chord_send': True}], indirect=True)
"""
These are decorators to be applied on test functions to modify the machine configuration.
Note that at the moment it's not possible to apply both at the same time.
"""

@pytest.fixture
def strokes(machine):
Expand Down Expand Up @@ -97,3 +101,13 @@ def test_arpeggiate_2(capture, machine, strokes):
machine.start_capture()
send_input(capture, 'a +h +space -space -h w')
assert strokes == [{'S-', '*'}]

@first_up_chord_send
def test_first_up_chord_send(capture, machine, strokes):
machine.start_capture()
send_input(capture, '+a +w +l -l +l')
assert strokes == [{'S-', 'T-', '-G'}]
send_input(capture, '-l')
assert strokes == [{'S-', 'T-', '-G'}, {'S-', 'T-', '-G'}]
send_input(capture, '-a -w')
assert strokes == [{'S-', 'T-', '-G'}, {'S-', 'T-', '-G'}]

0 comments on commit f3144b5

Please sign in to comment.