Skip to content

Commit 20d2087

Browse files
committed
💄 style(tests): format test code for consistency
1 parent 3d545a0 commit 20d2087

File tree

10 files changed

+254
-294
lines changed

10 files changed

+254
-294
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ignore = [
6363
"TRY300",
6464
"A004",
6565
"FBT003",
66+
"COM812",
6667
]
6768

6869
[tool.ruff.lint.per-file-ignores]

pyrightconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"exclude": [
3-
"tests"
4-
]
5-
}
3+
"tests",
4+
],
5+
}

tests/unit/test_add.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_add_single_file(self, mock_simple_run_command):
1313
"""Test adding a single file"""
1414
runner = CliRunner()
1515
result = runner.invoke(add, ["test.txt"])
16-
16+
1717
assert result.exit_code == 0
1818
mock_simple_run_command.assert_called_once_with("git add test.txt")
1919

@@ -22,7 +22,7 @@ def test_add_multiple_files(self, mock_simple_run_command):
2222
"""Test adding multiple files"""
2323
runner = CliRunner()
2424
result = runner.invoke(add, ["file1.txt", "file2.py", "file3.md"])
25-
25+
2626
assert result.exit_code == 0
2727
mock_simple_run_command.assert_called_once_with("git add file1.txt file2.py file3.md")
2828

@@ -31,7 +31,7 @@ def test_add_files_with_spaces(self, mock_simple_run_command):
3131
"""Test adding files with spaces in names"""
3232
runner = CliRunner()
3333
result = runner.invoke(add, ["file with spaces.txt", "another file.py"])
34-
34+
3535
assert result.exit_code == 0
3636
mock_simple_run_command.assert_called_once_with("git add file with spaces.txt another file.py")
3737

@@ -40,7 +40,7 @@ def test_add_empty_list(self, mock_simple_run_command):
4040
"""Test adding empty file list"""
4141
runner = CliRunner()
4242
result = runner.invoke(add, [])
43-
43+
4444
# Since files argument is required=True, this should fail
4545
assert result.exit_code == 2
4646
mock_simple_run_command.assert_not_called()
@@ -50,7 +50,7 @@ def test_add_files_with_special_characters(self, mock_simple_run_command):
5050
"""Test adding files with special characters"""
5151
runner = CliRunner()
5252
result = runner.invoke(add, ["file-with-dashes.txt", "file_with_underscores.py", "file.with.dots.md"])
53-
53+
5454
assert result.exit_code == 0
5555
mock_simple_run_command.assert_called_once_with("git add file-with-dashes.txt file_with_underscores.py file.with.dots.md")
5656

@@ -59,8 +59,8 @@ def test_add_propagates_exception(self, mock_simple_run_command):
5959
"""Test that exceptions from simple_run_command are propagated"""
6060
mock_simple_run_command.side_effect = Exception("Git command failed")
6161
runner = CliRunner()
62-
62+
6363
result = runner.invoke(add, ["test.txt"])
64-
64+
6565
# Exception should cause non-zero exit code
6666
assert result.exit_code != 0

tests/unit/test_changelog.py

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
"""Tests for changelog module."""
22

3-
import pytest
4-
from unittest.mock import Mock, patch, mock_open, MagicMock
5-
from pathlib import Path
3+
from unittest.mock import Mock, patch, mock_open
64
from datetime import datetime, UTC
7-
import git
8-
import re
95
from click.testing import CliRunner
106

117

@@ -92,9 +88,9 @@ def test_heading_rich_console_h1(self):
9288
heading.text = Text("Main Title")
9389
console = Console()
9490
options = Mock()
95-
91+
9692
result = list(heading.__rich_console__(console, options))
97-
93+
9894
assert len(result) == 3 # Empty line, title, empty line
9995
assert result[0].plain == "" # Empty line before
10096
assert result[1].plain == "# Main Title"
@@ -106,9 +102,9 @@ def test_heading_rich_console_h2(self):
106102
heading.text = Text("Subtitle")
107103
console = Console()
108104
options = Mock()
109-
105+
110106
result = list(heading.__rich_console__(console, options))
111-
107+
112108
assert len(result) == 2 # Empty line, title
113109
assert result[0].plain == "" # Empty line before
114110
assert result[1].plain == "## Subtitle"
@@ -119,9 +115,9 @@ def test_heading_rich_console_h3(self):
119115
heading.text = Text("Sub-subtitle")
120116
console = Console()
121117
options = Mock()
122-
118+
123119
result = list(heading.__rich_console__(console, options))
124-
120+
125121
assert len(result) == 1 # Only title
126122
assert result[0].plain == "### Sub-subtitle"
127123

@@ -845,7 +841,7 @@ def test_changelog_function_defaults(self, mock_handle):
845841
"""Test changelog function with default arguments."""
846842
runner = CliRunner()
847843
result = runner.invoke(changelog, ["."])
848-
844+
849845
assert result.exit_code == 0
850846
mock_handle.assert_called_once()
851847
# Get the actual args passed to handle_changelog - it should be a ChangelogArgs object
@@ -861,7 +857,7 @@ def test_changelog_function_with_output_flag(self, mock_handle):
861857
"""Test changelog function with output flag."""
862858
runner = CliRunner()
863859
result = runner.invoke(changelog, [".", "--output", ""])
864-
860+
865861
assert result.exit_code == 0
866862
mock_handle.assert_called_once()
867863
args = mock_handle.call_args[0][0]
@@ -872,7 +868,7 @@ def test_changelog_function_with_custom_args(self, mock_handle):
872868
"""Test changelog function with custom arguments."""
873869
runner = CliRunner()
874870
result = runner.invoke(changelog, ["/tmp", "--from", "v1.0.0", "--to", "v1.1.0", "-vv", "--output", "custom.md"]) # noqa: S108
875-
871+
876872
assert result.exit_code == 0
877873
mock_handle.assert_called_once()
878874
args = mock_handle.call_args[0][0]
@@ -1006,7 +1002,7 @@ def test_prepare_changelog_segments_no_tags(self, mock_first_commit, mock_get_la
10061002

10071003
with patch("tgit.changelog.print") as mock_print:
10081004
result = prepare_changelog_segments(mock_repo)
1009-
1005+
10101006
assert result == []
10111007
mock_print.assert_called_once_with("[yellow]No tags found in the repository.[/yellow]")
10121008

@@ -1015,24 +1011,24 @@ def test_prepare_changelog_segments_no_tags(self, mock_first_commit, mock_get_la
10151011
def test_prepare_changelog_segments_with_tags(self, mock_first_commit, mock_get_latest_tag):
10161012
"""Test prepare_changelog_segments with tags in repository."""
10171013
mock_repo = Mock()
1018-
1014+
10191015
# Create mock tags
10201016
mock_tag1 = Mock()
10211017
mock_tag1.name = "v1.0.0"
10221018
mock_tag1.commit.hexsha = "def456"
10231019
mock_tag1.commit.committed_datetime = datetime(2023, 1, 1, tzinfo=UTC)
1024-
1020+
10251021
mock_tag2 = Mock()
10261022
mock_tag2.name = "v2.0.0"
10271023
mock_tag2.commit.hexsha = "ghi789"
10281024
mock_tag2.commit.committed_datetime = datetime(2023, 2, 1, tzinfo=UTC)
1029-
1025+
10301026
mock_repo.tags = [mock_tag1, mock_tag2]
10311027
mock_first_commit.return_value = "abc123"
10321028
mock_get_latest_tag.return_value = "v2.0.0"
10331029

10341030
result = prepare_changelog_segments(mock_repo)
1035-
1031+
10361032
assert len(result) >= 1
10371033
# Should have version segments created
10381034

@@ -1041,18 +1037,18 @@ def test_prepare_changelog_segments_with_tags(self, mock_first_commit, mock_get_
10411037
def test_prepare_changelog_segments_with_current_tag(self, mock_first_commit, mock_get_latest_tag):
10421038
"""Test prepare_changelog_segments with current tag specified."""
10431039
mock_repo = Mock()
1044-
1040+
10451041
mock_tag1 = Mock()
10461042
mock_tag1.name = "v1.0.0"
10471043
mock_tag1.commit.hexsha = "def456"
10481044
mock_tag1.commit.committed_datetime = datetime(2023, 1, 1, tzinfo=UTC)
1049-
1045+
10501046
mock_repo.tags = [mock_tag1]
10511047
mock_first_commit.return_value = "abc123"
10521048
mock_get_latest_tag.return_value = "v1.0.0"
10531049

10541050
result = prepare_changelog_segments(mock_repo, current_tag="v2.0.0")
1055-
1051+
10561052
assert len(result) >= 1
10571053

10581054

@@ -1065,14 +1061,14 @@ def test_get_range_segments_basic(self, mock_prepare, mock_range):
10651061
"""Test _get_range_segments basic functionality."""
10661062
mock_repo = Mock()
10671063
mock_range.return_value = ("v1.0.0", "v2.0.0")
1068-
1064+
10691065
# Create mock segments
10701066
segment1 = VersionSegment(from_hash="abc123", to_hash="def456", from_name="v1.0.0", to_name="v1.1.0")
10711067
segment2 = VersionSegment(from_hash="def456", to_hash="ghi789", from_name="v1.1.0", to_name="v2.0.0")
10721068
mock_prepare.return_value = [segment1, segment2]
1073-
1069+
10741070
result = _get_range_segments(mock_repo, "v1.0.0", "v2.0.0")
1075-
1071+
10761072
assert len(result) >= 0
10771073

10781074

@@ -1082,9 +1078,9 @@ class TestGenerateChangelogsFromSegments:
10821078
def test_generate_changelogs_from_segments_empty(self):
10831079
"""Test _generate_changelogs_from_segments with empty segments."""
10841080
mock_repo = Mock()
1085-
1081+
10861082
result = _generate_changelogs_from_segments(mock_repo, [])
1087-
1083+
10881084
assert result == ""
10891085

10901086
@patch("tgit.changelog._process_commits")
@@ -1095,16 +1091,16 @@ def test_generate_changelogs_from_segments_with_segments(self, mock_uri_safe, mo
10951091
"""Test _generate_changelogs_from_segments with actual segments."""
10961092
mock_repo = Mock()
10971093
mock_repo.iter_commits.return_value = [Mock(), Mock()]
1098-
1094+
10991095
mock_process.return_value = [Mock(), Mock()]
11001096
mock_group.return_value = {"feat": [Mock()]}
11011097
mock_generate.return_value = "## v1.1.0\n\n### Features\n\n- New feature\n\n"
11021098
mock_uri_safe.return_value = "https://github.com/user/repo"
1103-
1099+
11041100
segment = VersionSegment(from_hash="abc123", to_hash="def456", from_name="v1.0.0", to_name="v1.1.0")
1105-
1101+
11061102
result = _generate_changelogs_from_segments(mock_repo, [segment])
1107-
1103+
11081104
assert "v1.1.0" in result
11091105

11101106

@@ -1115,29 +1111,29 @@ def test_get_remote_uri_safe_success(self):
11151111
"""Test _get_remote_uri_safe when remote URL is available."""
11161112
mock_repo = Mock()
11171113
mock_repo.remote.return_value.url = "https://github.com/user/repo.git"
1118-
1114+
11191115
with patch("tgit.changelog.get_remote_uri") as mock_get_uri:
11201116
mock_get_uri.return_value = "https://github.com/user/repo"
11211117
result = _get_remote_uri_safe(mock_repo)
1122-
1118+
11231119
assert result == "https://github.com/user/repo"
11241120
mock_get_uri.assert_called_once_with("https://github.com/user/repo.git")
11251121

11261122
def test_get_remote_uri_safe_value_error(self):
11271123
"""Test _get_remote_uri_safe when ValueError is raised."""
11281124
mock_repo = Mock()
11291125
mock_repo.remote.side_effect = ValueError("Origin not found")
1130-
1126+
11311127
result = _get_remote_uri_safe(mock_repo)
1132-
1128+
11331129
assert result is None
11341130

11351131

11361132
class TestGetChangelogByRange:
11371133
"""Test get_changelog_by_range function."""
11381134

11391135
@patch("tgit.changelog.get_commits")
1140-
@patch("tgit.changelog.group_commits_by_type")
1136+
@patch("tgit.changelog.group_commits_by_type")
11411137
@patch("tgit.changelog.generate_changelog")
11421138
@patch("tgit.changelog.get_remote_uri")
11431139
def test_get_changelog_by_range_success(self, mock_get_uri, mock_generate, mock_group, mock_commits):
@@ -1148,10 +1144,10 @@ def test_get_changelog_by_range_success(self, mock_get_uri, mock_generate, mock_
11481144
mock_group.return_value = {"feat": [Mock()]}
11491145
mock_generate.return_value = "changelog content"
11501146
mock_get_uri.return_value = "https://github.com/user/repo"
1151-
1147+
11521148
result = get_changelog_by_range(mock_repo, "v1.0.0", "v2.0.0")
1153-
1149+
11541150
assert result == "changelog content"
1155-
mock_commits.assert_called_once_with(mock_repo, "v1.0.0", "v2.0.0")
1151+
mock_commits.assert_called_once_with(mock_repo, "v1.0.0", "v2.0.0")
11561152
mock_group.assert_called_once()
11571153
mock_generate.assert_called_once()

tests/unit/test_cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def test_version_callback_true(self, mock_print, mock_version):
3232
mock_ctx = MagicMock()
3333
mock_ctx.resilient_parsing = False
3434
mock_param = MagicMock()
35-
35+
3636
version_callback(ctx=mock_ctx, _param=mock_param, value=True)
37-
37+
3838
mock_version.assert_called_once_with("tgit")
3939
mock_print.assert_called_once_with("TGIT - ver.1.0.0", highlight=False)
4040
mock_ctx.exit.assert_called_once()
@@ -46,9 +46,9 @@ def test_version_callback_false(self, mock_print, mock_version):
4646
mock_ctx = MagicMock()
4747
mock_ctx.resilient_parsing = False
4848
mock_param = MagicMock()
49-
49+
5050
version_callback(ctx=mock_ctx, _param=mock_param, value=False)
51-
51+
5252
mock_version.assert_not_called()
5353
mock_print.assert_not_called()
5454
mock_ctx.exit.assert_not_called()
@@ -58,10 +58,10 @@ def test_app_starts_openai_import_thread(self, mock_thread):
5858
"""Test that app starts a thread for OpenAI import"""
5959
mock_thread_instance = MagicMock()
6060
mock_thread.return_value = mock_thread_instance
61-
61+
6262
# Directly call the app function to test the callback
6363
app.callback()
64-
64+
6565
# The app should run the callback and start the thread
6666
mock_thread.assert_called_once()
6767
mock_thread_instance.start.assert_called_once()
@@ -71,14 +71,14 @@ def test_openai_import_function(self):
7171
# We can't easily test the actual import function directly since it's nested,
7272
# but we can test that threading works and doesn't raise exceptions
7373
import_called = threading.Event()
74-
74+
7575
def mock_import():
7676
import_called.set()
77-
77+
7878
thread = threading.Thread(target=mock_import)
7979
thread.start()
8080
thread.join(timeout=1)
81-
81+
8282
assert import_called.is_set()
8383

8484
def test_app_callback_registration(self):

0 commit comments

Comments
 (0)