You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
12 KiB

Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Apply suggestions from code review Co-Authored-By: Noah Frederick <code@noahfrederick.com> * Remove pip3 from the test runner
4 years ago
  1. import platform
  2. from subprocess import DEVNULL
  3. from milc import cli
  4. is_windows = 'windows' in platform.platform().lower()
  5. def check_subcommand(command, *args):
  6. cmd = ['qmk', command, *args]
  7. result = cli.run(cmd, stdin=DEVNULL, combined_output=True)
  8. return result
  9. def check_subcommand_stdin(file_to_read, command, *args):
  10. """Pipe content of a file to a command and return output.
  11. """
  12. with open(file_to_read, encoding='utf-8') as my_file:
  13. cmd = ['qmk', command, *args]
  14. result = cli.run(cmd, stdin=my_file, combined_output=True)
  15. return result
  16. def check_returncode(result, expected=[0]):
  17. """Print stdout if `result.returncode` does not match `expected`.
  18. """
  19. if result.returncode not in expected:
  20. print('`%s` stdout:' % ' '.join(result.args))
  21. print(result.stdout)
  22. print('returncode:', result.returncode)
  23. assert result.returncode in expected
  24. def test_format_c():
  25. result = check_subcommand('format-c', '-n', 'quantum/matrix.c')
  26. check_returncode(result)
  27. def test_format_c_all():
  28. result = check_subcommand('format-c', '-n', '-a')
  29. check_returncode(result, [0, 1])
  30. def test_compile():
  31. result = check_subcommand('compile', '-kb', 'handwired/pytest/basic', '-km', 'default', '-n')
  32. check_returncode(result)
  33. def test_compile_json():
  34. result = check_subcommand('compile', '-kb', 'handwired/pytest/basic', '-km', 'default_json', '-n')
  35. check_returncode(result)
  36. def test_flash():
  37. result = check_subcommand('flash', '-kb', 'handwired/pytest/basic', '-km', 'default', '-n')
  38. check_returncode(result)
  39. def test_flash_bootloaders():
  40. result = check_subcommand('flash', '-b')
  41. check_returncode(result, [1])
  42. def test_kle2json():
  43. result = check_subcommand('kle2json', 'lib/python/qmk/tests/kle.txt', '-f')
  44. check_returncode(result)
  45. assert 'Wrote out' in result.stdout
  46. def test_doctor():
  47. result = check_subcommand('doctor', '-n')
  48. check_returncode(result, [0, 1])
  49. assert 'QMK Doctor is checking your environment.' in result.stdout
  50. assert 'QMK is ready to go' in result.stdout
  51. def test_hello():
  52. result = check_subcommand('hello')
  53. check_returncode(result)
  54. assert 'Hello,' in result.stdout
  55. def test_format_python():
  56. result = check_subcommand('format-python', '-n', '-a')
  57. check_returncode(result)
  58. assert 'Successfully formatted the python code.' in result.stdout
  59. def test_list_keyboards():
  60. result = check_subcommand('list-keyboards')
  61. check_returncode(result)
  62. # check to see if a known keyboard is returned
  63. # this will fail if handwired/pytest/basic is removed
  64. assert 'handwired/pytest/basic' in result.stdout
  65. def test_list_keymaps():
  66. result = check_subcommand('list-keymaps', '-kb', 'handwired/pytest/basic')
  67. check_returncode(result)
  68. assert 'default' and 'default_json' in result.stdout
  69. def test_list_keymaps_long():
  70. result = check_subcommand('list-keymaps', '--keyboard', 'handwired/pytest/basic')
  71. check_returncode(result)
  72. assert 'default' and 'default_json' in result.stdout
  73. def test_list_keymaps_community():
  74. result = check_subcommand('list-keymaps', '--keyboard', 'handwired/pytest/has_community')
  75. check_returncode(result)
  76. assert 'test' in result.stdout
  77. def test_list_keymaps_kb_only():
  78. result = check_subcommand('list-keymaps', '-kb', 'niu_mini')
  79. check_returncode(result)
  80. assert 'default' and 'via' in result.stdout
  81. def test_list_keymaps_vendor_kb():
  82. result = check_subcommand('list-keymaps', '-kb', 'ai03/lunar')
  83. check_returncode(result)
  84. assert 'default' and 'via' in result.stdout
  85. def test_list_keymaps_vendor_kb_rev():
  86. result = check_subcommand('list-keymaps', '-kb', 'kbdfans/kbd67/mkiirgb/v2')
  87. check_returncode(result)
  88. assert 'default' and 'via' in result.stdout
  89. def test_list_keymaps_no_keyboard_found():
  90. result = check_subcommand('list-keymaps', '-kb', 'asdfghjkl')
  91. check_returncode(result, [2])
  92. assert 'invalid keyboard_folder value' in result.stdout
  93. def test_json2c():
  94. result = check_subcommand('json2c', 'keyboards/handwired/pytest/has_template/keymaps/default_json/keymap.json')
  95. check_returncode(result)
  96. 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'
  97. def test_json2c_macros():
  98. result = check_subcommand("json2c", 'keyboards/handwired/pytest/macro/keymaps/default/keymap.json')
  99. check_returncode(result)
  100. assert 'LAYOUT_ortho_1x1(MACRO_0)' in result.stdout
  101. assert 'case MACRO_0:' in result.stdout
  102. assert 'SEND_STRING("Hello, World!"SS_TAP(X_ENTER));' in result.stdout
  103. def test_json2c_stdin():
  104. result = check_subcommand_stdin('keyboards/handwired/pytest/has_template/keymaps/default_json/keymap.json', 'json2c', '-')
  105. check_returncode(result)
  106. 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'
  107. def test_info():
  108. result = check_subcommand('info', '-kb', 'handwired/pytest/basic')
  109. check_returncode(result)
  110. assert 'Keyboard Name: pytest' in result.stdout
  111. assert 'Processor: atmega32u4' in result.stdout
  112. assert 'Layout:' not in result.stdout
  113. assert 'k0' not in result.stdout
  114. def test_info_keyboard_render():
  115. result = check_subcommand('info', '-kb', 'handwired/pytest/basic', '-l')
  116. check_returncode(result)
  117. assert 'Keyboard Name: pytest' in result.stdout
  118. assert 'Processor: atmega32u4' in result.stdout
  119. assert 'Layouts:' in result.stdout
  120. assert 'k0' in result.stdout
  121. def test_info_keymap_render():
  122. result = check_subcommand('info', '-kb', 'handwired/pytest/basic', '-km', 'default_json')
  123. check_returncode(result)
  124. assert 'Keyboard Name: pytest' in result.stdout
  125. assert 'Processor: atmega32u4' in result.stdout
  126. if is_windows:
  127. assert '|A |' in result.stdout
  128. else:
  129. assert '│A │' in result.stdout
  130. def test_info_matrix_render():
  131. result = check_subcommand('info', '-kb', 'handwired/pytest/basic', '-m')
  132. check_returncode(result)
  133. assert 'Keyboard Name: pytest' in result.stdout
  134. assert 'Processor: atmega32u4' in result.stdout
  135. assert 'LAYOUT_ortho_1x1' in result.stdout
  136. if is_windows:
  137. assert '|0A|' in result.stdout
  138. else:
  139. assert '│0A│' in result.stdout
  140. assert 'Matrix for "LAYOUT_ortho_1x1"' in result.stdout
  141. def test_c2json():
  142. result = check_subcommand("c2json", "-kb", "handwired/pytest/has_template", "-km", "default", "keyboards/handwired/pytest/has_template/keymaps/default/keymap.c")
  143. check_returncode(result)
  144. 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"]]}'
  145. def test_c2json_nocpp():
  146. result = check_subcommand("c2json", "--no-cpp", "-kb", "handwired/pytest/has_template", "-km", "default", "keyboards/handwired/pytest/has_template/keymaps/nocpp/keymap.c")
  147. check_returncode(result)
  148. 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"]]}'
  149. def test_c2json_stdin():
  150. result = check_subcommand_stdin("keyboards/handwired/pytest/has_template/keymaps/default/keymap.c", "c2json", "-kb", "handwired/pytest/has_template", "-km", "default", "-")
  151. check_returncode(result)
  152. 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"]]}'
  153. def test_c2json_nocpp_stdin():
  154. result = check_subcommand_stdin("keyboards/handwired/pytest/has_template/keymaps/nocpp/keymap.c", "c2json", "--no-cpp", "-kb", "handwired/pytest/has_template", "-km", "default", "-")
  155. check_returncode(result)
  156. 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"]]}'
  157. def test_clean():
  158. result = check_subcommand('clean', '-a')
  159. check_returncode(result)
  160. assert result.stdout.count('done') == 2
  161. def test_generate_api():
  162. result = check_subcommand('generate-api', '--dry-run')
  163. check_returncode(result)
  164. def test_generate_rgb_breathe_table():
  165. result = check_subcommand("generate-rgb-breathe-table", "-c", "1.2", "-m", "127")
  166. check_returncode(result)
  167. assert 'Breathing center: 1.2' in result.stdout
  168. assert 'Breathing max: 127' in result.stdout
  169. def test_generate_config_h():
  170. result = check_subcommand('generate-config-h', '-kb', 'handwired/pytest/basic')
  171. check_returncode(result)
  172. assert '# define DEVICE_VER 0x0001' in result.stdout
  173. assert '# define DESCRIPTION handwired/pytest/basic' in result.stdout
  174. assert '# define DIODE_DIRECTION COL2ROW' in result.stdout
  175. assert '# define MANUFACTURER none' in result.stdout
  176. assert '# define PRODUCT pytest' in result.stdout
  177. assert '# define PRODUCT_ID 0x6465' in result.stdout
  178. assert '# define VENDOR_ID 0xFEED' in result.stdout
  179. assert '# define MATRIX_COLS 1' in result.stdout
  180. assert '# define MATRIX_COL_PINS { F4 }' in result.stdout
  181. assert '# define MATRIX_ROWS 1' in result.stdout
  182. assert '# define MATRIX_ROW_PINS { F5 }' in result.stdout
  183. def test_generate_rules_mk():
  184. result = check_subcommand('generate-rules-mk', '-kb', 'handwired/pytest/basic')
  185. check_returncode(result)
  186. assert 'BOOTLOADER ?= atmel-dfu' in result.stdout
  187. assert 'MCU ?= atmega32u4' in result.stdout
  188. def test_generate_version_h():
  189. result = check_subcommand('generate-version-h')
  190. check_returncode(result)
  191. assert '#define QMK_VERSION' in result.stdout
  192. def test_generate_layouts():
  193. result = check_subcommand('generate-layouts', '-kb', 'handwired/pytest/basic')
  194. check_returncode(result)
  195. assert '#define LAYOUT_custom(k0A) {' in result.stdout
  196. def test_format_json_keyboard():
  197. result = check_subcommand('format-json', '--format', 'keyboard', 'lib/python/qmk/tests/minimal_info.json')
  198. check_returncode(result)
  199. 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'
  200. def test_format_json_keymap():
  201. result = check_subcommand('format-json', '--format', 'keymap', 'lib/python/qmk/tests/minimal_keymap.json')
  202. check_returncode(result)
  203. 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'
  204. def test_format_json_keyboard_auto():
  205. result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_info.json')
  206. check_returncode(result)
  207. 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'
  208. def test_format_json_keymap_auto():
  209. result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_keymap.json')
  210. check_returncode(result)
  211. 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'