test_git.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """Test git"""
  2. import re
  3. import pytest
  4. @pytest.mark.usefixtures('ds1_copy')
  5. def test_git(runner, yadm_y, paths):
  6. """Test series of passthrough git commands
  7. Passthru unknown commands to Git
  8. Git command 'add' - badfile
  9. Git command 'add'
  10. Git command 'status'
  11. Git command 'commit'
  12. Git command 'log'
  13. """
  14. # passthru unknown commands to Git
  15. run = runner(command=yadm_y('bogus'))
  16. assert run.failure
  17. assert "git: 'bogus' is not a git command." in run.err
  18. assert "See 'git --help'" in run.err
  19. assert run.out == ''
  20. # git command 'add' - badfile
  21. run = runner(command=yadm_y('add', '-v', 'does_not_exist'))
  22. assert run.code == 128
  23. assert "pathspec 'does_not_exist' did not match any files" in run.err
  24. assert run.out == ''
  25. # git command 'add'
  26. newfile = paths.work.join('test_git')
  27. newfile.write('test_git')
  28. run = runner(command=yadm_y('add', '-v', str(newfile)))
  29. assert run.success
  30. assert run.err == ''
  31. assert "add 'test_git'" in run.out
  32. # git command 'status'
  33. run = runner(command=yadm_y('status'))
  34. assert run.success
  35. assert run.err == ''
  36. assert re.search(r'new file:\s+test_git', run.out)
  37. # git command 'commit'
  38. run = runner(command=yadm_y('commit', '-m', 'Add test_git'))
  39. assert run.success
  40. assert run.err == ''
  41. assert '1 file changed' in run.out
  42. assert '1 insertion' in run.out
  43. assert re.search(r'create mode .+ test_git', run.out)
  44. # git command 'log'
  45. run = runner(command=yadm_y('log', '--oneline'))
  46. assert run.success
  47. assert run.err == ''
  48. assert 'Add test_git' in run.out