test_cli_commands.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. result = check_subcommand('cformat', 'quantum/matrix.c')
  7. assert result.returncode == 0
  8. def test_compile():
  9. assert check_subcommand('compile', '-kb', 'handwired/onekey/pytest', '-km', 'default').returncode == 0
  10. def test_flash():
  11. assert check_subcommand('flash', '-b').returncode == 1
  12. assert check_subcommand('flash').returncode == 1
  13. def test_config():
  14. result = check_subcommand('config')
  15. assert result.returncode == 0
  16. assert 'general.color' in result.stdout
  17. def test_kle2json():
  18. assert check_subcommand('kle2json', 'kle.txt', '-f').returncode == 0
  19. def test_doctor():
  20. result = check_subcommand('doctor', '-n')
  21. assert result.returncode == 0
  22. assert 'QMK Doctor is checking your environment.' in result.stderr
  23. assert 'QMK is ready to go' in result.stderr
  24. def test_hello():
  25. result = check_subcommand('hello')
  26. assert result.returncode == 0
  27. assert 'Hello,' in result.stderr
  28. def test_pyformat():
  29. result = check_subcommand('pyformat')
  30. assert result.returncode == 0
  31. assert 'Successfully formatted the python code' in result.stderr
  32. def test_list_keyboards():
  33. result = check_subcommand('list-keyboards')
  34. assert result.returncode == 0
  35. # check to see if a known keyboard is returned
  36. # this will fail if handwired/onekey/pytest is removed
  37. assert 'handwired/onekey/pytest' in result.stdout
  38. def test_list_keymaps():
  39. result = check_subcommand("list-keymaps", "-kb", "handwired/onekey/pytest")
  40. assert result.returncode == 0
  41. assert "default" and "test" in result.stdout
  42. def test_list_keymaps_no_keyboard_found():
  43. result = check_subcommand("list-keymaps", "-kb", "asdfghjkl")
  44. assert result.returncode == 0
  45. assert "does not exist" in result.stdout