summaryrefslogtreecommitdiff
path: root/lib/python/qmk/tests
diff options
context:
space:
mode:
authorErovia <Erovia@users.noreply.github.com>2022-02-28 20:02:39 +0000
committerGitHub <noreply@github.com>2022-02-28 20:02:39 +0000
commitfbfd5312b995a32af690c183cad0dc988f695e89 (patch)
treebf241a475ec51b79d6427ac422f197b6d3720661 /lib/python/qmk/tests
parent779c7debcfff1a4a3ad578a0c12bdd50cba11039 (diff)
downloadqmk_firmware-fbfd5312b995a32af690c183cad0dc988f695e89.tar.gz
qmk_firmware-fbfd5312b995a32af690c183cad0dc988f695e89.zip
CLI: Validate JSON keymap input (#16261)
* Fix schema validator It should use the passed schema. * Add required attributes to keymap schema * Rework subcommands to validate the JSON keymaps The 'compile', 'flash' and 'json2c' subcommands were reworked to add JSON keymap validation so error is reported for non-JSON and non-compliant-JSON inputs. * Fix required fields in keymap schema * Add tests * Fix compiling keymaps directly from keymap directory * Schema should not require version for now.
Diffstat (limited to 'lib/python/qmk/tests')
-rw-r--r--lib/python/qmk/tests/test_cli_commands.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
index 54b143c64f..55e69175e6 100644
--- a/lib/python/qmk/tests/test_cli_commands.py
+++ b/lib/python/qmk/tests/test_cli_commands.py
@@ -156,6 +156,18 @@ def test_json2c_stdin():
assert result.stdout == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT_ortho_1x1(KC_A)};\n\n'
+def test_json2c_wrong_json():
+ result = check_subcommand('json2c', 'keyboards/handwired/pytest/info.json')
+ check_returncode(result, [1])
+ assert 'Invalid JSON keymap' in result.stdout
+
+
+def test_json2c_no_json():
+ result = check_subcommand('json2c', 'keyboards/handwired/pytest/pytest.h')
+ check_returncode(result, [1])
+ assert 'Invalid JSON encountered' in result.stdout
+
+
def test_info():
result = check_subcommand('info', '-kb', 'handwired/pytest/basic')
check_returncode(result)