summaryrefslogtreecommitdiff
path: root/lib/python/qmk/tests
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-03-25 04:38:10 -0700
committerGitHub <noreply@github.com>2021-03-25 22:38:10 +1100
commit3e60997edba46544557b3a775bdb1538e07c3edf (patch)
tree165923c2cd6b5eeee150c0285ce8ed9eff44eaee /lib/python/qmk/tests
parenta74846a0dbd5efbc7b993918f7f3122e1d620c24 (diff)
Add a `qmk format-json` command that will format JSON files (#12372)
* Add a command to format json files * change to work after rebase * add test for qmk format-json * add documentation for qmk format-json * Update lib/python/qmk/cli/format/json.py
Diffstat (limited to 'lib/python/qmk/tests')
-rw-r--r--lib/python/qmk/tests/minimal_info.json13
-rw-r--r--lib/python/qmk/tests/minimal_keymap.json7
-rw-r--r--lib/python/qmk/tests/pytest_export.json6
-rw-r--r--lib/python/qmk/tests/test_cli_commands.py24
4 files changed, 44 insertions, 6 deletions
diff --git a/lib/python/qmk/tests/minimal_info.json b/lib/python/qmk/tests/minimal_info.json
new file mode 100644
index 0000000000..b91c23bd3d
--- /dev/null
+++ b/lib/python/qmk/tests/minimal_info.json
@@ -0,0 +1,13 @@
+{
+ "keyboard_name": "tester",
+ "maintainer": "qmk",
+ "height": 5,
+ "width": 15,
+ "layouts": {
+ "LAYOUT": {
+ "layout": [
+ { "label": "KC_A", "x": 0, "y": 0, "matrix": [0, 0] }
+ ]
+ }
+ }
+}
diff --git a/lib/python/qmk/tests/minimal_keymap.json b/lib/python/qmk/tests/minimal_keymap.json
new file mode 100644
index 0000000000..258f9e8a9a
--- /dev/null
+++ b/lib/python/qmk/tests/minimal_keymap.json
@@ -0,0 +1,7 @@
+{
+ "keyboard": "handwired/pytest/basic",
+ "keymap": "test",
+ "layers": [["KC_A"]],
+ "layout": "LAYOUT_ortho_1x1",
+ "version": 1
+}
diff --git a/lib/python/qmk/tests/pytest_export.json b/lib/python/qmk/tests/pytest_export.json
deleted file mode 100644
index 5fb0d624f8..0000000000
--- a/lib/python/qmk/tests/pytest_export.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "keyboard":"handwired/pytest/basic",
- "keymap":"pytest_unittest",
- "layout":"LAYOUT",
- "layers":[["KC_A"]]
-}
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
index a97472e6be..c57d2b7fc7 100644
--- a/lib/python/qmk/tests/test_cli_commands.py
+++ b/lib/python/qmk/tests/test_cli_commands.py
@@ -259,3 +259,27 @@ def test_generate_layouts():
result = check_subcommand('generate-layouts', '-kb', 'handwired/pytest/basic')
check_returncode(result)
assert '#define LAYOUT_custom(k0A) {' in result.stdout
+
+
+def test_format_json_keyboard():
+ result = check_subcommand('format-json', '--format', 'keyboard', 'lib/python/qmk/tests/minimal_info.json')
+ check_returncode(result)
+ assert result.stdout == '{\n "keyboard_name": "tester",\n "maintainer": "qmk",\n "height": 5,\n "width": 15,\n "layouts": {\n "LAYOUT": {\n "layout": [\n { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 }\n ]\n }\n }\n}\n'
+
+
+def test_format_json_keymap():
+ result = check_subcommand('format-json', '--format', 'keymap', 'lib/python/qmk/tests/minimal_keymap.json')
+ check_returncode(result)
+ assert result.stdout == '{\n "version": 1,\n "keyboard": "handwired/pytest/basic",\n "keymap": "test",\n "layout": "LAYOUT_ortho_1x1",\n "layers": [\n [\n "KC_A"\n ]\n ]\n}\n'
+
+
+def test_format_json_keyboard_auto():
+ result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_info.json')
+ check_returncode(result)
+ assert result.stdout == '{\n "keyboard_name": "tester",\n "maintainer": "qmk",\n "height": 5,\n "width": 15,\n "layouts": {\n "LAYOUT": {\n "layout": [\n { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 }\n ]\n }\n }\n}\n'
+
+
+def test_format_json_keymap_auto():
+ result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_keymap.json')
+ check_returncode(result)
+ 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'