2020-11-02 08:41:01 +00:00
|
|
|
import platform
|
2021-05-19 22:24:46 +00:00
|
|
|
from subprocess import DEVNULL
|
2020-11-02 08:41:01 +00:00
|
|
|
|
2021-05-19 22:24:46 +00:00
|
|
|
from milc import cli
|
2019-09-22 20:25:33 +00:00
|
|
|
|
2020-11-02 08:41:01 +00:00
|
|
|
is_windows = 'windows' in platform.platform().lower()
|
|
|
|
|
2019-09-22 20:25:33 +00:00
|
|
|
|
|
|
|
def check_subcommand(command, *args):
|
2021-03-08 03:10:03 +00:00
|
|
|
cmd = ['qmk', command, *args]
|
2021-05-19 22:24:46 +00:00
|
|
|
result = cli.run(cmd, stdin=DEVNULL, combined_output=True)
|
2020-05-26 20:05:41 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
2020-12-29 19:34:48 +00:00
|
|
|
def check_subcommand_stdin(file_to_read, command, *args):
|
|
|
|
"""Pipe content of a file to a command and return output.
|
|
|
|
"""
|
2021-02-27 20:00:50 +00:00
|
|
|
with open(file_to_read, encoding='utf-8') as my_file:
|
2021-03-08 03:10:03 +00:00
|
|
|
cmd = ['qmk', command, *args]
|
2021-05-19 22:24:46 +00:00
|
|
|
result = cli.run(cmd, stdin=my_file, combined_output=True)
|
2020-12-29 19:34:48 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
2020-11-16 21:09:32 +00:00
|
|
|
def check_returncode(result, expected=[0]):
|
2020-05-26 20:05:41 +00:00
|
|
|
"""Print stdout if `result.returncode` does not match `expected`.
|
|
|
|
"""
|
2020-11-16 21:09:32 +00:00
|
|
|
if result.returncode not in expected:
|
2020-05-26 20:05:41 +00:00
|
|
|
print('`%s` stdout:' % ' '.join(result.args))
|
|
|
|
print(result.stdout)
|
|
|
|
print('returncode:', result.returncode)
|
2020-11-16 21:09:32 +00:00
|
|
|
assert result.returncode in expected
|
2019-09-22 20:25:33 +00:00
|
|
|
|
|
|
|
|
2021-07-23 20:41:33 +00:00
|
|
|
def test_format_c():
|
|
|
|
result = check_subcommand('format-c', '-n', 'quantum/matrix.c')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
2019-09-22 20:25:33 +00:00
|
|
|
|
|
|
|
|
2021-07-23 20:41:33 +00:00
|
|
|
def test_format_c_all():
|
|
|
|
result = check_subcommand('format-c', '-n', '-a')
|
2021-05-10 18:18:44 +00:00
|
|
|
check_returncode(result, [0, 1])
|
|
|
|
|
|
|
|
|
2019-09-22 20:25:33 +00:00
|
|
|
def test_compile():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('compile', '-kb', 'handwired/pytest/basic', '-km', 'default', '-n')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
2019-09-22 20:25:33 +00:00
|
|
|
|
2019-11-16 07:10:19 +00:00
|
|
|
|
2020-10-07 00:10:19 +00:00
|
|
|
def test_compile_json():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('compile', '-kb', 'handwired/pytest/basic', '-km', 'default_json', '-n')
|
2020-10-07 00:10:19 +00:00
|
|
|
check_returncode(result)
|
|
|
|
|
|
|
|
|
2019-10-05 06:38:34 +00:00
|
|
|
def test_flash():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('flash', '-kb', 'handwired/pytest/basic', '-km', 'default', '-n')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
|
|
|
|
|
|
|
|
|
|
|
def test_flash_bootloaders():
|
|
|
|
result = check_subcommand('flash', '-b')
|
2020-11-16 21:09:32 +00:00
|
|
|
check_returncode(result, [1])
|
2019-09-22 20:25:33 +00:00
|
|
|
|
2019-11-16 07:10:19 +00:00
|
|
|
|
2019-11-13 04:55:41 +00:00
|
|
|
def test_kle2json():
|
2020-10-06 23:46:10 +00:00
|
|
|
result = check_subcommand('kle2json', 'lib/python/qmk/tests/kle.txt', '-f')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
2020-10-06 23:46:10 +00:00
|
|
|
assert 'Wrote out' in result.stdout
|
2019-09-22 20:25:33 +00:00
|
|
|
|
2019-11-13 05:24:56 +00:00
|
|
|
|
2019-09-22 20:25:33 +00:00
|
|
|
def test_doctor():
|
2020-02-08 12:43:55 +00:00
|
|
|
result = check_subcommand('doctor', '-n')
|
2020-11-16 21:09:32 +00:00
|
|
|
check_returncode(result, [0, 1])
|
2020-05-26 20:05:41 +00:00
|
|
|
assert 'QMK Doctor is checking your environment.' in result.stdout
|
|
|
|
assert 'QMK is ready to go' in result.stdout
|
2019-09-22 20:25:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_hello():
|
|
|
|
result = check_subcommand('hello')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
|
|
|
assert 'Hello,' in result.stdout
|
2019-09-22 20:25:33 +00:00
|
|
|
|
|
|
|
|
2021-07-23 20:41:33 +00:00
|
|
|
def test_format_python():
|
|
|
|
result = check_subcommand('format-python', '--dry-run')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
2021-08-29 23:50:22 +00:00
|
|
|
assert 'Python code in `lib/python` is correctly formatted.' in result.stdout
|
2020-05-26 20:05:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_keyboards():
|
|
|
|
result = check_subcommand('list-keyboards')
|
|
|
|
check_returncode(result)
|
|
|
|
# check to see if a known keyboard is returned
|
2021-01-05 00:52:31 +00:00
|
|
|
# this will fail if handwired/pytest/basic is removed
|
|
|
|
assert 'handwired/pytest/basic' in result.stdout
|
2019-10-07 18:32:30 +00:00
|
|
|
|
|
|
|
|
2020-05-16 20:47:07 +00:00
|
|
|
def test_list_keymaps():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('list-keymaps', '-kb', 'handwired/pytest/basic')
|
2020-11-16 21:09:32 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert 'default' and 'default_json' in result.stdout
|
2019-10-13 17:16:19 +00:00
|
|
|
|
2020-01-07 20:54:21 +00:00
|
|
|
|
2020-05-16 20:47:07 +00:00
|
|
|
def test_list_keymaps_long():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('list-keymaps', '--keyboard', 'handwired/pytest/basic')
|
2020-11-16 21:09:32 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert 'default' and 'default_json' in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_keymaps_community():
|
|
|
|
result = check_subcommand('list-keymaps', '--keyboard', 'handwired/pytest/has_community')
|
|
|
|
check_returncode(result)
|
|
|
|
assert 'test' in result.stdout
|
2020-05-16 20:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_keymaps_kb_only():
|
|
|
|
result = check_subcommand('list-keymaps', '-kb', 'niu_mini')
|
2020-11-16 21:09:32 +00:00
|
|
|
check_returncode(result)
|
2020-05-16 20:47:07 +00:00
|
|
|
assert 'default' and 'via' in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_keymaps_vendor_kb():
|
|
|
|
result = check_subcommand('list-keymaps', '-kb', 'ai03/lunar')
|
2020-11-16 21:09:32 +00:00
|
|
|
check_returncode(result)
|
2020-05-16 20:47:07 +00:00
|
|
|
assert 'default' and 'via' in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_keymaps_vendor_kb_rev():
|
|
|
|
result = check_subcommand('list-keymaps', '-kb', 'kbdfans/kbd67/mkiirgb/v2')
|
2020-11-16 21:09:32 +00:00
|
|
|
check_returncode(result)
|
2020-05-16 20:47:07 +00:00
|
|
|
assert 'default' and 'via' in result.stdout
|
2020-01-07 20:54:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_keymaps_no_keyboard_found():
|
2020-05-16 20:47:07 +00:00
|
|
|
result = check_subcommand('list-keymaps', '-kb', 'asdfghjkl')
|
2021-03-24 16:26:38 +00:00
|
|
|
check_returncode(result, [2])
|
|
|
|
assert 'invalid keyboard_folder value' in result.stdout
|
2020-05-26 15:43:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_json2c():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('json2c', 'keyboards/handwired/pytest/has_template/keymaps/default_json/keymap.json')
|
2020-11-16 21:09:32 +00:00
|
|
|
check_returncode(result)
|
2020-06-18 18:37:47 +00:00
|
|
|
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'
|
2020-05-26 20:05:41 +00:00
|
|
|
|
|
|
|
|
2020-12-29 19:34:48 +00:00
|
|
|
def test_json2c_stdin():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand_stdin('keyboards/handwired/pytest/has_template/keymaps/default_json/keymap.json', 'json2c', '-')
|
2020-12-29 19:34:48 +00:00
|
|
|
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'
|
|
|
|
|
|
|
|
|
2020-05-26 20:05:41 +00:00
|
|
|
def test_info():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('info', '-kb', 'handwired/pytest/basic')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert 'Keyboard Name: handwired/pytest/basic' in result.stdout
|
|
|
|
assert 'Processor: atmega32u4' in result.stdout
|
2020-05-26 20:05:41 +00:00
|
|
|
assert 'Layout:' not in result.stdout
|
|
|
|
assert 'k0' not in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_info_keyboard_render():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('info', '-kb', 'handwired/pytest/basic', '-l')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert 'Keyboard Name: handwired/pytest/basic' in result.stdout
|
|
|
|
assert 'Processor: atmega32u4' in result.stdout
|
2020-06-18 18:37:47 +00:00
|
|
|
assert 'Layouts:' in result.stdout
|
2020-05-26 20:05:41 +00:00
|
|
|
assert 'k0' in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_info_keymap_render():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('info', '-kb', 'handwired/pytest/basic', '-km', 'default_json')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert 'Keyboard Name: handwired/pytest/basic' in result.stdout
|
|
|
|
assert 'Processor: atmega32u4' in result.stdout
|
2020-11-02 08:41:01 +00:00
|
|
|
|
|
|
|
if is_windows:
|
|
|
|
assert '|A |' in result.stdout
|
|
|
|
else:
|
|
|
|
assert '│A │' in result.stdout
|
2020-05-26 20:05:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_info_matrix_render():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand('info', '-kb', 'handwired/pytest/basic', '-m')
|
2020-05-26 20:05:41 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert 'Keyboard Name: handwired/pytest/basic' in result.stdout
|
|
|
|
assert 'Processor: atmega32u4' in result.stdout
|
2020-06-18 18:37:47 +00:00
|
|
|
assert 'LAYOUT_ortho_1x1' in result.stdout
|
2020-11-02 08:41:01 +00:00
|
|
|
|
|
|
|
if is_windows:
|
|
|
|
assert '|0A|' in result.stdout
|
|
|
|
else:
|
|
|
|
assert '│0A│' in result.stdout
|
|
|
|
|
2020-06-18 18:37:47 +00:00
|
|
|
assert 'Matrix for "LAYOUT_ortho_1x1"' in result.stdout
|
2020-10-07 00:10:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_c2json():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand("c2json", "-kb", "handwired/pytest/has_template", "-km", "default", "keyboards/handwired/pytest/has_template/keymaps/default/keymap.c")
|
2020-10-07 00:10:19 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert result.stdout.strip() == '{"keyboard": "handwired/pytest/has_template", "documentation": "This file is a keymap.json file for handwired/pytest/has_template", "keymap": "default", "layout": "LAYOUT_ortho_1x1", "layers": [["KC_A"]]}'
|
2020-10-07 00:10:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_c2json_nocpp():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand("c2json", "--no-cpp", "-kb", "handwired/pytest/has_template", "-km", "default", "keyboards/handwired/pytest/has_template/keymaps/nocpp/keymap.c")
|
2020-10-07 00:10:19 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert result.stdout.strip() == '{"keyboard": "handwired/pytest/has_template", "documentation": "This file is a keymap.json file for handwired/pytest/has_template", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_ENTER"]]}'
|
2020-11-04 19:18:47 +00:00
|
|
|
|
|
|
|
|
2020-12-29 19:34:48 +00:00
|
|
|
def test_c2json_stdin():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand_stdin("keyboards/handwired/pytest/has_template/keymaps/default/keymap.c", "c2json", "-kb", "handwired/pytest/has_template", "-km", "default", "-")
|
2020-12-29 19:34:48 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert result.stdout.strip() == '{"keyboard": "handwired/pytest/has_template", "documentation": "This file is a keymap.json file for handwired/pytest/has_template", "keymap": "default", "layout": "LAYOUT_ortho_1x1", "layers": [["KC_A"]]}'
|
2020-12-29 19:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_c2json_nocpp_stdin():
|
2021-01-05 00:52:31 +00:00
|
|
|
result = check_subcommand_stdin("keyboards/handwired/pytest/has_template/keymaps/nocpp/keymap.c", "c2json", "--no-cpp", "-kb", "handwired/pytest/has_template", "-km", "default", "-")
|
2020-12-29 19:34:48 +00:00
|
|
|
check_returncode(result)
|
2021-01-05 00:52:31 +00:00
|
|
|
assert result.stdout.strip() == '{"keyboard": "handwired/pytest/has_template", "documentation": "This file is a keymap.json file for handwired/pytest/has_template", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_ENTER"]]}'
|
2020-12-29 19:34:48 +00:00
|
|
|
|
|
|
|
|
2020-11-04 19:18:47 +00:00
|
|
|
def test_clean():
|
|
|
|
result = check_subcommand('clean', '-a')
|
|
|
|
check_returncode(result)
|
|
|
|
assert result.stdout.count('done') == 2
|
2020-12-16 03:24:42 +00:00
|
|
|
|
|
|
|
|
2021-05-10 18:18:44 +00:00
|
|
|
def test_generate_api():
|
|
|
|
result = check_subcommand('generate-api', '--dry-run')
|
|
|
|
check_returncode(result)
|
|
|
|
|
|
|
|
|
2020-12-16 03:24:42 +00:00
|
|
|
def test_generate_rgb_breathe_table():
|
|
|
|
result = check_subcommand("generate-rgb-breathe-table", "-c", "1.2", "-m", "127")
|
|
|
|
check_returncode(result)
|
|
|
|
assert 'Breathing center: 1.2' in result.stdout
|
|
|
|
assert 'Breathing max: 127' in result.stdout
|
2021-01-31 20:46:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_generate_config_h():
|
|
|
|
result = check_subcommand('generate-config-h', '-kb', 'handwired/pytest/basic')
|
|
|
|
check_returncode(result)
|
|
|
|
assert '# define DEVICE_VER 0x0001' in result.stdout
|
|
|
|
assert '# define DESCRIPTION handwired/pytest/basic' in result.stdout
|
|
|
|
assert '# define DIODE_DIRECTION COL2ROW' in result.stdout
|
|
|
|
assert '# define MANUFACTURER none' in result.stdout
|
|
|
|
assert '# define PRODUCT handwired/pytest/basic' in result.stdout
|
|
|
|
assert '# define PRODUCT_ID 0x6465' in result.stdout
|
|
|
|
assert '# define VENDOR_ID 0xFEED' in result.stdout
|
|
|
|
assert '# define MATRIX_COLS 1' in result.stdout
|
|
|
|
assert '# define MATRIX_COL_PINS { F4 }' in result.stdout
|
|
|
|
assert '# define MATRIX_ROWS 1' in result.stdout
|
|
|
|
assert '# define MATRIX_ROW_PINS { F5 }' in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_generate_rules_mk():
|
|
|
|
result = check_subcommand('generate-rules-mk', '-kb', 'handwired/pytest/basic')
|
|
|
|
check_returncode(result)
|
|
|
|
assert 'BOOTLOADER ?= atmel-dfu' in result.stdout
|
|
|
|
assert 'MCU ?= atmega32u4' in result.stdout
|
|
|
|
|
|
|
|
|
2021-06-26 16:29:02 +00:00
|
|
|
def test_generate_version_h():
|
|
|
|
result = check_subcommand('generate-version-h')
|
|
|
|
check_returncode(result)
|
|
|
|
assert '#define QMK_VERSION' in result.stdout
|
|
|
|
|
|
|
|
|
2021-01-31 20:46:00 +00:00
|
|
|
def test_generate_layouts():
|
|
|
|
result = check_subcommand('generate-layouts', '-kb', 'handwired/pytest/basic')
|
|
|
|
check_returncode(result)
|
|
|
|
assert '#define LAYOUT_custom(k0A) {' in result.stdout
|
2021-03-25 11:38:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_format_json_keyboard():
|
|
|
|
result = check_subcommand('format-json', '--format', 'keyboard', 'lib/python/qmk/tests/minimal_info.json')
|
|
|
|
check_returncode(result)
|
2021-07-30 05:37:18 +00:00
|
|
|
assert result.stdout == '{\n "keyboard_name": "tester",\n "maintainer": "qmk",\n "layouts": {\n "LAYOUT": {\n "layout": [\n { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 }\n ]\n }\n }\n}\n'
|
2021-03-25 11:38:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2021-07-30 05:37:18 +00:00
|
|
|
assert result.stdout == '{\n "keyboard_name": "tester",\n "maintainer": "qmk",\n "layouts": {\n "LAYOUT": {\n "layout": [\n { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 }\n ]\n }\n }\n}\n'
|
2021-03-25 11:38:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
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'
|