style: apply ruff format to all source files

This commit is contained in:
Кокос Артем Николаевич
2026-07-10 12:39:24 +07:00
parent 25425901b1
commit 0968560090
14 changed files with 286 additions and 107 deletions

View File

@@ -62,7 +62,9 @@ def test_cli_returns_zero_on_no_entries(mock_fetch):
@mock.patch.dict(os.environ, {}, clear=True)
def test_cli_config_error():
"""Невалидный конфиг -- выход 1."""
code = main(["--date", "2026-01-01--2026-01-31", "--config-path", "/nonexistent/config.yml"])
code = main(
["--date", "2026-01-01--2026-01-31", "--config-path", "/nonexistent/config.yml"]
)
assert code == 1
@@ -183,7 +185,7 @@ def test_cli_config_file_loading(mock_fetch, tmp_path):
"""--config загружает переменные из указанного .env-файла."""
config_path = tmp_path / "custom.env"
config_path.write_text(
"REDMINE_URL=https://config.redmine.loc\n" "REDMINE_API_KEY=config-token\n",
"REDMINE_URL=https://config.redmine.loc\nREDMINE_API_KEY=config-token\n",
encoding="utf-8",
)
mock_fetch.return_value = None
@@ -248,7 +250,9 @@ def test_cli_prints_readable_timeout_error(mock_fetch, capsys):
"""CLI выводит понятное сообщение при таймауте."""
from redmine_reporter.client import RedmineAPIError
mock_fetch.side_effect = RedmineAPIError("Redmine request timed out after 30 seconds")
mock_fetch.side_effect = RedmineAPIError(
"Redmine request timed out after 30 seconds"
)
code = main(["--date", "2026-01-01--2026-01-31"])
captured = capsys.readouterr()
assert code == 1
@@ -263,7 +267,9 @@ def test_cli_no_time_passed_to_formatter(mock_fetch, tmp_path):
mock_fetch.return_value = [(issue, 1.0)]
output = str(tmp_path / "report.xlsx")
with mock.patch("redmine_reporter.cli.get_formatter_by_extension") as mock_get_formatter:
with mock.patch(
"redmine_reporter.cli.get_formatter_by_extension"
) as mock_get_formatter:
mock_formatter = mock.MagicMock()
mock_get_formatter.return_value = mock_formatter
main(["--date", "2026-01-01--2026-01-31", "--output", output, "--no-time"])
@@ -454,7 +460,9 @@ class TestOutputPathResolution:
@mock.patch.dict(os.environ, VALID_ENV, clear=True)
@mock.patch("redmine_reporter.cli.fetch_issues_with_spent_time")
def test_output_without_extension_appends_default_format(self, mock_fetch, tmp_path):
def test_output_without_extension_appends_default_format(
self, mock_fetch, tmp_path
):
"""--output report без расширения → добавляет .xlsx."""
issue = _MockIssue()
mock_fetch.return_value = [(issue, 1.0)]
@@ -548,7 +556,9 @@ class TestCommitFlag:
mock_fetch.return_value = [(issue, 1.0)]
config_path = tmp_path / "config.yml"
config_path.write_text(yaml.dump({"period": {"precision": "date", "dynamic": True}}))
config_path.write_text(
yaml.dump({"period": {"precision": "date", "dynamic": True}})
)
with mock.patch("redmine_reporter.cli.get_formatter_by_extension") as mock_get:
mock_formatter = mock.MagicMock()
@@ -583,7 +593,9 @@ class TestCommitFlag:
mock_fetch.return_value = [(issue, 1.0)]
config_path = tmp_path / "config.yml"
config_path.write_text(yaml.dump({"period": {"precision": "datetime", "dynamic": True}}))
config_path.write_text(
yaml.dump({"period": {"precision": "datetime", "dynamic": True}})
)
with mock.patch("redmine_reporter.cli.get_formatter_by_extension") as mock_get:
mock_formatter = mock.MagicMock()
@@ -630,7 +642,9 @@ class TestCommitFlag:
@mock.patch.dict(os.environ, VALID_ENV, clear=True)
@mock.patch("redmine_reporter.cli.fetch_issues_with_spent_time")
@mock.patch("redmine_reporter.cli.save_period_to_config")
def test_commit_dynamic_false_overwrites_defaults(self, mock_save, mock_fetch, tmp_path):
def test_commit_dynamic_false_overwrites_defaults(
self, mock_save, mock_fetch, tmp_path
):
"""При dynamic=false --commit перезаписывает default_from/to."""
import yaml
@@ -638,7 +652,9 @@ class TestCommitFlag:
mock_fetch.return_value = [(issue, 1.0)]
config_path = tmp_path / "config.yml"
config_path.write_text(yaml.dump({"period": {"precision": "date", "dynamic": False}}))
config_path.write_text(
yaml.dump({"period": {"precision": "date", "dynamic": False}})
)
with mock.patch("redmine_reporter.cli.get_formatter_by_extension") as mock_get:
mock_formatter = mock.MagicMock()
@@ -663,7 +679,9 @@ class TestCommitFlag:
@mock.patch.dict(os.environ, VALID_ENV, clear=True)
@mock.patch("redmine_reporter.cli.fetch_issues_with_spent_time")
@mock.patch("redmine_reporter.cli.save_period_to_config")
def test_commit_without_output_uses_default_path(self, mock_save, mock_fetch, tmp_path):
def test_commit_without_output_uses_default_path(
self, mock_save, mock_fetch, tmp_path
):
"""--commit без --output сохраняет файл по шаблону из конфига."""
import yaml
@@ -702,7 +720,9 @@ class TestCommitFlag:
@mock.patch.dict(os.environ, VALID_ENV, clear=True)
@mock.patch("redmine_reporter.cli.fetch_issues_with_spent_time")
@mock.patch("redmine_reporter.cli.save_period_to_config")
def test_commit_prints_info_to_stderr(self, mock_save, mock_fetch, capsys, tmp_path):
def test_commit_prints_info_to_stderr(
self, mock_save, mock_fetch, capsys, tmp_path
):
"""--commit выводит сообщение о фиксации в stderr."""
import yaml
@@ -710,7 +730,9 @@ class TestCommitFlag:
mock_fetch.return_value = [(issue, 1.0)]
config_path = tmp_path / "config.yml"
config_path.write_text(yaml.dump({"period": {"precision": "date", "dynamic": True}}))
config_path.write_text(
yaml.dump({"period": {"precision": "date", "dynamic": True}})
)
with mock.patch("redmine_reporter.cli.get_formatter_by_extension") as mock_get:
mock_formatter = mock.MagicMock()
@@ -741,7 +763,9 @@ class TestCommitFlag:
mock_fetch.return_value = []
config_path = tmp_path / "config.yml"
config_path.write_text(yaml.dump({"period": {"precision": "date", "dynamic": True}}))
config_path.write_text(
yaml.dump({"period": {"precision": "date", "dynamic": True}})
)
code = main(
[
@@ -791,10 +815,13 @@ class TestSendFlag:
output = str(tmp_path / "report.xlsx")
code = main(
[
"--date", "2026-06-01--2026-06-30",
"--output", output,
"--date",
"2026-06-01--2026-06-30",
"--output",
output,
"--send",
"--config-path", str(config_path),
"--config-path",
str(config_path),
]
)
assert code == 0
@@ -804,7 +831,9 @@ class TestSendFlag:
@mock.patch("redmine_reporter.cli.fetch_issues_with_spent_time")
@mock.patch("redmine_reporter.cli.send_report")
@mock.patch("redmine_reporter.cli.get_formatter_by_extension")
def test_send_without_output_saves_to_default_path(self, mock_get, mock_send, mock_fetch, tmp_path):
def test_send_without_output_saves_to_default_path(
self, mock_get, mock_send, mock_fetch, tmp_path
):
"""--send без --output сохраняет файл по шаблону, затем отправляет."""
issue = _MockIssue()
mock_fetch.return_value = [(issue, 1.0)]
@@ -830,9 +859,11 @@ class TestSendFlag:
code = main(
[
"--date", "2026-06-01--2026-06-30",
"--date",
"2026-06-01--2026-06-30",
"--send",
"--config-path", str(config_path),
"--config-path",
str(config_path),
]
)
assert code == 0
@@ -851,10 +882,13 @@ class TestSendFlag:
code = main(
[
"--date", "2026-06-01--2026-06-30",
"--output", str(tmp_path / "report.xlsx"),
"--date",
"2026-06-01--2026-06-30",
"--output",
str(tmp_path / "report.xlsx"),
"--send",
"--config-path", str(config_path),
"--config-path",
str(config_path),
]
)
assert code == 1
@@ -865,7 +899,9 @@ class TestSendFlag:
@mock.patch("redmine_reporter.cli.fetch_issues_with_spent_time")
@mock.patch("redmine_reporter.cli.send_report")
@mock.patch("redmine_reporter.cli.get_formatter_by_extension")
def test_send_smtp_error_reported_to_stderr(self, mock_get, mock_send, mock_fetch, tmp_path, capsys):
def test_send_smtp_error_reported_to_stderr(
self, mock_get, mock_send, mock_fetch, tmp_path, capsys
):
"""Ошибка SMTP выводится в stderr, exit code 1."""
from redmine_reporter.client import RedmineAPIError
@@ -873,7 +909,9 @@ class TestSendFlag:
mock_fetch.return_value = [(issue, 1.0)]
mock_formatter = mock.MagicMock()
mock_get.return_value = mock_formatter
mock_send.side_effect = RedmineAPIError("Не удалось подключиться к SMTP-серверу bad:587")
mock_send.side_effect = RedmineAPIError(
"Не удалось подключиться к SMTP-серверу bad:587"
)
config_path = tmp_path / "config.yml"
config_path.write_text(
@@ -890,10 +928,13 @@ class TestSendFlag:
code = main(
[
"--date", "2026-06-01--2026-06-30",
"--output", str(tmp_path / "report.xlsx"),
"--date",
"2026-06-01--2026-06-30",
"--output",
str(tmp_path / "report.xlsx"),
"--send",
"--config-path", str(config_path),
"--config-path",
str(config_path),
]
)
assert code == 1
@@ -932,11 +973,14 @@ class TestSendFlag:
code = main(
[
"--date", "2026-06-01--2026-06-30",
"--output", str(tmp_path / "report.xlsx"),
"--date",
"2026-06-01--2026-06-30",
"--output",
str(tmp_path / "report.xlsx"),
"--send",
"--commit",
"--config-path", str(config_path),
"--config-path",
str(config_path),
]
)
assert code == 0