diff options
author | Stefan Kerkmann <karlk90@pm.me> | 2022-12-14 16:31:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 02:31:08 +1100 |
commit | 962e4c0e1854b10612bab547c3d842c5f967dd23 (patch) | |
tree | dfe13a5a7d3f593452a1e77b5c4173263d3fb2e2 /lib/python/qmk/cli/generate | |
parent | e2ab98f9601049a7540bd89cb128669b09c688d5 (diff) |
[Test] Reset timer for every unit test and provide timestamps for log messages (#17028)
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rw-r--r-- | lib/python/qmk/cli/generate/keycodes_tests.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/generate/keycodes_tests.py b/lib/python/qmk/cli/generate/keycodes_tests.py new file mode 100644 index 0000000000..453b4693a7 --- /dev/null +++ b/lib/python/qmk/cli/generate/keycodes_tests.py @@ -0,0 +1,39 @@ +"""Used by the make system to generate a keycode lookup table from keycodes_{version}.json +""" +from milc import cli + +from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE +from qmk.commands import dump_lines +from qmk.path import normpath +from qmk.keycodes import load_spec + + +def _generate_defines(lines, keycodes): + lines.append('') + lines.append('std::map<uint16_t, std::string> KEYCODE_ID_TABLE = {') + for key, value in keycodes["keycodes"].items(): + lines.append(f' {{{value.get("key")}, "{value.get("key")}"}},') + lines.append('};') + + +@cli.argument('-v', '--version', arg_only=True, required=True, help='Version of keycodes to generate.') +@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') +@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") +@cli.subcommand('Used by the make system to generate a keycode lookup table from keycodes_{version}.json', hidden=True) +def generate_keycodes_tests(cli): + """Generates a keycode to identifier lookup table for unit test output. + """ + + # Build the keycodes.h file. + keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '// clang-format off'] + keycodes_h_lines.append('extern "C" {\n#include <keycode.h>\n}') + keycodes_h_lines.append('#include <map>') + keycodes_h_lines.append('#include <string>') + keycodes_h_lines.append('#include <cstdint>') + + keycodes = load_spec(cli.args.version) + + _generate_defines(keycodes_h_lines, keycodes) + + # Show the results + dump_lines(cli.args.output, keycodes_h_lines, cli.args.quiet) |