Last active
April 14, 2024 08:41
-
-
Save eeriemyxi/ec779ba75d1a6a807234d6cf2af480d5 to your computer and use it in GitHub Desktop.
Swap keyboard layout per test: extension of Lismi (@ https://github.com/eeriemyxi/lismi) typing frontend.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import subprocess | |
# https://stackoverflow.com/a/52025430/22818367 | |
class ArgumentParserWithDefaults(argparse.ArgumentParser): | |
def add_argument( # type:ignore | |
self, | |
*args: object, | |
help: str | None = None, # noqa:A002 | |
default: object | None = None, | |
**kwargs: dict, | |
) -> None: | |
if help is not None: | |
kwargs["help"] = help # type:ignore | |
if default is not None and args[0] != "-h": | |
kwargs["default"] = default # type:ignore | |
if help is not None: | |
kwargs["help"] += f" (default: {default!r})" # type:ignore | |
super().add_argument(*args, **kwargs) # type:ignore | |
TOTAL = 50 | |
ARGS = "-S" | |
EXTRA_ARGS = "" | |
PROGRAM = "lismi" | |
parser = ArgumentParserWithDefaults() | |
parser.add_argument("-n", "--total", default=TOTAL, type=int, help="Total tests.") | |
parser.add_argument("--program", default=PROGRAM, help="Program path.") | |
parser.add_argument( | |
"-a", "--extra-args", default=EXTRA_ARGS, help="Extra arguments to pass to Lismi." | |
) | |
args = parser.parse_args() | |
PROGRAM = args.program | |
TOTAL = args.total | |
EXTRA_ARGS = args.extra_args | |
def main() -> None: | |
target_layouts = ["colemak", "colemak"] | |
emulate_layouts = ["qwerty", "colemak"] | |
for i in range(TOTAL): | |
args = [ # noqa:S603 | |
PROGRAM, | |
ARGS, | |
"-t", | |
target_layouts[i % 2], | |
"-e", | |
emulate_layouts[i % 2], | |
] | |
if EXTRA_ARGS: | |
args.append(EXTRA_ARGS) | |
subprocess.run(args) | |
if __name__ == "__main__": | |
try: | |
main() | |
except KeyboardInterrupt: | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edit the variables
target_layouts
andemulate_layouts
as you wish.