diff options
| author | Zach White <skullydazed@users.noreply.github.com> | 2020-05-26 13:05:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-26 13:05:41 -0700 |
| commit | 751316c34465ea77e066c3052729b207f3d62e0c (patch) | |
| tree | cb99656b93c156757e2fd7c84fe716f9c300ca89 /lib/python/qmk/tests | |
| parent | 5d3bf8a050f3c0beb1f91147dc1ab54de36cbb05 (diff) | |
| download | qmk_firmware-751316c34465ea77e066c3052729b207f3d62e0c.tar.gz qmk_firmware-751316c34465ea77e066c3052729b207f3d62e0c.zip | |
[CLI] Add a subcommand for getting information about a keyboard (#8666)
You can now use `qmk info` to get information about keyboards and keymaps.
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
Diffstat (limited to 'lib/python/qmk/tests')
| -rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 104 |
1 files changed, 83 insertions, 21 deletions
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index 768929de1..dce270de8 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py | |||
| @@ -4,89 +4,151 @@ from qmk.commands import run | |||
| 4 | 4 | ||
| 5 | def check_subcommand(command, *args): | 5 | def check_subcommand(command, *args): |
| 6 | cmd = ['bin/qmk', command] + list(args) | 6 | cmd = ['bin/qmk', command] + list(args) |
| 7 | return run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | 7 | result = run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) |
| 8 | return result | ||
| 9 | |||
| 10 | |||
| 11 | def check_returncode(result, expected=0): | ||
| 12 | """Print stdout if `result.returncode` does not match `expected`. | ||
| 13 | """ | ||
| 14 | if result.returncode != expected: | ||
| 15 | print('`%s` stdout:' % ' '.join(result.args)) | ||
| 16 | print(result.stdout) | ||
| 17 | print('returncode:', result.returncode) | ||
| 18 | assert result.returncode == expected | ||
| 8 | 19 | ||
| 9 | 20 | ||
| 10 | def test_cformat(): | 21 | def test_cformat(): |
| 11 | result = check_subcommand('cformat', 'quantum/matrix.c') | 22 | result = check_subcommand('cformat', 'quantum/matrix.c') |
| 12 | assert result.returncode == 0 | 23 | check_returncode(result) |
| 13 | 24 | ||
| 14 | 25 | ||
| 15 | def test_compile(): | 26 | def test_compile(): |
| 16 | assert check_subcommand('compile', '-kb', 'handwired/onekey/pytest', '-km', 'default').returncode == 0 | 27 | result = check_subcommand('compile', '-kb', 'handwired/onekey/pytest', '-km', 'default', '-n') |
| 28 | check_returncode(result) | ||
| 17 | 29 | ||
| 18 | 30 | ||
| 19 | def test_flash(): | 31 | def test_flash(): |
| 20 | assert check_subcommand('flash', '-b').returncode == 1 | 32 | result = check_subcommand('flash', '-kb', 'handwired/onekey/pytest', '-km', 'default', '-n') |
| 21 | assert check_subcommand('flash').returncode == 1 | 33 | check_returncode(result) |
| 34 | |||
| 35 | |||
| 36 | def test_flash_bootloaders(): | ||
| 37 | result = check_subcommand('flash', '-b') | ||
| 38 | check_returncode(result, 1) | ||
| 22 | 39 | ||
| 23 | 40 | ||
| 24 | def test_config(): | 41 | def test_config(): |
| 25 | result = check_subcommand('config') | 42 | result = check_subcommand('config') |
| 26 | assert result.returncode == 0 | 43 | check_returncode(result) |
| 27 | assert 'general.color' in result.stdout | 44 | assert 'general.color' in result.stdout |
| 28 | 45 | ||
| 29 | 46 | ||
| 30 | def test_kle2json(): | 47 | def test_kle2json(): |
| 31 | assert check_subcommand('kle2json', 'kle.txt', '-f').returncode == 0 | 48 | result = check_subcommand('kle2json', 'kle.txt', '-f') |
| 49 | check_returncode(result) | ||
| 32 | 50 | ||
| 33 | 51 | ||
| 34 | def test_doctor(): | 52 | def test_doctor(): |
| 35 | result = check_subcommand('doctor', '-n') | 53 | result = check_subcommand('doctor', '-n') |
| 36 | assert result.returncode == 0 | 54 | check_returncode(result) |
| 37 | assert 'QMK Doctor is checking your environment.' in result.stderr | 55 | assert 'QMK Doctor is checking your environment.' in result.stdout |
| 38 | assert 'QMK is ready to go' in result.stderr | 56 | assert 'QMK is ready to go' in result.stdout |
| 39 | 57 | ||
| 40 | 58 | ||
| 41 | def test_hello(): | 59 | def test_hello(): |
| 42 | result = check_subcommand('hello') | 60 | result = check_subcommand('hello') |
| 43 | assert result.returncode == 0 | 61 | check_returncode(result) |
| 44 | assert 'Hello,' in result.stderr | 62 | assert 'Hello,' in result.stdout |
| 45 | 63 | ||
| 46 | 64 | ||
| 47 | def test_pyformat(): | 65 | def test_pyformat(): |
| 48 | result = check_subcommand('pyformat') | 66 | result = check_subcommand('pyformat') |
| 49 | assert result.returncode == 0 | 67 | check_returncode(result) |
| 50 | assert 'Successfully formatted the python code' in result.stderr | 68 | assert 'Successfully formatted the python code' in result.stdout |
| 69 | |||
| 70 | |||
| 71 | def test_list_keyboards(): | ||
| 72 | result = check_subcommand('list-keyboards') | ||
| 73 | check_returncode(result) | ||
| 74 | # check to see if a known keyboard is returned | ||
| 75 | # this will fail if handwired/onekey/pytest is removed | ||
| 76 | assert 'handwired/onekey/pytest' in result.stdout | ||
| 51 | 77 | ||
| 52 | 78 | ||
| 53 | def test_list_keymaps(): | 79 | def test_list_keymaps(): |
| 54 | result = check_subcommand('list-keymaps', '-kb', 'handwired/onekey/pytest') | 80 | result = check_subcommand('list-keymaps', '-kb', 'handwired/onekey/pytest') |
| 55 | assert result.returncode == 0 | 81 | check_returncode(result, 0) |
| 56 | assert 'default' and 'test' in result.stdout | 82 | assert 'default' and 'test' in result.stdout |
| 57 | 83 | ||
| 58 | 84 | ||
| 59 | def test_list_keymaps_long(): | 85 | def test_list_keymaps_long(): |
| 60 | result = check_subcommand('list-keymaps', '--keyboard', 'handwired/onekey/pytest') | 86 | result = check_subcommand('list-keymaps', '--keyboard', 'handwired/onekey/pytest') |
| 61 | assert result.returncode == 0 | 87 | check_returncode(result, 0) |
| 62 | assert 'default' and 'test' in result.stdout | 88 | assert 'default' and 'test' in result.stdout |
| 63 | 89 | ||
| 64 | 90 | ||
| 65 | def test_list_keymaps_kb_only(): | 91 | def test_list_keymaps_kb_only(): |
| 66 | result = check_subcommand('list-keymaps', '-kb', 'niu_mini') | 92 | result = check_subcommand('list-keymaps', '-kb', 'niu_mini') |
| 67 | assert result.returncode == 0 | 93 | check_returncode(result, 0) |
| 68 | assert 'default' and 'via' in result.stdout | 94 | assert 'default' and 'via' in result.stdout |
| 69 | 95 | ||
| 70 | 96 | ||
| 71 | def test_list_keymaps_vendor_kb(): | 97 | def test_list_keymaps_vendor_kb(): |
| 72 | result = check_subcommand('list-keymaps', '-kb', 'ai03/lunar') | 98 | result = check_subcommand('list-keymaps', '-kb', 'ai03/lunar') |
| 73 | assert result.returncode == 0 | 99 | check_returncode(result, 0) |
| 74 | assert 'default' and 'via' in result.stdout | 100 | assert 'default' and 'via' in result.stdout |
| 75 | 101 | ||
| 76 | 102 | ||
| 77 | def test_list_keymaps_vendor_kb_rev(): | 103 | def test_list_keymaps_vendor_kb_rev(): |
| 78 | result = check_subcommand('list-keymaps', '-kb', 'kbdfans/kbd67/mkiirgb/v2') | 104 | result = check_subcommand('list-keymaps', '-kb', 'kbdfans/kbd67/mkiirgb/v2') |
| 79 | assert result.returncode == 0 | 105 | check_returncode(result, 0) |
| 80 | assert 'default' and 'via' in result.stdout | 106 | assert 'default' and 'via' in result.stdout |
| 81 | 107 | ||
| 82 | 108 | ||
| 83 | def test_list_keymaps_no_keyboard_found(): | 109 | def test_list_keymaps_no_keyboard_found(): |
| 84 | result = check_subcommand('list-keymaps', '-kb', 'asdfghjkl') | 110 | result = check_subcommand('list-keymaps', '-kb', 'asdfghjkl') |
| 85 | assert result.returncode == 0 | 111 | check_returncode(result, 1) |
| 86 | assert 'does not exist' in result.stdout | 112 | assert 'does not exist' in result.stdout |
| 87 | 113 | ||
| 88 | 114 | ||
| 89 | def test_json2c(): | 115 | def test_json2c(): |
| 90 | result = check_subcommand('json2c', 'keyboards/handwired/onekey/keymaps/default_json/keymap.json') | 116 | result = check_subcommand('json2c', 'keyboards/handwired/onekey/keymaps/default_json/keymap.json') |
| 91 | assert result.returncode == 0 | 117 | check_returncode(result, 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' | 118 | assert result.stdout == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT(KC_A)};\n\n' |
| 119 | |||
| 120 | |||
| 121 | def test_info(): | ||
| 122 | result = check_subcommand('info', '-kb', 'handwired/onekey/pytest') | ||
| 123 | check_returncode(result) | ||
| 124 | assert 'Keyboard Name: handwired/onekey/pytest' in result.stdout | ||
| 125 | assert 'Processor: STM32F303' in result.stdout | ||
| 126 | assert 'Layout:' not in result.stdout | ||
| 127 | assert 'k0' not in result.stdout | ||
| 128 | |||
| 129 | |||
| 130 | def test_info_keyboard_render(): | ||
| 131 | result = check_subcommand('info', '-kb', 'handwired/onekey/pytest', '-l') | ||
| 132 | check_returncode(result) | ||
| 133 | assert 'Keyboard Name: handwired/onekey/pytest' in result.stdout | ||
| 134 | assert 'Processor: STM32F303' in result.stdout | ||
| 135 | assert 'Layout:' in result.stdout | ||
| 136 | assert 'k0' in result.stdout | ||
| 137 | |||
| 138 | |||
| 139 | def test_info_keymap_render(): | ||
| 140 | result = check_subcommand('info', '-kb', 'handwired/onekey/pytest', '-km', 'default_json') | ||
| 141 | check_returncode(result) | ||
| 142 | assert 'Keyboard Name: handwired/onekey/pytest' in result.stdout | ||
| 143 | assert 'Processor: STM32F303' in result.stdout | ||
| 144 | assert '│A │' in result.stdout | ||
| 145 | |||
| 146 | |||
| 147 | def test_info_matrix_render(): | ||
| 148 | result = check_subcommand('info', '-kb', 'handwired/onekey/pytest', '-m') | ||
| 149 | check_returncode(result) | ||
| 150 | assert 'Keyboard Name: handwired/onekey/pytest' in result.stdout | ||
| 151 | assert 'Processor: STM32F303' in result.stdout | ||
| 152 | assert 'LAYOUT' in result.stdout | ||
| 153 | assert '│0A│' in result.stdout | ||
| 154 | assert 'Matrix for "LAYOUT"' in result.stdout | ||
