diff options
Diffstat (limited to 'lib/python/qmk/tests')
| -rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 08e80f2c9..efd9f6cf6 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py | |||
| @@ -8,11 +8,20 @@ is_windows = 'windows' in platform.platform().lower() | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | def check_subcommand(command, *args): | 10 | def check_subcommand(command, *args): |
| 11 | cmd = ['bin/qmk', command] + list(args) | 11 | cmd = ['bin/qmk', command, *args] |
| 12 | result = run(cmd, stdout=PIPE, stderr=STDOUT, universal_newlines=True) | 12 | result = run(cmd, stdout=PIPE, stderr=STDOUT, universal_newlines=True) |
| 13 | return result | 13 | return result |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | def check_subcommand_stdin(file_to_read, command, *args): | ||
| 17 | """Pipe content of a file to a command and return output. | ||
| 18 | """ | ||
| 19 | with open(file_to_read) as my_file: | ||
| 20 | cmd = ['bin/qmk', command, *args] | ||
| 21 | result = run(cmd, stdin=my_file, stdout=PIPE, stderr=STDOUT, universal_newlines=True) | ||
| 22 | return result | ||
| 23 | |||
| 24 | |||
| 16 | def check_returncode(result, expected=[0]): | 25 | def check_returncode(result, expected=[0]): |
| 17 | """Print stdout if `result.returncode` does not match `expected`. | 26 | """Print stdout if `result.returncode` does not match `expected`. |
| 18 | """ | 27 | """ |
| @@ -129,6 +138,12 @@ def test_json2c(): | |||
| 129 | 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' | 138 | 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' |
| 130 | 139 | ||
| 131 | 140 | ||
| 141 | def test_json2c_stdin(): | ||
| 142 | result = check_subcommand_stdin('keyboards/handwired/onekey/keymaps/default_json/keymap.json', 'json2c', '-') | ||
| 143 | check_returncode(result) | ||
| 144 | 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' | ||
| 145 | |||
| 146 | |||
| 132 | def test_info(): | 147 | def test_info(): |
| 133 | result = check_subcommand('info', '-kb', 'handwired/onekey/pytest') | 148 | result = check_subcommand('info', '-kb', 'handwired/onekey/pytest') |
| 134 | check_returncode(result) | 149 | check_returncode(result) |
| @@ -186,6 +201,18 @@ def test_c2json_nocpp(): | |||
| 186 | assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_ENTER"]]}' | 201 | assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_ENTER"]]}' |
| 187 | 202 | ||
| 188 | 203 | ||
| 204 | def test_c2json_stdin(): | ||
| 205 | result = check_subcommand_stdin("keyboards/handwired/onekey/keymaps/default/keymap.c", "c2json", "-kb", "handwired/onekey/pytest", "-km", "default", "-") | ||
| 206 | check_returncode(result) | ||
| 207 | assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "keymap": "default", "layout": "LAYOUT_ortho_1x1", "layers": [["KC_A"]]}' | ||
| 208 | |||
| 209 | |||
| 210 | def test_c2json_nocpp_stdin(): | ||
| 211 | result = check_subcommand_stdin("keyboards/handwired/onekey/keymaps/pytest_nocpp/keymap.c", "c2json", "--no-cpp", "-kb", "handwired/onekey/pytest", "-km", "default", "-") | ||
| 212 | check_returncode(result) | ||
| 213 | assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_ENTER"]]}' | ||
| 214 | |||
| 215 | |||
| 189 | def test_clean(): | 216 | def test_clean(): |
| 190 | result = check_subcommand('clean', '-a') | 217 | result = check_subcommand('clean', '-a') |
| 191 | check_returncode(result) | 218 | check_returncode(result) |
