Skip to content

Commit c15eb5f

Browse files
committed
fix: format with ruff
1 parent 7bdaca3 commit c15eb5f

File tree

7 files changed

+193
-92
lines changed

7 files changed

+193
-92
lines changed

tests/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@
44
import pytest
55
from helper import TempRepository
66

7-
def create_repo(dirname = None):
7+
8+
def create_repo(dirname=None):
89
repo = TempRepository(dirname)
9-
tmp_file_a = repo.create_tmp_file()
10-
tmp_file_b = repo.create_tmp_file()
10+
repo.create_tmp_file()
11+
repo.create_tmp_file()
1112
repo.switch_cwd_under_repo()
1213
return repo
1314

15+
1416
def init_repo_git_status(repo):
1517
git = repo.get_repo_git()
1618
git.add(".")
1719
git.config("--local", "user.name", "test")
1820
git.config("--local", "user.email", "[email protected]")
1921
git.commit("-m", "chore: initial commit")
2022

23+
2124
@pytest.fixture(scope="module")
2225
def temp_repo():
2326
repo = create_repo()
2427
init_repo_git_status(repo)
2528
return repo
2629

30+
2731
@pytest.fixture(scope="module")
2832
def named_temp_repo(request):
2933
dirname = request.param

tests/helper.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import os, subprocess, shutil, tempfile
1+
import os
2+
import subprocess
3+
import shutil
4+
import tempfile
25
from git import Repo, GitCommandError
3-
from testpath import MockCommand, modified_env
46

57
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
68
GIT_EXTRAS_BIN = os.path.abspath(os.path.join(CURRENT_DIR, "..", "bin"))
@@ -10,15 +12,16 @@
1012
GITLAB_ORIGIN = "https://gitlab.com/tj/git-extras.git"
1113
BITBUCKET_ORIGIN = "https://bitbucket.org/tj/git-extras.git"
1214

15+
1316
class TempRepository:
14-
def __init__(self, repo_work_dir = None):
17+
def __init__(self, repo_work_dir=None):
1518
self._system_tmpdir = tempfile.gettempdir()
16-
if repo_work_dir == None:
19+
if repo_work_dir is None:
1720
repo_work_dir = tempfile.mkdtemp()
1821
else:
1922
repo_work_dir = os.path.join(self._system_tmpdir, repo_work_dir)
2023
self._cwd = repo_work_dir
21-
self._tempdirname = self._cwd[len(self._system_tmpdir) + 1:]
24+
self._tempdirname = self._cwd[len(self._system_tmpdir) + 1 :]
2225
self._git_repo = Repo.init(repo_work_dir, b="default")
2326
self._files = []
2427
self.change_origin_to_github()
@@ -50,8 +53,8 @@ def create_tmp_dir(self):
5053
tmp_dir = tempfile.mkdtemp()
5154
return tmp_dir
5255

53-
def create_tmp_file(self, temp_dir = None):
54-
if temp_dir == None:
56+
def create_tmp_file(self, temp_dir=None):
57+
if temp_dir is None:
5558
temp_dir = self._cwd
5659

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

6568
def writefile(self, temp_file, data):
66-
if data == None:
69+
if data is None:
6770
return
6871

6972
with open(temp_file, "w", encoding="utf-8") as f:
@@ -86,8 +89,9 @@ def invoke_installed_extras_command(self, name, *params):
8689
origin_extras_command = os.path.join(GIT_EXTRAS_BIN, command_name)
8790
temp_extras_command = os.path.join(self._cwd, command_name)
8891
helpers = [
89-
os.path.join(GIT_EXTRAS_HELPER, "git-extra-utility"),
90-
os.path.join(GIT_EXTRAS_HELPER, "is-git-repo")]
92+
os.path.join(GIT_EXTRAS_HELPER, "git-extra-utility"),
93+
os.path.join(GIT_EXTRAS_HELPER, "is-git-repo"),
94+
]
9195

9296
if not os.path.exists(temp_extras_command):
9397
whole = []
@@ -106,7 +110,7 @@ def invoke_installed_extras_command(self, name, *params):
106110
os.chmod(temp_extras_command, 0o775)
107111

108112
script = [temp_extras_command, *params]
109-
print(f"Run the script \"{script}\"")
113+
print(f'Run the script "{script}"')
110114
return subprocess.run(script, capture_output=True)
111115

112116
def change_origin(self, origin_url):

tests/test_git_abort.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from git import GitCommandError
22

3+
34
class TestGitAbort:
45
def test_init(self, temp_repo):
56
git = temp_repo.get_repo_git()

tests/test_git_archive_file.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import os, pytest
1+
import os
2+
import pytest
3+
24

35
class TestGitArchiveFile:
46
def test_init(self, temp_repo):
@@ -16,14 +18,17 @@ def test_archive_file_on_tags_branch(self, temp_repo):
1618
filename = "{0}.{1}.zip".format(temp_repo.get_repo_dirname(), git.describe())
1719
assert filename in os.listdir()
1820

19-
def test_archive_file_on_any_not_tags_branch_without_default_branch(self, temp_repo):
21+
def test_archive_file_on_any_not_tags_branch_without_default_branch(
22+
self, temp_repo
23+
):
2024
git = temp_repo.get_repo_git()
2125
git.checkout("-b", "not-tags-branch")
2226
temp_repo.invoke_installed_extras_command("archive-file")
2327
filename = "{0}.{1}.{2}.zip".format(
24-
temp_repo.get_repo_dirname(),
25-
git.describe("--always", "--long"),
26-
"not-tags-branch")
28+
temp_repo.get_repo_dirname(),
29+
git.describe("--always", "--long"),
30+
"not-tags-branch",
31+
)
2732
assert filename in os.listdir()
2833

2934
def test_archive_file_on_any_not_tags_branch_with_default_branch(self, temp_repo):
@@ -32,28 +37,28 @@ def test_archive_file_on_any_not_tags_branch_with_default_branch(self, temp_repo
3237
git.config("git-extras.default-branch", "default")
3338
temp_repo.invoke_installed_extras_command("archive-file")
3439
filename = "{0}.{1}.zip".format(
35-
temp_repo.get_repo_dirname(),
36-
git.describe("--always", "--long"))
40+
temp_repo.get_repo_dirname(), git.describe("--always", "--long")
41+
)
3742
assert filename in os.listdir()
3843

3944
def test_archive_file_on_branch_name_has_slash(self, temp_repo):
4045
git = temp_repo.get_repo_git()
4146
git.checkout("-b", "feature/slash")
4247
temp_repo.invoke_installed_extras_command("archive-file")
4348
filename = "{0}.{1}.{2}.zip".format(
44-
temp_repo.get_repo_dirname(),
45-
git.describe("--always", "--long"),
46-
"feature-slash")
49+
temp_repo.get_repo_dirname(),
50+
git.describe("--always", "--long"),
51+
"feature-slash",
52+
)
4753
assert filename in os.listdir()
4854

4955
@pytest.mark.parametrize("named_temp_repo", ["backslash\\dir"], indirect=True)
5056
def test_archive_file_on_dirname_has_backslash(self, named_temp_repo):
5157
named_temp_repo.invoke_installed_extras_command("archive-file")
5258
git = named_temp_repo.get_repo_git()
5359
filename = "{0}.{1}.{2}.zip".format(
54-
"backslash-dir",
55-
git.describe("--always", "--long"),
56-
"default")
60+
"backslash-dir", git.describe("--always", "--long"), "default"
61+
)
5762
assert filename in os.listdir()
5863

5964
def test_archive_file_on_tag_name_has_slash(self, temp_repo):
@@ -65,6 +70,6 @@ def test_archive_file_on_tag_name_has_slash(self, temp_repo):
6570
temp_repo.invoke_installed_extras_command("archive-file")
6671
description_include_version = git.describe("--always", "--long")
6772
filename = "{0}.{1}.zip".format(
68-
temp_repo.get_repo_dirname(),
69-
description_include_version.replace("/", "-"))
73+
temp_repo.get_repo_dirname(), description_include_version.replace("/", "-")
74+
)
7075
assert filename in os.listdir()

tests/test_git_authors.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import os, subprocess
2-
3-
expected_authors_list = "test <[email protected]>\ntestagain <[email protected]>\n"
1+
expected_authors_list = (
2+
"test <[email protected]>\ntestagain <[email protected]>\n"
3+
)
44
expected_authors_list_without_email = "test\ntestagain\n"
55
authors_file = "AUTHORS"
66

7+
78
class TestGitAuthors:
89
def test_init(self, temp_repo):
910
git = temp_repo.get_repo_git()
@@ -18,16 +19,16 @@ def test_init(self, temp_repo):
1819
git.commit("-m", "test: add data B")
1920

2021
def test_output_authors_has_email_without_any_parameter(self, temp_repo):
21-
git = temp_repo.get_repo_git()
22-
rs = temp_repo.invoke_extras_command("authors")
22+
temp_repo.get_repo_git()
23+
temp_repo.invoke_extras_command("authors")
2324
with open(authors_file) as f:
2425
content = f.read()
2526
print(content)
2627
print(expected_authors_list)
2728
assert content == expected_authors_list
2829

2930
def test_list_authors_has_email_defaultly(self, temp_repo):
30-
git = temp_repo.get_repo_git()
31+
temp_repo.get_repo_git()
3132
actual = temp_repo.invoke_extras_command("authors", "--list")
3233
actual = actual.stdout.decode()
3334
assert actual == expected_authors_list
@@ -36,7 +37,7 @@ def test_list_authors_has_email_defaultly(self, temp_repo):
3637
assert actual == expected_authors_list
3738

3839
def test_list_authors_has_not_email(self, temp_repo):
39-
git = temp_repo.get_repo_git()
40+
temp_repo.get_repo_git()
4041
actual = temp_repo.invoke_extras_command("authors", "--list", "--no-email")
4142
actual = actual.stdout.decode()
4243
assert actual == expected_authors_list_without_email

0 commit comments

Comments
 (0)