aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gmail.com>2021-03-05 14:59:10 -0700
committerTim Harder <radhermit@gmail.com>2021-03-05 14:59:38 -0700
commit6da619f82fb4946826defb3e71ae0da9a54af620 (patch)
tree37799b6a8f4239366af484c34f9ea4de624e7f6d /tests/test_git.py
parentbump version (diff)
downloadpkgdev-6da619f82fb4946826defb3e71ae0da9a54af620.tar.gz
pkgdev-6da619f82fb4946826defb3e71ae0da9a54af620.tar.bz2
pkgdev-6da619f82fb4946826defb3e71ae0da9a54af620.zip
tests: add initial git.run() tests
Diffstat (limited to 'tests/test_git.py')
-rw-r--r--tests/test_git.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_git.py b/tests/test_git.py
new file mode 100644
index 0000000..4874d0b
--- /dev/null
+++ b/tests/test_git.py
@@ -0,0 +1,27 @@
+import subprocess
+from unittest.mock import patch
+
+import pytest
+from snakeoil.cli.exceptions import UserException
+from snakeoil.contexts import chdir
+from pkgdev import git
+
+
+class TestGitRun:
+
+ def test_git_missing(self):
+ with patch('subprocess.run') as git_run:
+ git_run.side_effect = FileNotFoundError("no such file 'git'")
+ with pytest.raises(UserException, match="no such file 'git'"):
+ git.run('commit')
+
+ def test_failed_run(self):
+ with patch('subprocess.run') as git_run:
+ git_run.side_effect = subprocess.CalledProcessError(1, 'git commit')
+ with pytest.raises(git.GitError):
+ git.run('commit')
+
+ def test_successful_run(self, git_repo):
+ with chdir(git_repo.path):
+ p = git.run('rev-parse', '--abbrev-ref', 'HEAD', stdout=subprocess.PIPE)
+ assert p.stdout.strip() == 'master'