test_cli_commands.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import subprocess
  2. def check_subcommand(command, *args):
  3. cmd = ['bin/qmk', command] + list(args)
  4. return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
  5. def test_cformat():
  6. assert check_subcommand('cformat', 'tmk_core/common/keyboard.c').returncode == 0
  7. def test_compile():
  8. assert check_subcommand('compile', '-kb', 'handwired/onekey/pytest', '-km', 'default').returncode == 0
  9. def test_flash():
  10. assert check_subcommand('flash', '-b').returncode == 1
  11. assert check_subcommand('flash').returncode == 1
  12. def test_config():
  13. result = check_subcommand('config')
  14. assert result.returncode == 0
  15. assert 'general.color' in result.stdout
  16. def test_kle2json():
  17. assert check_subcommand('kle2json', 'kle.txt', '-f').returncode == 0
  18. def test_doctor():
  19. result = check_subcommand('doctor', '-n')
  20. assert result.returncode == 0
  21. assert 'QMK Doctor is checking your environment.' in result.stderr
  22. assert 'QMK is ready to go' in result.stderr
  23. def test_hello():
  24. result = check_subcommand('hello')
  25. assert result.returncode == 0
  26. assert 'Hello,' in result.stderr
  27. def test_pyformat():
  28. result = check_subcommand('pyformat')
  29. assert result.returncode == 0
  30. assert 'Successfully formatted the python code' in result.stderr
  31. def test_list_keyboards():
  32. result = check_subcommand('list-keyboards')
  33. assert result.returncode == 0
  34. # check to see if a known keyboard is returned
  35. # this will fail if handwired/onekey/pytest is removed
  36. assert 'handwired/onekey/pytest' in result.stdout
  37. def test_list_keymaps():
  38. result = check_subcommand("list-keymaps", "-kb", "planck/ez")
  39. assert result.returncode == 0
  40. assert "planck/ez:default" and "planck/ez:drashna" in result.stdout
  41. def test_list_keymaps_no_keyboard_found():
  42. result = check_subcommand("list-keymaps", "-kb", "asdfghjkl")
  43. assert result.returncode == 0
  44. assert "does not exist" in result.stdout