mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-02 15:40:19 +00:00
more tests for holding
This commit is contained in:
parent
d5f1405e28
commit
20d19b5378
@ -457,7 +457,8 @@ def parse(macro, mapping, return_errors=False):
|
||||
mapping : Mapping
|
||||
The preset object, needed for some config stuff
|
||||
return_errors : bool
|
||||
if True, returns errors as a string or None if parsing worked
|
||||
If True, returns errors as a string or None if parsing worked.
|
||||
If False, returns the parsed macro.
|
||||
"""
|
||||
# whitespaces, tabs, newlines and such don't serve a purpose. make
|
||||
# the log output clearer and the parsing easier.
|
||||
|
@ -24,7 +24,7 @@ import unittest
|
||||
import asyncio
|
||||
|
||||
from keymapper.dev.macros import parse, _Macro, _extract_params, \
|
||||
is_this_a_macro
|
||||
is_this_a_macro, _parse_recurse
|
||||
from keymapper.config import config
|
||||
from keymapper.mapping import Mapping
|
||||
from keymapper.state import system_mapping
|
||||
@ -95,6 +95,11 @@ class TestMacros(unittest.TestCase):
|
||||
self.assertIsNone(parse('r(a, k(b))', self.mapping))
|
||||
self.assertIsNone(parse('m(a, b)', self.mapping))
|
||||
|
||||
def test_parse_params(self):
|
||||
self.assertEqual(_parse_recurse('', self.mapping), None)
|
||||
self.assertEqual(_parse_recurse('5', self.mapping), 5)
|
||||
self.assertEqual(_parse_recurse('foo', self.mapping), 'foo')
|
||||
|
||||
def test_0(self):
|
||||
macro = parse('k(1)', self.mapping)
|
||||
macro.set_handler(self.handler)
|
||||
@ -179,7 +184,28 @@ class TestMacros(unittest.TestCase):
|
||||
|
||||
self.assertEqual(len(macro.child_macros), 1)
|
||||
|
||||
def test_hold_forever(self):
|
||||
def test_dont_hold(self):
|
||||
macro = parse('k(1).h(k(a)).k(3)', self.mapping)
|
||||
macro.set_handler(self.handler)
|
||||
self.assertSetEqual(macro.get_capabilities(), {
|
||||
system_mapping.get('1'),
|
||||
system_mapping.get('a'),
|
||||
system_mapping.get('3')
|
||||
})
|
||||
|
||||
asyncio.ensure_future(macro.run())
|
||||
self.loop.run_until_complete(asyncio.sleep(0.2))
|
||||
self.assertFalse(macro.is_holding())
|
||||
# press_key was never called, so the macro completes right away
|
||||
# and the child macro of hold is never called.
|
||||
self.assertEqual(len(self.result), 4)
|
||||
|
||||
self.assertEqual(self.result[0], (system_mapping.get('1'), 1))
|
||||
self.assertEqual(self.result[-1], (system_mapping.get('3'), 0))
|
||||
|
||||
self.assertEqual(len(macro.child_macros), 1)
|
||||
|
||||
def test_just_hold(self):
|
||||
macro = parse('k(1).h().k(3)', self.mapping)
|
||||
macro.set_handler(self.handler)
|
||||
self.assertSetEqual(macro.get_capabilities(), {
|
||||
@ -206,6 +232,26 @@ class TestMacros(unittest.TestCase):
|
||||
|
||||
self.assertEqual(len(macro.child_macros), 0)
|
||||
|
||||
def test_dont_just_hold(self):
|
||||
macro = parse('k(1).h().k(3)', self.mapping)
|
||||
macro.set_handler(self.handler)
|
||||
self.assertSetEqual(macro.get_capabilities(), {
|
||||
system_mapping.get('1'),
|
||||
system_mapping.get('3')
|
||||
})
|
||||
|
||||
asyncio.ensure_future(macro.run())
|
||||
self.loop.run_until_complete(asyncio.sleep(0.1))
|
||||
self.assertFalse(macro.is_holding())
|
||||
# since press_key was never called it just does the macro
|
||||
# completely
|
||||
self.assertEqual(len(self.result), 4)
|
||||
|
||||
self.assertEqual(self.result[0], (system_mapping.get('1'), 1))
|
||||
self.assertEqual(self.result[-1], (system_mapping.get('3'), 0))
|
||||
|
||||
self.assertEqual(len(macro.child_macros), 0)
|
||||
|
||||
def test_2(self):
|
||||
start = time.time()
|
||||
repeats = 20
|
||||
|
Loading…
Reference in New Issue
Block a user