test_qmk_keymap.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import qmk.keymap
  2. def test_template_c_pytest_basic():
  3. templ = qmk.keymap.template_c('handwired/pytest/basic')
  4. assert templ == qmk.keymap.DEFAULT_KEYMAP_C
  5. def test_template_json_pytest_basic():
  6. templ = qmk.keymap.template_json('handwired/pytest/basic')
  7. assert templ == {'keyboard': 'handwired/pytest/basic'}
  8. def test_generate_c_pytest_basic():
  9. keymap_json = {
  10. 'keyboard': 'handwired/pytest/basic',
  11. 'layout': 'LAYOUT',
  12. 'layers': [['KC_A']],
  13. 'macros': None,
  14. }
  15. templ = qmk.keymap.generate_c(keymap_json)
  16. assert templ == """#include QMK_KEYBOARD_H
  17. #if __has_include("keymap.h")
  18. # include "keymap.h"
  19. #endif
  20. /* THIS FILE WAS GENERATED!
  21. *
  22. * This file was generated by qmk json2c. You may or may not want to
  23. * edit it directly.
  24. */
  25. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  26. [0] = LAYOUT(KC_A)
  27. };
  28. #if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
  29. const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
  30. };
  31. #endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
  32. """
  33. def test_generate_json_pytest_basic():
  34. templ = qmk.keymap.generate_json('default', 'handwired/pytest/basic', 'LAYOUT', [['KC_A']])
  35. assert templ == {"keyboard": "handwired/pytest/basic", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_A"]]}
  36. def test_parse_keymap_c():
  37. parsed_keymap_c = qmk.keymap.parse_keymap_c('keyboards/handwired/pytest/basic/keymaps/default/keymap.c')
  38. assert parsed_keymap_c == {'layers': [{'name': '0', 'layout': 'LAYOUT_ortho_1x1', 'keycodes': ['KC_A']}]}
  39. # FIXME(skullydazed): Add a test for qmk.keymap.write that mocks up an FD.