Skip to content

Commit b64bbcd

Browse files
committed
test: update e2e test
1 parent 4667860 commit b64bbcd

35 files changed

+1471
-28
lines changed

e2e/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import urllib.request
44
import json
55

6-
DEFAULT_VERSION = "2.2.0-beta.12+c733b95"
6+
DEFAULT_VERSION = "2.2.0-beta.19"
77

88
builds_dir = os.path.join(os.path.dirname(__file__), "builds")
99

e2e/ccos.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CCOS:
6363
action_to_id: dict[int, str]
6464
id_to_action: dict[str, int]
6565
id_to_keycode: dict[str, int]
66+
settings: dict[str, dict[str, dict]]
6667

6768
meta: dict
6869
actions: dict
@@ -75,6 +76,7 @@ def __init__(self, lib_path: str, data_path: str):
7576
self.action_to_id = {}
7677
self.id_to_action = {}
7778
self.id_to_keycode = {}
79+
self.settings = {}
7880
self.lib = cdll.LoadLibrary(lib_path)
7981
self.idle = False
8082

@@ -121,7 +123,20 @@ def load_factory_defaults(items: dict):
121123

122124
load_factory_defaults(self.meta["factory_defaults"])
123125

124-
with open(os.path.join(os.path.dirname(lib_path), "actions.json"), "r") as f:
126+
with open(
127+
os.path.join(os.path.dirname(lib_path), self.meta["settings"]), "r"
128+
) as f:
129+
settings = json.load(f)
130+
for category in settings:
131+
category_name = category["name"]
132+
self.settings[category_name] = {}
133+
for item in category["items"]:
134+
item_name = item["name"]
135+
self.settings[category_name][item_name] = item
136+
137+
with open(
138+
os.path.join(os.path.dirname(lib_path), self.meta["actions"]), "r"
139+
) as f:
125140
self.actions = json.load(f)
126141
for group in self.actions:
127142
group_actions = group["actions"]

e2e/ccos_wrapper.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,15 @@ def verify_layout(self, profile: str, layout: list[list[int]]):
113113
for key, action in enumerate(row):
114114
command = f"VAR B3 {profile}{layer + 1} {key}"
115115
self.serial_verify(command, f"{command} {action} 0")
116+
117+
def set_setting(self, category: str, item: str, value: str | int):
118+
setting_info: dict = self.ccos.settings[category][item]
119+
value_id: int = (
120+
setting_info["enum"].index(value) if isinstance(value, str) else value
121+
)
122+
assert value_id >= 0, f"Invalid setting value: {value}"
123+
command_str = f"VAR B2 0x{setting_info['id']:02X} {value_id}"
124+
self.serial_verify(
125+
command_str,
126+
f"{command_str} 0",
127+
)

e2e/runner.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
22
import json
33
import yaml
4-
from unittest import TestSuite, TestCase, main
4+
from unittest import TestSuite, TestCase
55
import io
6+
import re
67
from xmlrunner import XMLTestRunner
78
from xmlrunner.extra.xunit_plugin import transform
89

@@ -37,6 +38,8 @@ def tearDown(self):
3738
self.wrapper.ccos.unload()
3839

3940
def runTest(self):
41+
print(f"{BOLD}Running test: {self.id()}{RESET}")
42+
4043
assert isinstance(self.test_case["test"], list)
4144
for command in self.test_case["test"]:
4245
print(f"{BOLD}============={RESET}")
@@ -58,6 +61,13 @@ def runTest(self):
5861
for chord in command["verifyChords"]:
5962
self.wrapper.check_chord(chord["input"], chord["output"])
6063
print(f"{BLUE}...1ms{RESET}")
64+
if "settings" in command:
65+
for category_name, category in command["settings"].items():
66+
for setting_name, setting_value in category.items():
67+
self.wrapper.set_setting(
68+
category_name, setting_name, setting_value
69+
)
70+
6171
if "remap" in command:
6272
print(json.dumps(command))
6373
for layer, remaps in command["remap"].items():
@@ -90,15 +100,28 @@ def runTest(self):
90100
self.wrapper.millis += command["step"]
91101
self.wrapper.ccos.update(self.wrapper.millis)
92102
print(f"{BLUE}...{command['step']}ms{RESET}")
93-
if "keys" in command:
103+
if "keys" in command or "modifiers" in command:
104+
modifiers = command.get("modifiers", {})
105+
keys = command.get("keys", [])
94106
print(
95-
f"{YELLOW}? modifiers=[{', '.join(command.get('modifiers', []))}] keys=[{', '.join(command['keys'])}]{RESET}"
107+
f"{YELLOW}? modifiers=[{', '.join(modifiers.keys())}] keys=[{', '.join(keys)}]{RESET}"
96108
)
97109
self.assertGreater(len(self.wrapper.reports), 0)
98110
report = self.wrapper.reports.pop(0)
99-
keys = [self.wrapper.ccos.toKeycode(key) for key in command["keys"]]
111+
expected_modifiers = (
112+
(modifiers.get("lctrl", False) << 0)
113+
| (modifiers.get("lshift", False) << 1)
114+
| (modifiers.get("lalt", False) << 2)
115+
| (modifiers.get("lmeta", False) << 3)
116+
| (modifiers.get("rctrl", False) << 4)
117+
| (modifiers.get("rshift", False) << 5)
118+
| (modifiers.get("ralt", False) << 6)
119+
| (modifiers.get("rmeta", False) << 7)
120+
)
121+
expected_keys = [self.wrapper.ccos.toKeycode(key) for key in keys]
100122
report.keys = [key for key in report.keys if key != 0]
101-
self.assertEqual(report.keys, keys)
123+
self.assertEqual(report.keys, expected_keys)
124+
self.assertEqual(report.modifiers, expected_modifiers)
102125

103126
self.assertEqual(
104127
0,
@@ -152,23 +175,34 @@ def runTest(self):
152175
self.wrapper.check_chord_backup([])
153176

154177

155-
def collect_tests(build_dir: str) -> TestSuite:
156-
tests: list[TestCase] = [FactoryTest(build_dir)]
178+
def collect_tests(build_dir: str, filter: str | None) -> TestSuite:
179+
filter_match = re.compile(filter) if filter is not None else None
180+
tests: list[TestCase] = (
181+
[FactoryTest(build_dir)]
182+
if filter_match is None or filter_match.match("factory")
183+
else []
184+
)
157185
for root, _, files in os.walk(tests_dir):
186+
dirs = os.path.relpath(root, tests_dir).split(os.sep)
187+
if dirs == ["."]:
188+
dirs = []
158189
for file in files:
159190
if not file.endswith(".yml"):
160191
continue
192+
test_name = ".".join([*dirs, file.removesuffix(".yml")])
193+
if filter_match is not None and not filter_match.match(test_name):
194+
continue
161195
with open(os.path.join(root, file), "r") as f:
162-
test = CCOSTest(build_dir, file.removesuffix(".yml"), yaml.safe_load(f))
196+
test = CCOSTest(build_dir, test_name, yaml.safe_load(f))
163197
tests.append(test)
164198
return TestSuite(tests)
165199

166200

167-
def run_tests(build_dir: str):
201+
def run_tests(build_dir: str, filter: str | None = None):
168202
report_file = os.path.join(e2e_dir, "report.xml")
169203
if os.path.exists(report_file):
170204
os.remove(report_file)
171-
suite = collect_tests(build_dir)
205+
suite = collect_tests(build_dir, filter)
172206
out = io.BytesIO()
173207
runner = XMLTestRunner(output=out)
174208
runner.run(suite)

e2e/tests/actions/capitalize.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
test:
2+
- clearChords: true
3+
addChords:
4+
- input: [[c, p]]
5+
output: [CAPITALIZE]
6+
- input: [[a, b]]
7+
output: [a, b, c]
8+
idle: true
9+
10+
- press: [c, p]
11+
keys: [c, p]
12+
- release: [c, p]
13+
- step: 16
14+
keys: []
15+
- keys: [BKSP]
16+
- keys: []
17+
- keys: [BKSP]
18+
- keys: []
19+
idle: true
20+
21+
- press: [a, b]
22+
keys: [a, b]
23+
- release: [a, b]
24+
- step: 16
25+
keys: []
26+
- keys: [BKSP]
27+
- keys: []
28+
- keys: [BKSP]
29+
- keys: [a]
30+
modifiers:
31+
lshift: true
32+
- keys: [b]
33+
- keys: [c]
34+
- keys: [SPACE]
35+
- keys: []
36+
idle: true
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
test:
2+
- clearChords: true
3+
addChords:
4+
- input: [[c, p]]
5+
output: [CAPITALIZE, KSC_00]
6+
- input: [[a, b]]
7+
output: [JOIN, a, b, c, KSC_00]
8+
idle: true
9+
10+
- press: [c, p]
11+
keys: [c, p]
12+
- release: [c, p]
13+
- step: 16
14+
keys: []
15+
- keys: [BKSP]
16+
- keys: []
17+
- keys: [BKSP]
18+
- keys: []
19+
idle: true
20+
21+
- press: [a, b]
22+
keys: [a, b]
23+
- release: [a, b]
24+
- step: 16
25+
keys: []
26+
- keys: [BKSP]
27+
- keys: []
28+
- keys: [BKSP]
29+
- keys: [a]
30+
modifiers:
31+
lshift: true
32+
- keys: [b]
33+
- keys: [c]
34+
- keys: []
35+
idle: true
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
test:
22
- remap:
33
A1:
4-
- [b, DUP]
4+
- [d, DUP]
55
idle: true
66

77
- press: [a]
88
keys: [a]
99
- release: [a]
1010
- step: 16
1111
keys: []
12+
idle: true
1213

13-
- press: [b]
14+
- press: [d]
1415
keys: [a]
15-
- release: [b]
16+
- release: [d]
1617
- step: 16
1718
keys: []
19+
idle: true
1820

1921
- press: [c]
2022
keys: [c]
2123
- release: [c]
2224
- step: 16
2325
keys: []
26+
idle: true
2427

25-
- press: [b]
28+
- press: [d]
2629
keys: [c]
27-
- release: [b]
30+
- release: [d]
2831
- step: 16
2932
keys: []
30-
31-
- idle: true
33+
idle: true
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
test:
2+
- remap:
3+
A1:
4+
- [d, DUP]
5+
idle: true
6+
7+
- press: [a]
8+
keys: [a]
9+
- release: [a]
10+
- step: 16
11+
keys: []
12+
idle: true
13+
14+
- press: [LEFT_SHIFT]
15+
modifiers:
16+
lshift: true
17+
- press: [d]
18+
keys: [a]
19+
modifiers:
20+
lshift: true
21+
- release: [LEFT_SHIFT, d]
22+
- step: 16
23+
keys: []
24+
idle: true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
test:
2+
- remap:
3+
A1:
4+
- [d, DUP]
5+
idle: true
6+
7+
- press: [a]
8+
keys: [a]
9+
- release: [a]
10+
- step: 16
11+
keys: []
12+
idle: true
13+
14+
- step: 16
15+
idle: true
16+
17+
- press: [a]
18+
keys: [a]
19+
- press: [d]
20+
keys: []
21+
- keys: [a]
22+
- release: [a, d]
23+
- step: 16
24+
keys: []
25+
idle: true

0 commit comments

Comments
 (0)