diff options
| author | skullY <skullydazed@gmail.com> | 2019-08-21 23:40:24 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-09-07 07:58:41 -0700 |
| commit | 5b7a5b2a7629fbb667d23a55836dce3c6c46a203 (patch) | |
| tree | b153a030844887422464c6c4f4833242b34a9314 /lib/python/qmk/tests | |
| parent | 4d339b7b5d1ecc2320080798d7e07e2d43675578 (diff) | |
| download | qmk_firmware-5b7a5b2a7629fbb667d23a55836dce3c6c46a203.tar.gz qmk_firmware-5b7a5b2a7629fbb667d23a55836dce3c6c46a203.zip | |
Setup a python test framework
Diffstat (limited to 'lib/python/qmk/tests')
| -rw-r--r-- | lib/python/qmk/tests/__init__.py | 0 | ||||
| -rw-r--r-- | lib/python/qmk/tests/attrdict.py | 8 | ||||
| -rw-r--r-- | lib/python/qmk/tests/onekey_export.json | 6 | ||||
| -rw-r--r-- | lib/python/qmk/tests/test_qmk_errors.py | 7 | ||||
| -rw-r--r-- | lib/python/qmk/tests/test_qmk_keymap.py | 18 | ||||
| -rw-r--r-- | lib/python/qmk/tests/test_qmk_path.py | 12 |
6 files changed, 51 insertions, 0 deletions
diff --git a/lib/python/qmk/tests/__init__.py b/lib/python/qmk/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/python/qmk/tests/__init__.py | |||
diff --git a/lib/python/qmk/tests/attrdict.py b/lib/python/qmk/tests/attrdict.py new file mode 100644 index 000000000..a2584b923 --- /dev/null +++ b/lib/python/qmk/tests/attrdict.py | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | class AttrDict(dict): | ||
| 2 | """A dictionary that can be accessed by attributes. | ||
| 3 | |||
| 4 | This should only be used to mock objects for unit testing. Please do not use this outside of qmk.tests. | ||
| 5 | """ | ||
| 6 | def __init__(self, *args, **kwargs): | ||
| 7 | super(AttrDict, self).__init__(*args, **kwargs) | ||
| 8 | self.__dict__ = self | ||
diff --git a/lib/python/qmk/tests/onekey_export.json b/lib/python/qmk/tests/onekey_export.json new file mode 100644 index 000000000..95f0a980f --- /dev/null +++ b/lib/python/qmk/tests/onekey_export.json | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | { | ||
| 2 | "keyboard":"handwired/onekey/pytest", | ||
| 3 | "keymap":"pytest_unittest", | ||
| 4 | "layout":"LAYOUT", | ||
| 5 | "layers":[["KC_A"]] | ||
| 6 | } | ||
diff --git a/lib/python/qmk/tests/test_qmk_errors.py b/lib/python/qmk/tests/test_qmk_errors.py new file mode 100644 index 000000000..3f6b56713 --- /dev/null +++ b/lib/python/qmk/tests/test_qmk_errors.py | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | from qmk.errors import NoSuchKeyboardError | ||
| 2 | |||
| 3 | def test_NoSuchKeyboardError(): | ||
| 4 | try: | ||
| 5 | raise(NoSuchKeyboardError("test message")) | ||
| 6 | except NoSuchKeyboardError as e: | ||
| 7 | assert e.message == 'test message' | ||
diff --git a/lib/python/qmk/tests/test_qmk_keymap.py b/lib/python/qmk/tests/test_qmk_keymap.py new file mode 100644 index 000000000..6a565ee90 --- /dev/null +++ b/lib/python/qmk/tests/test_qmk_keymap.py | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | import qmk.keymap | ||
| 2 | |||
| 3 | def test_template_onekey_proton_c(): | ||
| 4 | templ = qmk.keymap.template('handwired/onekey/proton_c') | ||
| 5 | assert templ == qmk.keymap.DEFAULT_KEYMAP_C | ||
| 6 | |||
| 7 | |||
| 8 | def test_template_onekey_pytest(): | ||
| 9 | templ = qmk.keymap.template('handwired/onekey/pytest') | ||
| 10 | assert templ == 'const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {__KEYMAP_GOES_HERE__};\n' | ||
| 11 | |||
| 12 | |||
| 13 | def test_generate_onekey_pytest(): | ||
| 14 | templ = qmk.keymap.generate('handwired/onekey/pytest', 'LAYOUT', [['KC_A']]) | ||
| 15 | assert templ == 'const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT(KC_A)};\n' | ||
| 16 | |||
| 17 | |||
| 18 | # FIXME(skullydazed): Add a test for qmk.keymap.write that mocks up an FD. | ||
diff --git a/lib/python/qmk/tests/test_qmk_path.py b/lib/python/qmk/tests/test_qmk_path.py new file mode 100644 index 000000000..23816be7e --- /dev/null +++ b/lib/python/qmk/tests/test_qmk_path.py | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | import os | ||
| 2 | |||
| 3 | import qmk.path | ||
| 4 | |||
| 5 | def test_keymap_onekey_pytest(): | ||
| 6 | path = qmk.path.keymap('handwired/onekey/pytest') | ||
| 7 | assert path == 'keyboards/handwired/onekey/keymaps' | ||
| 8 | |||
| 9 | |||
| 10 | def test_normpath(): | ||
| 11 | path = qmk.path.normpath('lib/python') | ||
| 12 | assert path == os.environ['ORIG_CWD'] + '/lib/python' | ||
