-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Sharing fixtures | ||
# Ref: https://docs.pytest.org/en/6.2.x/fixture.html#scope-sharing-fixtures-across-classes-modules-packages-or-session | ||
|
||
import os | ||
import subprocess | ||
import shlex | ||
import shutil | ||
import tempfile | ||
import pytest | ||
|
||
@pytest.fixture(scope="module") | ||
def git_repo(): | ||
git_extras_cwd = os.getcwd() | ||
tmp_dir = tempfile.mkdtemp() | ||
tmp_file_a = tempfile.mkstemp(dir=tmp_dir) | ||
tmp_file_b = tempfile.mkstemp(dir=tmp_dir) | ||
os.chdir(tmp_dir) | ||
result = subprocess.run(shlex.split("git init"), capture_output=True) | ||
print(result.stdout.decode()) | ||
print(result.stderr.decode()) | ||
result = subprocess.run(shlex.split("git add ."), capture_output=True) | ||
print(result.stdout.decode()) | ||
print(result.stderr.decode()) | ||
subprocess.run(shlex.split("git config --local user.name \"test\"")) | ||
subprocess.run(shlex.split("git config --local user.email \"[email protected]\"")) | ||
result = subprocess.run(shlex.split("git commit -m 'chore: initial commit'"), capture_output=True) | ||
print(result.stdout.decode()) | ||
print(result.stderr.decode()) | ||
yield [git_extras_cwd, tmp_dir, tmp_file_a, tmp_file_b] | ||
shutil.rmtree(tmp_dir, ignore_errors=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
import subprocess | ||
import shlex | ||
|
||
class TestGitAbort: | ||
def test_init(self, git_repo): | ||
_, tmp_dir, tmp_a, tmp_b = git_repo | ||
subprocess.run(shlex.split("git branch A")) | ||
subprocess.run(shlex.split("git branch B")) | ||
subprocess.run(shlex.split("git checkout A")) | ||
file_a = open(tmp_a[1], "w", encoding="utf-8") | ||
file_a.write('a') | ||
file_a.close() | ||
subprocess.run(shlex.split("git add .")) | ||
subprocess.run(shlex.split("git commit -m \"A\"")) | ||
subprocess.run(shlex.split("git checkout B")) | ||
file_b = open(tmp_a[1], "w", encoding="utf-8") | ||
file_b.write('b') | ||
file_b.close() | ||
subprocess.run(shlex.split("git add .")) | ||
subprocess.run(shlex.split("git commit -m \"B\"")) | ||
subprocess.run(shlex.split("git status")) | ||
|
||
def test_cherry_pick(self, git_repo): | ||
git_extras_cwd = git_repo[0] | ||
result = subprocess.run(shlex.split("git cherry-pick A"), capture_output=True) | ||
result = subprocess.run(shlex.split("git status"), capture_output=True) | ||
assert "Unmerged path" in result.stdout.decode() | ||
subprocess.run(shlex.split(os.path.join(git_extras_cwd, 'bin', 'git-abort'))) | ||
result = subprocess.run(shlex.split("git status"), capture_output=True) | ||
assert "nothing to commit, working tree clean" in result.stdout.decode() | ||
|
||
def test_merge(self, git_repo): | ||
git_extras_cwd = git_repo[0] | ||
git_extras_cwd = git_repo[0] | ||
result = subprocess.run(shlex.split("git merge --allow-unrelated-histories A"), capture_output=True) | ||
result = subprocess.run(shlex.split("git status"), capture_output=True) | ||
assert "Unmerged path" in result.stdout.decode() | ||
subprocess.run(shlex.split(os.path.join(git_extras_cwd, 'bin', 'git-abort'))) | ||
result = subprocess.run(shlex.split("git status"), capture_output=True) | ||
assert "nothing to commit, working tree clean" in result.stdout.decode() | ||
|
||
def test_rebase(self, git_repo): | ||
git_extras_cwd = git_repo[0] | ||
git_extras_cwd = git_repo[0] | ||
result = subprocess.run(shlex.split("git rebase A"), capture_output=True) | ||
result = subprocess.run(shlex.split("git status"), capture_output=True) | ||
assert "Unmerged path" in result.stdout.decode() | ||
subprocess.run(shlex.split(os.path.join(git_extras_cwd, 'bin', 'git-abort'))) | ||
result = subprocess.run(shlex.split("git status"), capture_output=True) | ||
assert "nothing to commit, working tree clean" in result.stdout.decode() | ||
|
||
def test_revert(self, git_repo): | ||
git_extras_cwd = git_repo[0] | ||
result = subprocess.run(shlex.split("git revert A"), capture_output=True) | ||
result = subprocess.run(shlex.split("git status"), capture_output=True) | ||
assert "Unmerged path" in result.stdout.decode() | ||
subprocess.run(shlex.split(os.path.join(git_extras_cwd, 'bin', 'git-abort'))) | ||
result = subprocess.run(shlex.split("git status"), capture_output=True) | ||
assert "nothing to commit, working tree clean" in result.stdout.decode() |