diff options
| author | Sergey Vlasov <sigprof@gmail.com> | 2024-09-13 23:52:31 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-14 06:52:31 +1000 |
| commit | 0b3ece1189b11e36790c99a1a80f75413b826bb4 (patch) | |
| tree | 464b4e70e0368ccc7e5c7331f38b8f0f2c9a23ec /lib/python/qmk | |
| parent | ae4ab5ed31360cbb327436ae7e76d1d0cef59449 (diff) | |
`qmk find`: Fix handling of keys with dots in filter functions (#24393)
Diffstat (limited to 'lib/python/qmk')
| -rw-r--r-- | lib/python/qmk/search.py | 10 | ||||
| -rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 65 |
2 files changed, 71 insertions, 4 deletions
diff --git a/lib/python/qmk/search.py b/lib/python/qmk/search.py index baaf11eb34..25e3d92066 100644 --- a/lib/python/qmk/search.py +++ b/lib/python/qmk/search.py | |||
| @@ -74,28 +74,30 @@ class Exists(FilterFunction): | |||
| 74 | func_name = "exists" | 74 | func_name = "exists" |
| 75 | 75 | ||
| 76 | def apply(self, target_info: KeyboardKeymapDesc) -> bool: | 76 | def apply(self, target_info: KeyboardKeymapDesc) -> bool: |
| 77 | return self.key in target_info.data | 77 | return self.key in target_info.dotty |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | class Absent(FilterFunction): | 80 | class Absent(FilterFunction): |
| 81 | func_name = "absent" | 81 | func_name = "absent" |
| 82 | 82 | ||
| 83 | def apply(self, target_info: KeyboardKeymapDesc) -> bool: | 83 | def apply(self, target_info: KeyboardKeymapDesc) -> bool: |
| 84 | return self.key not in target_info.data | 84 | return self.key not in target_info.dotty |
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | class Length(FilterFunction): | 87 | class Length(FilterFunction): |
| 88 | func_name = "length" | 88 | func_name = "length" |
| 89 | 89 | ||
| 90 | def apply(self, target_info: KeyboardKeymapDesc) -> bool: | 90 | def apply(self, target_info: KeyboardKeymapDesc) -> bool: |
| 91 | return (self.key in target_info.data and len(target_info.data[self.key]) == int(self.value)) | 91 | info_dotty = target_info.dotty |
| 92 | return (self.key in info_dotty and len(info_dotty[self.key]) == int(self.value)) | ||
| 92 | 93 | ||
| 93 | 94 | ||
| 94 | class Contains(FilterFunction): | 95 | class Contains(FilterFunction): |
| 95 | func_name = "contains" | 96 | func_name = "contains" |
| 96 | 97 | ||
| 97 | def apply(self, target_info: KeyboardKeymapDesc) -> bool: | 98 | def apply(self, target_info: KeyboardKeymapDesc) -> bool: |
| 98 | return (self.key in target_info.data and self.value in target_info.data[self.key]) | 99 | info_dotty = target_info.dotty |
| 100 | return (self.key in info_dotty and self.value in info_dotty[self.key]) | ||
| 99 | 101 | ||
| 100 | 102 | ||
| 101 | def _get_filter_class(func_name: str, key: str, value: str) -> Optional[FilterFunction]: | 103 | def _get_filter_class(func_name: str, key: str, value: str) -> Optional[FilterFunction]: |
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 4c322e0c9d..f18bd12f82 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py | |||
| @@ -347,3 +347,68 @@ def test_format_json_keymap_auto(): | |||
| 347 | result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_keymap.json') | 347 | result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_keymap.json') |
| 348 | check_returncode(result) | 348 | check_returncode(result) |
| 349 | assert result.stdout == '{\n "keyboard": "handwired/pytest/basic",\n "keymap": "test",\n "layers": [\n ["KC_A"]\n ],\n "layout": "LAYOUT_ortho_1x1",\n "version": 1\n}\n' | 349 | assert result.stdout == '{\n "keyboard": "handwired/pytest/basic",\n "keymap": "test",\n "layers": [\n ["KC_A"]\n ],\n "layout": "LAYOUT_ortho_1x1",\n "version": 1\n}\n' |
| 350 | |||
| 351 | |||
| 352 | def test_find_exists(): | ||
| 353 | result = check_subcommand('find', '-f', 'exists(rgb_matrix.split_count)', '-p', 'rgb_matrix.split_count') | ||
| 354 | check_returncode(result) | ||
| 355 | values = [s for s in result.stdout.splitlines() if 'rgb_matrix.split_count=' in s] | ||
| 356 | assert len(values) > 0 | ||
| 357 | for s in values: | ||
| 358 | assert '=None' not in s | ||
| 359 | assert '=[' in s | ||
| 360 | |||
| 361 | |||
| 362 | def test_find_absent(): | ||
| 363 | result = check_subcommand('find', '-f', 'absent(rgb_matrix.split_count)', '-p', 'rgb_matrix.split_count') | ||
| 364 | check_returncode(result) | ||
| 365 | values = [s for s in result.stdout.splitlines() if 'rgb_matrix.split_count=' in s] | ||
| 366 | assert len(values) > 0 | ||
| 367 | for s in values: | ||
| 368 | assert '=None' in s | ||
| 369 | assert '=[' not in s | ||
| 370 | |||
| 371 | |||
| 372 | def test_find_length(): | ||
| 373 | result = check_subcommand('find', '-f', 'length(matrix_pins.cols, 6)', '-p', 'matrix_pins.cols') | ||
| 374 | check_returncode(result) | ||
| 375 | values = [s for s in result.stdout.splitlines() if 'matrix_pins.cols=' in s] | ||
| 376 | assert len(values) > 0 | ||
| 377 | for s in values: | ||
| 378 | assert s.count(',') == 5 | ||
| 379 | |||
| 380 | |||
| 381 | def test_find_contains(): | ||
| 382 | result = check_subcommand('find', '-f', 'contains(matrix_pins.cols, B1)', '-p', 'matrix_pins.cols') | ||
| 383 | check_returncode(result) | ||
| 384 | values = [s for s in result.stdout.splitlines() if 'matrix_pins.cols=' in s] | ||
| 385 | assert len(values) > 0 | ||
| 386 | for s in values: | ||
| 387 | assert "'B1'" in s | ||
| 388 | |||
| 389 | |||
| 390 | def test_find_multiple_conditions(): | ||
| 391 | # this is intended to match at least 'crkbd/rev1' | ||
| 392 | result = check_subcommand( | ||
| 393 | 'find', '-f', 'exists(rgb_matrix.split_count)', '-f', 'contains(matrix_pins.cols, B1)', '-f', 'length(matrix_pins.cols, 6)', '-f', 'absent(eeprom.driver)', '-f', 'ws2812.pin=D3', '-p', 'rgb_matrix.split_count', '-p', 'matrix_pins.cols', '-p', | ||
| 394 | 'eeprom.driver', '-p', 'ws2812.pin' | ||
| 395 | ) | ||
| 396 | check_returncode(result) | ||
| 397 | rgb_matrix_split_count_values = [s for s in result.stdout.splitlines() if 'rgb_matrix.split_count=' in s] | ||
| 398 | assert len(rgb_matrix_split_count_values) > 0 | ||
| 399 | for s in rgb_matrix_split_count_values: | ||
| 400 | assert '=None' not in s | ||
| 401 | assert '=[' in s | ||
| 402 | matrix_pins_cols_values = [s for s in result.stdout.splitlines() if 'matrix_pins.cols=' in s] | ||
| 403 | assert len(matrix_pins_cols_values) > 0 | ||
| 404 | for s in matrix_pins_cols_values: | ||
| 405 | assert s.count(',') == 5 | ||
| 406 | assert "'B1'" in s | ||
| 407 | eeprom_driver_values = [s for s in result.stdout.splitlines() if 'eeprom.driver=' in s] | ||
| 408 | assert len(eeprom_driver_values) > 0 | ||
| 409 | for s in eeprom_driver_values: | ||
| 410 | assert '=None' in s | ||
| 411 | ws2812_pin_values = [s for s in result.stdout.splitlines() if 'ws2812.pin=' in s] | ||
| 412 | assert len(ws2812_pin_values) > 0 | ||
| 413 | for s in ws2812_pin_values: | ||
| 414 | assert '=D3' in s | ||
