diff options
author | William Chang <william@factual.com> | 2019-11-20 22:17:07 -0800 |
---|---|---|
committer | William Chang <william@factual.com> | 2019-11-20 22:17:07 -0800 |
commit | e7f4d56592b3975c38af329e77b4efd9108495e8 (patch) | |
tree | 0a416bccbf70bfdbdb9ffcdb3bf136b47378c014 /lib/python/qmk/tests | |
parent | 71493b2f9bbd5f3d18373c518fa14ccafcbf48fc (diff) | |
parent | 8416a94ad27b3ff058576f09f35f0704a8b39ff3 (diff) |
Merge remote-tracking branch 'upstream/master'
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/kle.txt | 5 | ||||
-rw-r--r-- | lib/python/qmk/tests/onekey_export.json | 6 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 56 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_qmk_errors.py | 8 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_qmk_keymap.py | 19 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_qmk_path.py | 13 |
8 files changed, 115 insertions, 0 deletions
diff --git a/lib/python/qmk/tests/__init__.py b/lib/python/qmk/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /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 0000000000..a2584b9233 --- /dev/null +++ b/lib/python/qmk/tests/attrdict.py @@ -0,0 +1,8 @@ +class AttrDict(dict): + """A dictionary that can be accessed by attributes. + + This should only be used to mock objects for unit testing. Please do not use this outside of qmk.tests. + """ + def __init__(self, *args, **kwargs): + super(AttrDict, self).__init__(*args, **kwargs) + self.__dict__ = self diff --git a/lib/python/qmk/tests/kle.txt b/lib/python/qmk/tests/kle.txt new file mode 100644 index 0000000000..862a899ab9 --- /dev/null +++ b/lib/python/qmk/tests/kle.txt @@ -0,0 +1,5 @@ +["¬\n`","!\n1","\"\n2","£\n3","$\n4","%\n5","^\n6","&\n7","*\n8","(\n9",")\n0","_\n-","+\n=",{w:2},"Backspace"], +[{w:1.5},"Tab","Q","W","E","R","T","Y","U","I","O","P","{\n[","}\n]",{x:0.25,w:1.25,h:2,w2:1.5,h2:1,x2:-0.25},"Enter"], +[{w:1.75},"Caps Lock","A","S","D","F","G","H","J","K","L",":\n;","@\n'","~\n#"], +[{w:1.25},"Shift","|\n\\","Z","X","C","V","B","N","M","<\n,",">\n.","?\n/",{w:2.75},"Shift"], +[{w:1.25},"Ctrl",{w:1.25},"Win",{w:1.25},"Alt",{a:7,w:6.25},"",{a:4,w:1.25},"AltGr",{w:1.25},"Win",{w:1.25},"Menu",{w:1.25},"Ctrl"] diff --git a/lib/python/qmk/tests/onekey_export.json b/lib/python/qmk/tests/onekey_export.json new file mode 100644 index 0000000000..95f0a980fe --- /dev/null +++ b/lib/python/qmk/tests/onekey_export.json @@ -0,0 +1,6 @@ +{ + "keyboard":"handwired/onekey/pytest", + "keymap":"pytest_unittest", + "layout":"LAYOUT", + "layers":[["KC_A"]] +} diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py new file mode 100644 index 0000000000..3f75cef3e1 --- /dev/null +++ b/lib/python/qmk/tests/test_cli_commands.py @@ -0,0 +1,56 @@ +import subprocess + + +def check_subcommand(command, *args): + cmd = ['bin/qmk', command] + list(args) + return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + + +def test_cformat(): + assert check_subcommand('cformat', 'tmk_core/common/keyboard.c').returncode == 0 + + +def test_compile(): + assert check_subcommand('compile', '-kb', 'handwired/onekey/pytest', '-km', 'default').returncode == 0 + + +def test_flash(): + assert check_subcommand('flash', '-b').returncode == 1 + assert check_subcommand('flash').returncode == 1 + + +def test_config(): + result = check_subcommand('config') + assert result.returncode == 0 + assert 'general.color' in result.stdout + + +def test_kle2json(): + assert check_subcommand('kle2json', 'kle.txt', '-f').returncode == 0 + + +def test_doctor(): + result = check_subcommand('doctor') + assert result.returncode == 0 + assert 'QMK Doctor is checking your environment.' in result.stderr + assert 'QMK is ready to go' in result.stderr + + +def test_hello(): + result = check_subcommand('hello') + assert result.returncode == 0 + assert 'Hello,' in result.stderr + + +def test_pyformat(): + result = check_subcommand('pyformat') + assert result.returncode == 0 + assert 'Successfully formatted the python code' in result.stderr + + +def test_list_keyboards(): + result = check_subcommand('list-keyboards') + assert result.returncode == 0 + # check to see if a known keyboard is returned + # this will fail if handwired/onekey/pytest is removed + assert 'handwired/onekey/pytest' in result.stdout 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 0000000000..1d8690b7ef --- /dev/null +++ b/lib/python/qmk/tests/test_qmk_errors.py @@ -0,0 +1,8 @@ +from qmk.errors import NoSuchKeyboardError + + +def test_NoSuchKeyboardError(): + try: + raise NoSuchKeyboardError("test message") + except NoSuchKeyboardError as e: + 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 0000000000..2db625600e --- /dev/null +++ b/lib/python/qmk/tests/test_qmk_keymap.py @@ -0,0 +1,19 @@ +import qmk.keymap + + +def test_template_onekey_proton_c(): + templ = qmk.keymap.template('handwired/onekey/proton_c') + assert templ == qmk.keymap.DEFAULT_KEYMAP_C + + +def test_template_onekey_pytest(): + templ = qmk.keymap.template('handwired/onekey/pytest') + assert templ == 'const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {__KEYMAP_GOES_HERE__};\n' + + +def test_generate_onekey_pytest(): + templ = qmk.keymap.generate('handwired/onekey/pytest', 'LAYOUT', [['KC_A']]) + assert templ == 'const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT(KC_A)};\n' + + +# 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 0000000000..d6961a0f65 --- /dev/null +++ b/lib/python/qmk/tests/test_qmk_path.py @@ -0,0 +1,13 @@ +import os + +import qmk.path + + +def test_keymap_onekey_pytest(): + path = qmk.path.keymap('handwired/onekey/pytest') + assert path == 'keyboards/handwired/onekey/keymaps' + + +def test_normpath(): + path = qmk.path.normpath('lib/python') + assert path == os.path.join(os.environ['ORIG_CWD'], 'lib/python') |