Speed up unit tests
This commit is contained in:
@@ -7,6 +7,7 @@ from tests.keyboard_test import KeyboardTest
|
||||
|
||||
class TestStringSubstitution(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.delay = KeyboardTest.loop_delay_ms
|
||||
self.symbols = '`-=[]\\;\',./~!@#$%^&*()_+{}|:\"<>?'
|
||||
self.everything = ALL_NUMBERS + ALL_ALPHAS + ALL_ALPHAS.lower() + self.symbols
|
||||
self.test_dictionary = {
|
||||
@@ -46,21 +47,21 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
# that results in a corresponding match, as that key is never sent
|
||||
self.keyboard.test(
|
||||
'multi-character key, single-character value',
|
||||
[(0, True), (0, False), (0, True), (0, False), 50],
|
||||
[(0, True), (0, False), (0, True), (0, False), self.delay],
|
||||
[{KC.A}, {}, {KC.BACKSPACE}, {}, {KC.B}, {}],
|
||||
)
|
||||
# note: the pressed key is never sent here, as the event is
|
||||
# intercepted and the replacement is sent instead
|
||||
self.keyboard.test(
|
||||
'multi-character value, single-character key',
|
||||
[(1, True), (1, False), 50],
|
||||
[(1, True), (1, False), self.delay],
|
||||
[{KC.A}, {}, {KC.A}, {}],
|
||||
)
|
||||
# modifiers are force-released if there's a match,
|
||||
# so the keyup event for them isn't sent
|
||||
self.keyboard.test(
|
||||
'shifted alphanumeric or symbol in key and/or value',
|
||||
[(3, True), (2, True), (2, False), (3, False), 50],
|
||||
[(3, True), (2, True), (2, False), (3, False), self.delay],
|
||||
[{KC.LSHIFT}, {KC.LSHIFT, KC.N2}, {}],
|
||||
)
|
||||
self.keyboard.test(
|
||||
@@ -74,7 +75,7 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
(5, False),
|
||||
(5, True),
|
||||
(5, False),
|
||||
10,
|
||||
self.delay,
|
||||
],
|
||||
[
|
||||
{KC.D},
|
||||
@@ -93,7 +94,7 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
)
|
||||
self.keyboard.test(
|
||||
'the presence of non-shift modifiers prevents a multi-character match',
|
||||
[(4, True), (0, True), (0, False), (0, True), (0, False), (4, False), 50],
|
||||
[(4, True), (0, True), (0, False), (0, True), (0, False), (4, False)],
|
||||
[
|
||||
{KC.LCTRL},
|
||||
{KC.LCTRL, KC.A},
|
||||
@@ -105,7 +106,7 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
)
|
||||
self.keyboard.test(
|
||||
'the presence of non-shift modifiers prevents a single-character match',
|
||||
[(4, True), (1, True), (1, False), (4, False), 50],
|
||||
[(4, True), (1, True), (1, False), (4, False)],
|
||||
[
|
||||
{KC.LCTRL},
|
||||
{KC.LCTRL, KC.B},
|
||||
@@ -115,7 +116,7 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
)
|
||||
self.keyboard.test(
|
||||
'the presence of non-shift modifiers resets current potential matches',
|
||||
[(0, True), (0, False), (4, True), (0, True), (0, False), (4, False), 50],
|
||||
[(0, True), (0, False), (4, True), (0, True), (0, False), (4, False)],
|
||||
[
|
||||
{KC.A},
|
||||
{},
|
||||
@@ -128,7 +129,15 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
|
||||
self.keyboard.test(
|
||||
'match found and replaced when there are preceding characters',
|
||||
[(5, True), (5, False), (0, True), (0, False), (0, True), (0, False), 50],
|
||||
[
|
||||
(5, True),
|
||||
(5, False),
|
||||
(0, True),
|
||||
(0, False),
|
||||
(0, True),
|
||||
(0, False),
|
||||
self.delay,
|
||||
],
|
||||
[
|
||||
{KC.C},
|
||||
{},
|
||||
@@ -142,7 +151,15 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
)
|
||||
self.keyboard.test(
|
||||
'match found and replaced when there are trailing characters, and the trailing characters are sent',
|
||||
[(0, True), (0, False), (0, True), (0, False), (5, True), (5, False), 50],
|
||||
[
|
||||
(0, True),
|
||||
(0, False),
|
||||
(0, True),
|
||||
(0, False),
|
||||
(5, True),
|
||||
(5, False),
|
||||
self.delay,
|
||||
],
|
||||
[
|
||||
{KC.A},
|
||||
{},
|
||||
@@ -156,7 +173,7 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
)
|
||||
self.keyboard.test(
|
||||
'no match',
|
||||
[(0, True), (0, False), (2, True), (2, False), 50],
|
||||
[(0, True), (0, False), (2, True), (2, False)],
|
||||
[
|
||||
{KC.A},
|
||||
{},
|
||||
@@ -183,7 +200,7 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
(6, False),
|
||||
(0, True),
|
||||
(0, False),
|
||||
50,
|
||||
10 * self.delay,
|
||||
],
|
||||
[
|
||||
{KC.D},
|
||||
@@ -241,7 +258,7 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
# send the unreachable match "cccc" after matching "ccc"
|
||||
(5, True),
|
||||
(5, False),
|
||||
10,
|
||||
self.delay,
|
||||
],
|
||||
[
|
||||
{KC.C},
|
||||
@@ -272,7 +289,7 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
(0, True),
|
||||
(0, False),
|
||||
(7, False),
|
||||
10,
|
||||
self.delay,
|
||||
],
|
||||
[
|
||||
{KC.RSHIFT},
|
||||
@@ -303,7 +320,6 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
(0, False),
|
||||
(4, False),
|
||||
(8, False),
|
||||
10,
|
||||
],
|
||||
[
|
||||
{KC.RALT},
|
||||
@@ -325,7 +341,6 @@ class TestStringSubstitution(unittest.TestCase):
|
||||
(1, False),
|
||||
(3, False),
|
||||
(8, False),
|
||||
10,
|
||||
],
|
||||
[
|
||||
{KC.RALT},
|
||||
|
Reference in New Issue
Block a user