Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into oikarinen-git-continue
Browse files Browse the repository at this point in the history
  • Loading branch information
oikarinen committed Nov 28, 2024
2 parents a2cef11 + c23da8a commit d31583f
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 83 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: 'Get Changed Files'
id: 'files'
run: |
CHANGED_FILES=$(git diff --name-only "${BASE_SHA:-$BEFORE_SHA}...${HEAD_SHA:-GITHUB_REF}")
CHANGED_FILES=$(git diff --name-only "${BASE_SHA:-$BEFORE_SHA}...${HEAD_SHA:-$GITHUB_REF}")
echo "::notice::Changed files: $CHANGED_FILES"
{
echo "added_modified<<EOF"
Expand All @@ -36,6 +36,8 @@ jobs:
env:
# NOTE: use env to pass the output in order to avoid possible injection attacks
FILES: "${{ steps.files.outputs.added_modified }}"
- name: Lint and format Python with Ruff
uses: astral-sh/ruff-action@v1

typo:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def named_temp_repo(request):

@pytest.fixture(scope="function")
def temp_repo_clean():
""" Create a temporary repository that is reset for each function call. """
"""Create a temporary repository that is reset for each function call."""
repo = create_repo()
init_repo_git_status(repo)
return repo
6 changes: 3 additions & 3 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class TempRepository:
def __init__(self, repo_work_dir=None):
self._system_tmpdir = tempfile.gettempdir()
if repo_work_dir == None:
if repo_work_dir is None:
repo_work_dir = tempfile.mkdtemp()
else:
repo_work_dir = os.path.join(self._system_tmpdir, repo_work_dir)
Expand Down Expand Up @@ -54,7 +54,7 @@ def create_tmp_dir(self):
return tmp_dir

def create_tmp_file(self, temp_dir=None):
if temp_dir == None:
if temp_dir is None:
temp_dir = self._cwd

tmp_file = tempfile.mkstemp(dir=temp_dir)
Expand All @@ -66,7 +66,7 @@ def remove_tmp_file(self, file_path):
print(f"File {file_path} has been removed")

def writefile(self, temp_file, data):
if data == None:
if data is None:
return

with open(temp_file, "w", encoding="utf-8") as f:
Expand Down
63 changes: 63 additions & 0 deletions tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,66 @@ testpaths = ["."]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

# Same as Black.
line-length = 88
indent-width = 4

# Assume Python 3.9
target-version = "py39"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
1 change: 1 addition & 0 deletions tests/test_git_abort.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from git import GitCommandError


class TestGitAbort:
def test_init(self, temp_repo):
git = temp_repo.get_repo_git()
Expand Down
35 changes: 20 additions & 15 deletions tests/test_git_archive_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os, pytest
import os
import pytest


class TestGitArchiveFile:
def test_init(self, temp_repo):
Expand All @@ -16,14 +18,17 @@ def test_archive_file_on_tags_branch(self, temp_repo):
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):
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")
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):
Expand All @@ -32,28 +37,28 @@ def test_archive_file_on_any_not_tags_branch_with_default_branch(self, temp_repo
git.config("git-extras.default-branch", "default")
temp_repo.invoke_installed_extras_command("archive-file")
filename = "{0}.{1}.zip".format(
temp_repo.get_repo_dirname(),
git.describe("--always", "--long"))
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")
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"),
"default")
"backslash-dir", git.describe("--always", "--long"), "default"
)
assert filename in os.listdir()

def test_archive_file_on_tag_name_has_slash(self, temp_repo):
Expand All @@ -65,6 +70,6 @@ def test_archive_file_on_tag_name_has_slash(self, temp_repo):
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("/", "-"))
temp_repo.get_repo_dirname(), description_include_version.replace("/", "-")
)
assert filename in os.listdir()
15 changes: 8 additions & 7 deletions tests/test_git_authors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os, subprocess

expected_authors_list = "test <test@git-extras.com>\ntestagain <testagain@git-extras.com>\n"
expected_authors_list = (
"test <test@git-extras.com>\ntestagain <testagain@git-extras.com>\n"
)
expected_authors_list_without_email = "test\ntestagain\n"
authors_file = "AUTHORS"


class TestGitAuthors:
def test_init(self, temp_repo):
git = temp_repo.get_repo_git()
Expand All @@ -18,16 +19,16 @@ def test_init(self, temp_repo):
git.commit("-m", "test: add data B")

def test_output_authors_has_email_without_any_parameter(self, temp_repo):
git = temp_repo.get_repo_git()
rs = temp_repo.invoke_extras_command("authors")
temp_repo.get_repo_git()
temp_repo.invoke_extras_command("authors")
with open(authors_file) as f:
content = f.read()
print(content)
print(expected_authors_list)
assert content == expected_authors_list

def test_list_authors_has_email_defaultly(self, temp_repo):
git = temp_repo.get_repo_git()
temp_repo.get_repo_git()
actual = temp_repo.invoke_extras_command("authors", "--list")
actual = actual.stdout.decode()
assert actual == expected_authors_list
Expand All @@ -36,7 +37,7 @@ def test_list_authors_has_email_defaultly(self, temp_repo):
assert actual == expected_authors_list

def test_list_authors_has_not_email(self, temp_repo):
git = temp_repo.get_repo_git()
temp_repo.get_repo_git()
actual = temp_repo.invoke_extras_command("authors", "--list", "--no-email")
actual = actual.stdout.decode()
assert actual == expected_authors_list_without_email
Expand Down
Loading

0 comments on commit d31583f

Please sign in to comment.