Skip to content

Commit 83c8572

Browse files
committed
NOGH: finally upgrade pylint and fix tests
1 parent 2260a99 commit 83c8572

11 files changed

+31
-27
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,6 @@ fabric.properties
173173

174174
# Android studio 3.1+ serialized cache file
175175
.idea/caches/build_file_checksums.ser
176-
test_repo
176+
test_repo
177+
178+
*.zip

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PyInstaller==5.7.0
22
pytest==7.2.1
3-
pylint==2.7.4
3+
pylint==2.15.10
44
codecov==2.1.12
55
pytest-cov==4.0.0

scripts/lint.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
DOCSTRING_REQUIREMENT = 'C0111'
88

9-
# This can create a problem when we don't use self.assert() in a unit test (Mocking, ext..)
10-
METHOD_COULD_BE_FUNCTION = 'R0201'
11-
129
TOO_FEW_PUBLIC_METHODS = 'R0903'
1310

1411

@@ -36,5 +33,5 @@ def lint(ignore_rules: list, directories: list):
3633
'scripts'
3734
])
3835

39-
lint([DOCSTRING_REQUIREMENT, METHOD_COULD_BE_FUNCTION, TOO_FEW_PUBLIC_METHODS],
36+
lint([DOCSTRING_REQUIREMENT, TOO_FEW_PUBLIC_METHODS],
4037
['src.test', 'src.integration'])

scripts/os_specific_requirements.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
OS_PREFIX: str = platform.system().lower()
99

1010
print("Running OS setup")
11-
print("OS: %s" % OS_PREFIX)
11+
print(f"OS: {OS_PREFIX}")
1212

1313
if OS_PREFIX == "darwin":
1414
os.system("brew install upx")

scripts/package.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
PyInstaller.__main__.run([
2727
"--onefile",
2828
"--hidden-import=_cffi_backend",
29-
"--distpath=%s" % EXE_FILE_FOLDER,
30-
"--name=%s" % EXE_NAME,
29+
f"--distpath={EXE_FILE_FOLDER}",
30+
f"--name={EXE_NAME}",
3131
os.path.join("src", "main", "commit_msg_hook.py"),
3232
])
3333

@@ -52,4 +52,4 @@
5252
# in the current working directory
5353
zip_file_name = OS_ALIAS.capitalize()
5454
shutil.make_archive(zip_file_name, 'zip', EXE_FILE_FOLDER)
55-
print("Wrote zip file: %s" % zip_file_name)
55+
print(f"Wrote zip file: {zip_file_name}")

src/integration/test_integration.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ def setUp(self):
5757

5858
def test_commit_message_is_edited(self):
5959
file_to_commit_path = "example.txt"
60-
file_to_commit = open(file_to_commit_path, 'w')
61-
file_to_commit.write("content here")
62-
file_to_commit.close()
60+
with open(file_to_commit_path, 'w', encoding="utf8") as file_to_commit:
61+
file_to_commit.write("content here")
6362

6463
# stage file
6564
os.system("git add " + file_to_commit_path)
@@ -74,13 +73,13 @@ def test_commit_message_is_edited(self):
7473
# Give git a moment to switch branches
7574
time.sleep(2)
7675

77-
os.system('git commit -m "%s"' % commit_message)
76+
os.system(f"git commit -m \"{commit_message}\"")
7877

7978
# Give the hook N seconds to run
8079
time.sleep(5)
8180

8281
# Save commit message after hook should have run
8382
commit_message_after_hook: str = os.popen("git log -n 1 --format=\"%s\"").read()
8483

85-
self.assertEqual(commit_message_after_hook.strip(), "GH-123: %s" % commit_message,
84+
self.assertEqual(commit_message_after_hook.strip(), f"GH-123: {commit_message}",
8685
"Commit message was not edited correctly")

src/main/commit_msg_hook.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_config() -> CommitHookConfig:
3131
return CommitHookConfigINIImpl(
3232
open(
3333
config_file_path,
34-
'r')
34+
'r', encoding="utf8")
3535
)
3636

3737
logging.info(

src/main/config/commit_hook_config_base_impl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CommitHookConfigDefaultImpl(CommitHookConfig):
1010
"""
1111

1212
def get_issue_url_format(self, ticket: str = "") -> str:
13-
return 'https://github.com/unthreaded/git-hooks/issues/%s' % ticket
13+
return f"https://github.com/unthreaded/git-hooks/issues/{ticket}"
1414

1515
def get_issue_pattern(self) -> str:
1616
return "GH-[0-9]+"

src/main/hook/commit_msg_hook_runner.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ def run(self) -> ExitCode:
7272
"""
7373
issue_pattern: str = self.hook_config.get_issue_pattern()
7474
issue_or_no_issue_pattern: str = \
75-
"%s|%s" % (issue_pattern, self.hook_config.get_no_issue_phrase())
75+
f"{issue_pattern}|{self.hook_config.get_no_issue_phrase()}"
7676

7777
branch_name: str = self.get_current_branch_name()
7878

7979
commit_msg_file_path: str = os.path.join(self.git_repo_path, self.git_commit_message_path)
80-
raw_commit_msg_text: str = open(commit_msg_file_path, 'r').read()
80+
81+
raw_commit_msg_text: str
82+
83+
with open(commit_msg_file_path, 'r', encoding="utf8") as commit_msg_file:
84+
raw_commit_msg_text = commit_msg_file.read()
85+
8186
commit_msg_text: str = raw_commit_msg_text.splitlines()[0]
8287

8388
issue_in_branch: str = get_left_most_issue_in_string(issue_pattern, branch_name)
@@ -117,10 +122,9 @@ def run(self) -> ExitCode:
117122
issue_in_branch,
118123
branch_name)
119124

120-
commit_msg_text = "%s: %s" % (issue_in_branch, raw_commit_msg_text)
125+
commit_msg_text = f"{issue_in_branch}: {raw_commit_msg_text}"
121126

122127
# Open file for write, which will empty the file contents
123-
commit_msg_file = open(commit_msg_file_path, 'w')
124-
commit_msg_file.write(commit_msg_text)
125-
commit_msg_file.close()
128+
with open(commit_msg_file_path, 'w', encoding="utf8") as commit_msg_file:
129+
commit_msg_file.write(commit_msg_text)
126130
return ExitCode.SUCCESS

src/test/config/test_commit_hook_config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class TestINIImplCommitHookConfig(unittest.TestCase):
3636
def setUp(self):
3737
super().setUp()
3838
self.sut = CommitHookConfigINIImpl(
39-
open(os.path.join("src", "main", CommitHookConfigINIImpl.CONFIG_FILE_NAME), 'r')
39+
# pylint: disable=consider-using-with
40+
open(os.path.join("src", "main", CommitHookConfigINIImpl.CONFIG_FILE_NAME),
41+
'r', encoding="utf8")
4042
)
4143

4244
def test_protected_branch_prefixes(self):

src/test/hook/test_commit_msg_hook_runner.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def setUp(self):
3030
def write_to_commit_file(value: str):
3131
self.message_written_to_commit_file = value
3232

33-
self.mock_commit_file.write = Mock(side_effect=write_to_commit_file)
33+
self.mock_commit_file.__enter__.return_value.write = Mock(side_effect=write_to_commit_file)
3434

3535
self.mock_open = self.create_patch('builtins.open')
3636
self.mock_open.return_value = self.mock_commit_file
@@ -52,7 +52,7 @@ def write_to_commit_file(value: str):
5252
""")
5353

5454
def set_commit_message(self, message: str):
55-
self.mock_commit_file.read.return_value = message
55+
self.mock_commit_file.__enter__.return_value.read.return_value = message
5656

5757
def set_branch_name(self, branch: str):
5858
self.mock_branch_name.return_value = bytes(branch, encoding="utf-8")
@@ -68,7 +68,7 @@ def test_no_action_taken_on_merge_or_revert(self):
6868
"MERGE changes from release/V1.2"]
6969

7070
for no_action_commit in no_action_commit_messages:
71-
print("Testing this commit message: %s" % no_action_commit)
71+
print(f"Testing this commit message: {no_action_commit}")
7272

7373
self.set_commit_message(no_action_commit)
7474

0 commit comments

Comments
 (0)