-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
test_qmk_compiler.py
73 lines (55 loc) · 2.58 KB
/
test_qmk_compiler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Test suite for qmk_compiler.
This file tests most of the functionality in qmk_compiler. Given the nature
of qmk_compiler most of the functionality depends on qmk_firmware being
checked out and available. To satisfy this requirement
`test_0000_checkout_qmk_skip_cache()` must be tested first, and
`test_9999_teardown()` must be tested last. It would be better if this were
setup as a test fixture, and some day it will be. Setting up a proper test
fixture here is a non-trivial task and will take work that the author has
not had time to put in yet.
"""
import filecmp
import os
import os.path
import re
import shutil
from tempfile import mkstemp
import pytest
import qmk_commands
############################################################################
# Setup Environment #
############################################################################
def test_0000_checkout_qmk_master():
"""Make sure that we successfully git clone qmk_firmware and generate the version.txt hash.
"""
qmk_commands.checkout_qmk(branch='master')
assert (qmk_commands.QMK_FIRMWARE_PATH / 'version.txt').exists()
############################################################################
# Begin Tests #
############################################################################
def test_0011_find_firmware_file_hex():
"""Make sure that qmk_commands.find_firmware_file() can find a hex file.
"""
fd, test_firmware = mkstemp(suffix='.hex', dir='.')
firmware_file = qmk_commands.find_firmware_file()
os.remove(test_firmware)
assert os.path.split(test_firmware)[-1] == firmware_file
def test_0012_find_firmware_file_bin():
"""Make sure that qmk_commands.find_firmware_file() can find a bin file.
"""
fd, test_firmware = mkstemp(suffix='.bin', dir='.')
firmware_file = qmk_commands.find_firmware_file()
os.remove(test_firmware)
assert os.path.split(test_firmware)[-1] == firmware_file
def test_0013_git_hash():
"""Make sure that we get a valid hex string in the git hash.
"""
hash = qmk_commands.git_hash()
assert re.match(r'^[0-9a-f]+$', hash)
assert len(hash) == 40
############################################################################
# Clean Up Environment #
############################################################################
def test_9999_teardown():
shutil.rmtree(str(qmk_commands.QMK_FIRMWARE_PATH))
assert not qmk_commands.QMK_FIRMWARE_PATH.exists()