test_cli_commands.py 2.0 KB

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