diff options
author | Erovia <Erovia@users.noreply.github.com> | 2020-05-26 17:43:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-26 17:43:33 +0200 |
commit | 6501377070ff20bd061ea85c7ae5517652b6478b (patch) | |
tree | 5dd31794e887b98da40ed647405452a85c852f08 | |
parent | af2ca136045c0157c5c093fb902dccacd9fa0e32 (diff) | |
download | qmk_firmware-6501377070ff20bd061ea85c7ae5517652b6478b.tar.gz qmk_firmware-6501377070ff20bd061ea85c7ae5517652b6478b.zip |
CLI: fix `json2c` subcommand and add/fix tests (#9206)
Co-authored-by: Zach White <skullydazed@users.noreply.github.com>
-rw-r--r-- | keyboards/handwired/onekey/keymaps/default_json/keymap.json | 9 | ||||
-rw-r--r-- | keyboards/handwired/onekey/pytest/templates/keymap.c | 1 | ||||
-rwxr-xr-x | lib/python/qmk/cli/json2c.py | 12 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 6 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_qmk_keymap.py | 4 |
5 files changed, 24 insertions, 8 deletions
diff --git a/keyboards/handwired/onekey/keymaps/default_json/keymap.json b/keyboards/handwired/onekey/keymaps/default_json/keymap.json new file mode 100644 index 000000000..cf30f37b7 --- /dev/null +++ b/keyboards/handwired/onekey/keymaps/default_json/keymap.json | |||
@@ -0,0 +1,9 @@ | |||
1 | { | ||
2 | "keyboard":"handwired/onekey/pytest", | ||
3 | "keymap":"default_json", | ||
4 | "layout":"LAYOUT", | ||
5 | "layers":[["KC_A"]], | ||
6 | "author":"qmk", | ||
7 | "notes":"This file is a keymap.json file for handwired/onekey/pytest", | ||
8 | "version":1 | ||
9 | } | ||
diff --git a/keyboards/handwired/onekey/pytest/templates/keymap.c b/keyboards/handwired/onekey/pytest/templates/keymap.c index d355210c4..6cb25d522 100644 --- a/keyboards/handwired/onekey/pytest/templates/keymap.c +++ b/keyboards/handwired/onekey/pytest/templates/keymap.c | |||
@@ -1 +1,2 @@ | |||
1 | #include QMK_KEYBOARD_H | ||
1 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {__KEYMAP_GOES_HERE__}; | 2 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {__KEYMAP_GOES_HERE__}; |
diff --git a/lib/python/qmk/cli/json2c.py b/lib/python/qmk/cli/json2c.py index 521840507..af0d80a9a 100755 --- a/lib/python/qmk/cli/json2c.py +++ b/lib/python/qmk/cli/json2c.py | |||
@@ -18,19 +18,19 @@ def json2c(cli): | |||
18 | This command uses the `qmk.keymap` module to generate a keymap.c from a configurator export. The generated keymap is written to stdout, or to a file if -o is provided. | 18 | This command uses the `qmk.keymap` module to generate a keymap.c from a configurator export. The generated keymap is written to stdout, or to a file if -o is provided. |
19 | """ | 19 | """ |
20 | # Error checking | 20 | # Error checking |
21 | if not cli.args.filename.exists(): | 21 | if cli.args.filename and cli.args.filename.name == '-': |
22 | cli.log.error('JSON file does not exist!') | 22 | # TODO(skullydazed/anyone): Read file contents from STDIN |
23 | cli.log.error('Reading from STDIN is not (yet) supported.') | ||
23 | cli.print_usage() | 24 | cli.print_usage() |
24 | exit(1) | 25 | exit(1) |
25 | 26 | ||
26 | if cli.args.filename.name == '-': | 27 | if not cli.args.filename.exists(): |
27 | # TODO(skullydazed/anyone): Read file contents from STDIN | 28 | cli.log.error('JSON file does not exist!') |
28 | cli.log.error('Reading from STDIN is not (yet) supported.') | ||
29 | cli.print_usage() | 29 | cli.print_usage() |
30 | exit(1) | 30 | exit(1) |
31 | 31 | ||
32 | # Environment processing | 32 | # Environment processing |
33 | if cli.args.output.name == ('-'): | 33 | if cli.args.output and cli.args.output.name == '-': |
34 | cli.args.output = None | 34 | cli.args.output = None |
35 | 35 | ||
36 | # Parse the configurator json | 36 | # Parse the configurator json |
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index a93587150..768929de1 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py | |||
@@ -84,3 +84,9 @@ def test_list_keymaps_no_keyboard_found(): | |||
84 | result = check_subcommand('list-keymaps', '-kb', 'asdfghjkl') | 84 | result = check_subcommand('list-keymaps', '-kb', 'asdfghjkl') |
85 | assert result.returncode == 0 | 85 | assert result.returncode == 0 |
86 | assert 'does not exist' in result.stdout | 86 | assert 'does not exist' in result.stdout |
87 | |||
88 | |||
89 | def test_json2c(): | ||
90 | result = check_subcommand('json2c', 'keyboards/handwired/onekey/keymaps/default_json/keymap.json') | ||
91 | assert result.returncode == 0 | ||
92 | assert result.stdout == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT(KC_A)};\n\n' | ||
diff --git a/lib/python/qmk/tests/test_qmk_keymap.py b/lib/python/qmk/tests/test_qmk_keymap.py index 2db625600..d8669e549 100644 --- a/lib/python/qmk/tests/test_qmk_keymap.py +++ b/lib/python/qmk/tests/test_qmk_keymap.py | |||
@@ -8,12 +8,12 @@ def test_template_onekey_proton_c(): | |||
8 | 8 | ||
9 | def test_template_onekey_pytest(): | 9 | def test_template_onekey_pytest(): |
10 | templ = qmk.keymap.template('handwired/onekey/pytest') | 10 | templ = qmk.keymap.template('handwired/onekey/pytest') |
11 | assert templ == 'const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {__KEYMAP_GOES_HERE__};\n' | 11 | assert templ == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {__KEYMAP_GOES_HERE__};\n' |
12 | 12 | ||
13 | 13 | ||
14 | def test_generate_onekey_pytest(): | 14 | def test_generate_onekey_pytest(): |
15 | templ = qmk.keymap.generate('handwired/onekey/pytest', 'LAYOUT', [['KC_A']]) | 15 | templ = qmk.keymap.generate('handwired/onekey/pytest', 'LAYOUT', [['KC_A']]) |
16 | assert templ == 'const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT(KC_A)};\n' | 16 | assert templ == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT(KC_A)};\n' |
17 | 17 | ||
18 | 18 | ||
19 | # FIXME(skullydazed): Add a test for qmk.keymap.write that mocks up an FD. | 19 | # FIXME(skullydazed): Add a test for qmk.keymap.write that mocks up an FD. |