forked from tj/git-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(git-archive-file): add unit test (tj#1084)
- Loading branch information
Showing
3 changed files
with
131 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,29 @@ | |
import pytest | ||
from helper import TempRepository | ||
|
||
@pytest.fixture(scope="module") | ||
def temp_repo(): | ||
repo = TempRepository() | ||
git = repo.get_repo_git() | ||
def create_repo(dirname = None): | ||
repo = TempRepository(dirname) | ||
tmp_file_a = repo.create_tmp_file() | ||
tmp_file_b = repo.create_tmp_file() | ||
repo.switch_cwd_under_repo() | ||
return repo | ||
|
||
def init_repo_git_status(repo): | ||
git = repo.get_repo_git() | ||
git.add(".") | ||
git.config("--local", "user.name", "test") | ||
git.config("--local", "user.email", "[email protected]") | ||
git.commit("-m", "chore: initial commit") | ||
|
||
@pytest.fixture(scope="module") | ||
def temp_repo(): | ||
repo = create_repo() | ||
init_repo_git_status(repo) | ||
return repo | ||
|
||
@pytest.fixture(scope="module") | ||
def named_temp_repo(request): | ||
dirname = request.param | ||
repo = create_repo(dirname) | ||
init_repo_git_status(repo) | ||
return repo |
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,70 @@ | ||
import os, pytest | ||
|
||
class TestGitArchiveFile: | ||
def test_init(self, temp_repo): | ||
git = temp_repo.get_repo_git() | ||
tmp_file = temp_repo.get_file(0) | ||
temp_repo.writefile(tmp_file, "data") | ||
git.add(".") | ||
git.commit("-m", "test: add data") | ||
git.tag("0.1.0", "-m", "bump: 0.1.0") | ||
|
||
def test_archive_file_on_tags_branch(self, temp_repo): | ||
git = temp_repo.get_repo_git() | ||
git.checkout("-b", "tags0.1.0") | ||
temp_repo.invoke_installed_extras_command("archive-file") | ||
filename = "{0}.{1}.zip".format(temp_repo.get_repo_dirname(), git.describe()) | ||
assert filename in os.listdir() | ||
|
||
def test_archive_file_on_any_not_tags_branch_without_default_branch(self, temp_repo): | ||
git = temp_repo.get_repo_git() | ||
git.checkout("-b", "not-tags-branch") | ||
temp_repo.invoke_installed_extras_command("archive-file") | ||
filename = "{0}.{1}.{2}.zip".format( | ||
temp_repo.get_repo_dirname(), | ||
git.describe("--always", "--long"), | ||
"not-tags-branch") | ||
assert filename in os.listdir() | ||
|
||
def test_archive_file_on_any_not_tags_branch_with_default_branch(self, temp_repo): | ||
git = temp_repo.get_repo_git() | ||
git.checkout("master") | ||
git.config("git-extras.default-branch", "master") | ||
temp_repo.invoke_installed_extras_command("archive-file") | ||
filename = "{0}.{1}.zip".format( | ||
temp_repo.get_repo_dirname(), | ||
git.describe("--always", "--long")) | ||
assert filename in os.listdir() | ||
|
||
def test_archive_file_on_branch_name_has_slash(self, temp_repo): | ||
git = temp_repo.get_repo_git() | ||
git.checkout("-b", "feature/slash") | ||
temp_repo.invoke_installed_extras_command("archive-file") | ||
filename = "{0}.{1}.{2}.zip".format( | ||
temp_repo.get_repo_dirname(), | ||
git.describe("--always", "--long"), | ||
"feature-slash") | ||
assert filename in os.listdir() | ||
|
||
@pytest.mark.parametrize("named_temp_repo", ["backslash\\dir"], indirect=True) | ||
def test_archive_file_on_dirname_has_backslash(self, named_temp_repo): | ||
named_temp_repo.invoke_installed_extras_command("archive-file") | ||
git = named_temp_repo.get_repo_git() | ||
filename = "{0}.{1}.{2}.zip".format( | ||
"backslash-dir", | ||
git.describe("--always", "--long"), | ||
"master") | ||
assert filename in os.listdir() | ||
|
||
def test_archive_file_on_tag_name_has_slash(self, temp_repo): | ||
temp_repo.switch_cwd_under_repo() | ||
git = temp_repo.get_repo_git() | ||
git.checkout("master") | ||
git.tag("--delete", "0.1.0") | ||
git.tag("0.1.0/slash", "-m", "bump: 0.1.0") | ||
temp_repo.invoke_installed_extras_command("archive-file") | ||
description_include_version = git.describe("--always", "--long") | ||
filename = "{0}.{1}.zip".format( | ||
temp_repo.get_repo_dirname(), | ||
description_include_version.replace("/", "-")) | ||
assert filename in os.listdir() |