diff options
author | QMK Bot <hello@qmk.fm> | 2020-12-29 19:35:24 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2020-12-29 19:35:24 +0000 |
commit | 7b7763469bb8cc0091d02f1f5a5e77d70d7666cd (patch) | |
tree | 8480a7cb9573d22d7ecbcd28c9d0cb49b5ac803b /lib/python/qmk/tests | |
parent | 9748b6b847d9c184db6efd660ee8b343a4bf7485 (diff) | |
parent | 221d8fd8669ff528bfedd01f41486f5298d960e1 (diff) |
Merge remote-tracking branch 'origin/master' into develop
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 08e80f2c95..efd9f6cf6a 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() def check_subcommand(command, *args): - cmd = ['bin/qmk', command] + list(args) + cmd = ['bin/qmk', command, *args] result = run(cmd, stdout=PIPE, stderr=STDOUT, universal_newlines=True) return result +def check_subcommand_stdin(file_to_read, command, *args): + """Pipe content of a file to a command and return output. + """ + with open(file_to_read) as my_file: + cmd = ['bin/qmk', command, *args] + result = run(cmd, stdin=my_file, stdout=PIPE, stderr=STDOUT, universal_newlines=True) + return result + + def check_returncode(result, expected=[0]): """Print stdout if `result.returncode` does not match `expected`. """ @@ -129,6 +138,12 @@ def test_json2c(): 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_stdin(): + result = check_subcommand_stdin('keyboards/handwired/onekey/keymaps/default_json/keymap.json', 'json2c', '-') + check_returncode(result) + 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_info(): result = check_subcommand('info', '-kb', 'handwired/onekey/pytest') check_returncode(result) @@ -186,6 +201,18 @@ def test_c2json_nocpp(): 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"]]}' +def test_c2json_stdin(): + result = check_subcommand_stdin("keyboards/handwired/onekey/keymaps/default/keymap.c", "c2json", "-kb", "handwired/onekey/pytest", "-km", "default", "-") + check_returncode(result) + 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"]]}' + + +def test_c2json_nocpp_stdin(): + result = check_subcommand_stdin("keyboards/handwired/onekey/keymaps/pytest_nocpp/keymap.c", "c2json", "--no-cpp", "-kb", "handwired/onekey/pytest", "-km", "default", "-") + check_returncode(result) + 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"]]}' + + def test_clean(): result = check_subcommand('clean', '-a') check_returncode(result) |