Public Access
DEVX-60: feat: add create-task, create-pr, pre-push-check tools and devx.mak fragment
Post-merge / detect-type (push) Successful in 6s
Post-merge / validate-commit-msg (push) Successful in 6s
Post-merge / configure-repo (push) Successful in 9s
Post-merge / release (push) Successful in 1m0s
Post-merge / vikunja (push) Successful in 14s
Post-merge / sync-wiki (push) Successful in 59s
Post-merge / badges (push) Successful in 1m12s
Post-merge / detect-type (push) Successful in 6s
Post-merge / validate-commit-msg (push) Successful in 6s
Post-merge / configure-repo (push) Successful in 9s
Post-merge / release (push) Successful in 1m0s
Post-merge / vikunja (push) Successful in 14s
Post-merge / sync-wiki (push) Successful in 59s
Post-merge / badges (push) Successful in 1m12s
This commit was merged in pull request #98.
This commit is contained in:
@@ -137,6 +137,19 @@ class TestGiteaClient:
|
||||
assert result is None
|
||||
client.create_label.assert_not_called()
|
||||
|
||||
def test_ensure_label_creates_when_others_exist(self) -> None:
|
||||
"""When labels exist but none match the target name, create a new one."""
|
||||
client = GiteaClient("https://git.example.com", "tok", "owner", "repo")
|
||||
client.list_labels = MagicMock(
|
||||
return_value=[{"name": "bug", "color": "ff0000"}, {"name": "docs", "color": "007ec6"}]
|
||||
)
|
||||
client.create_label = MagicMock(return_value={"name": "ready-to-merge", "color": "2ecc71"})
|
||||
|
||||
result = client.ensure_label("ready-to-merge", "2ecc71", "desc")
|
||||
assert result is not None
|
||||
assert result["name"] == "ready-to-merge"
|
||||
client.create_label.assert_called_once_with("ready-to-merge", "2ecc71", "desc")
|
||||
|
||||
def test_list_branch_protections(self) -> None:
|
||||
client = GiteaClient("https://git.example.com", "tok", "owner", "repo")
|
||||
client._session.request = MagicMock(
|
||||
@@ -196,6 +209,18 @@ class TestGiteaClient:
|
||||
expected_update = {k: v for k, v in TEST_BP_CONFIG.items() if k != "branch_name"}
|
||||
client.update_branch_protection.assert_called_once_with("master", expected_update)
|
||||
|
||||
def test_ensure_branch_protection_creates_when_none_match(self) -> None:
|
||||
"""When existing protections exist but none match the target branch, create a new one."""
|
||||
client = GiteaClient("https://git.example.com", "tok", "owner", "repo")
|
||||
client.list_branch_protections = MagicMock(
|
||||
return_value=[{"branch_name": "develop"}, {"branch_name": "staging"}]
|
||||
)
|
||||
client.create_branch_protection = MagicMock(return_value={"id": 5, "branch_name": "master"})
|
||||
|
||||
result = client.ensure_branch_protection("master", TEST_BP_CONFIG)
|
||||
assert result["id"] == 5
|
||||
client.create_branch_protection.assert_called_once_with(TEST_BP_CONFIG)
|
||||
|
||||
def test_merge_pr(self) -> None:
|
||||
client = GiteaClient("https://git.example.com", "tok", "owner", "repo")
|
||||
client._session.request = MagicMock(return_value=_mock_response())
|
||||
@@ -248,6 +273,37 @@ class TestGiteaClient:
|
||||
timeout=DEFAULT_TIMEOUT,
|
||||
)
|
||||
|
||||
def test_create_pr(self) -> None:
|
||||
client = GiteaClient("https://git.example.com", "tok", "owner", "repo")
|
||||
client._session.request = MagicMock(
|
||||
return_value=_mock_response({"number": 15, "html_url": "https://git.example.com/pr/15"})
|
||||
)
|
||||
result = client.create_pr(title="DEVX-42: Add feature", head="DEVX-42-fix", body="desc")
|
||||
assert result["number"] == 15
|
||||
client._session.request.assert_called_once_with(
|
||||
"POST",
|
||||
"https://git.example.com/repos/owner/repo/pulls",
|
||||
timeout=DEFAULT_TIMEOUT,
|
||||
json={"title": "DEVX-42: Add feature", "head": "DEVX-42-fix", "base": "master", "body": "desc"},
|
||||
)
|
||||
|
||||
def test_create_pr_no_body(self) -> None:
|
||||
client = GiteaClient("https://git.example.com", "tok", "owner", "repo")
|
||||
client._session.request = MagicMock(
|
||||
return_value=_mock_response({"number": 16, "html_url": "https://git.example.com/pr/16"})
|
||||
)
|
||||
result = client.create_pr(title="DEVX-43: Fix bug", head="DEVX-43-fix")
|
||||
assert result["number"] == 16
|
||||
call_kwargs = client._session.request.call_args.kwargs
|
||||
assert "body" not in call_kwargs["json"]
|
||||
|
||||
def test_create_pr_custom_base(self) -> None:
|
||||
client = GiteaClient("https://git.example.com", "tok", "owner", "repo")
|
||||
client._session.request = MagicMock(return_value=_mock_response({"number": 17}))
|
||||
client.create_pr(title="Test", head="branch", base="develop")
|
||||
call_kwargs = client._session.request.call_args.kwargs
|
||||
assert call_kwargs["json"]["base"] == "develop"
|
||||
|
||||
def test_get_pr_files(self) -> None:
|
||||
client = GiteaClient("https://git.example.com", "tok", "owner", "repo")
|
||||
client._session.request = MagicMock(
|
||||
@@ -701,6 +757,30 @@ class TestVikunjaClient:
|
||||
assert exc_info.value.status == 0
|
||||
assert client._session.request.call_count == 3 # MAX_RETRIES
|
||||
|
||||
def test_vikunja_create_task(self) -> None:
|
||||
client = VikunjaClient("https://work.example.com", "tok")
|
||||
client._session.request = MagicMock(
|
||||
return_value=_mock_response({"id": 1, "identifier": "DEVX-1", "title": "Test"})
|
||||
)
|
||||
result = client.create_task(6, "Test", "<p>desc</p>")
|
||||
assert result["identifier"] == "DEVX-1"
|
||||
client._session.request.assert_called_once_with(
|
||||
"PUT",
|
||||
"https://work.example.com/projects/6/tasks",
|
||||
timeout=DEFAULT_TIMEOUT,
|
||||
json={"title": "Test", "description": "<p>desc</p>"},
|
||||
)
|
||||
|
||||
def test_vikunja_create_task_no_description(self) -> None:
|
||||
client = VikunjaClient("https://work.example.com", "tok")
|
||||
client._session.request = MagicMock(
|
||||
return_value=_mock_response({"id": 2, "identifier": "DEVX-2", "title": "No desc"})
|
||||
)
|
||||
result = client.create_task(6, "No desc")
|
||||
assert result["id"] == 2
|
||||
call_kwargs = client._session.request.call_args.kwargs
|
||||
assert call_kwargs["json"]["description"] == ""
|
||||
|
||||
|
||||
class TestIsRetryable:
|
||||
def test_connection_error_is_retryable(self) -> None:
|
||||
|
||||
@@ -47,6 +47,22 @@ class TestReadTaskid:
|
||||
captured = capsys.readouterr()
|
||||
assert "WARNING" not in captured.out
|
||||
|
||||
def test_no_warning_when_taskid_file_matches_branch(self, tmp_path, monkeypatch, capsys) -> None: # type: ignore[no-untyped-def]
|
||||
"""No warning when .taskid file content matches the branch task ID."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
(tmp_path / ".taskid").write_text("DEVX-19\n")
|
||||
assert read_taskid("DEVX-19-fix-bug") == "DEVX-19"
|
||||
captured = capsys.readouterr()
|
||||
assert "WARNING" not in captured.out
|
||||
|
||||
def test_no_warning_when_taskid_file_empty(self, tmp_path, monkeypatch, capsys) -> None: # type: ignore[no-untyped-def]
|
||||
"""No warning when .taskid file exists but is empty."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
(tmp_path / ".taskid").write_text("\n")
|
||||
assert read_taskid("DEVX-19-fix-bug") == "DEVX-19"
|
||||
captured = capsys.readouterr()
|
||||
assert "WARNING" not in captured.out
|
||||
|
||||
|
||||
# -- extract_task_id (legacy fallback) --
|
||||
|
||||
|
||||
@@ -162,6 +162,15 @@ class TestClassifierConfig:
|
||||
assert config.user_facing_overrides == []
|
||||
assert config.tags == {}
|
||||
|
||||
def test_from_pyproject_dedupes_existing_default(self, tmp_path: Path) -> None:
|
||||
"""Project infrastructure patterns already in defaults are not duplicated."""
|
||||
pyproject = tmp_path / "pyproject.toml"
|
||||
pyproject.write_text('[tool.devx.classify]\ninfrastructure = [".gitea/**", "scripts/**"]\n')
|
||||
config = ClassifierConfig.from_pyproject(str(pyproject))
|
||||
# .gitea/** should appear only once (deduplicated with defaults)
|
||||
assert config.infrastructure.count(".gitea/**") == 1
|
||||
assert "scripts/**" in config.infrastructure
|
||||
|
||||
def test_defaults_are_empty_for_bare_constructor(self) -> None:
|
||||
"""ClassifierConfig() without from_pyproject has empty lists."""
|
||||
config = ClassifierConfig()
|
||||
@@ -515,6 +524,27 @@ class TestMain:
|
||||
assert "Ansible files" in result.output
|
||||
assert "ansible/tasks/main.yml" in result.output
|
||||
|
||||
@patch("devx.ci.classify_changes._get_classifier")
|
||||
@patch("devx.ci.classify_changes.get_changed_files")
|
||||
@patch("devx.ci.classify_changes.get_latest_tag", return_value="v0.3.0")
|
||||
def test_default_mode_skips_empty_tag(
|
||||
self, mock_tag: MagicMock, mock_changes: MagicMock, mock_clf: MagicMock
|
||||
) -> None:
|
||||
"""Tags with no matching files are skipped in default mode output."""
|
||||
mock_changes.return_value = ["ansible/tasks/main.yml"]
|
||||
mock_clf.return_value = ChangeClassifier(
|
||||
ClassifierConfig(
|
||||
infrastructure=[".gitea/**"],
|
||||
tags={"ansible": ["ansible/**"], "docs": ["docs/**"]},
|
||||
)
|
||||
)
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, [])
|
||||
assert result.exit_code == 0
|
||||
assert "Ansible files" in result.output
|
||||
# docs tag has no matching files — should not appear
|
||||
assert "Docs files" not in result.output
|
||||
|
||||
@patch("devx.ci.classify_changes.get_latest_tag", return_value="")
|
||||
def test_no_tags_non_quiet(self, mock_tag: MagicMock) -> None:
|
||||
runner = CliRunner()
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
"""Unit tests for devx.tools.create_pr."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import click
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
from devx.tools.create_pr import (
|
||||
cli,
|
||||
create_pr,
|
||||
extract_task_id,
|
||||
find_existing_pr,
|
||||
get_repo_name,
|
||||
get_vikunja_task_title,
|
||||
)
|
||||
|
||||
|
||||
class TestExtractTaskId:
|
||||
def test_valid(self) -> None:
|
||||
assert extract_task_id("DEVX-42-fix") == "DEVX-42"
|
||||
|
||||
def test_invalid(self) -> None:
|
||||
assert extract_task_id("feature") == ""
|
||||
|
||||
|
||||
class TestGetRepoName:
|
||||
@patch.dict("os.environ", {"DEVX_REPO_NAME": "infra"})
|
||||
def test_from_env(self) -> None:
|
||||
assert get_repo_name() == "infra"
|
||||
|
||||
@patch.dict("os.environ", {"GITHUB_REPOSITORY": "oblachno/infra"}, clear=True)
|
||||
def test_from_github(self) -> None:
|
||||
assert get_repo_name() == "infra"
|
||||
|
||||
@patch.dict("os.environ", {}, clear=True)
|
||||
def test_missing_raises(self) -> None:
|
||||
with pytest.raises(click.ClickException, match="Repository name"):
|
||||
get_repo_name()
|
||||
|
||||
|
||||
class TestGetVikunjaTaskTitle:
|
||||
@patch("devx.tools.create_pr.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_found(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.list_project_tasks.return_value = [{"identifier": "DEVX-42", "title": "Add feature"}]
|
||||
mock_client_cls.return_value = mock_client
|
||||
assert get_vikunja_task_title("DEVX-42") == "Add feature"
|
||||
|
||||
@patch.dict("os.environ", {}, clear=True)
|
||||
def test_no_token(self) -> None:
|
||||
with pytest.raises(click.ClickException, match="VIKUNJA_TOKEN"):
|
||||
get_vikunja_task_title("DEVX-42")
|
||||
|
||||
@patch("devx.tools.create_pr.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_not_found(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.list_project_tasks.return_value = []
|
||||
mock_client_cls.return_value = mock_client
|
||||
with pytest.raises(click.ClickException, match="Could not find"):
|
||||
get_vikunja_task_title("DEVX-42")
|
||||
|
||||
@patch("devx.tools.create_pr.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_pagination_not_found(self, mock_client_cls: MagicMock) -> None:
|
||||
from devx.config import DEFAULT_PER_PAGE
|
||||
|
||||
mock_client = MagicMock()
|
||||
page1 = [{"identifier": f"OTHER-{i}"} for i in range(DEFAULT_PER_PAGE)]
|
||||
page2 = [{"identifier": "OTHER-99"}]
|
||||
mock_client.list_project_tasks.side_effect = [page1, page2]
|
||||
mock_client_cls.return_value = mock_client
|
||||
with pytest.raises(click.ClickException, match="Could not find"):
|
||||
get_vikunja_task_title("DEVX-42")
|
||||
|
||||
|
||||
class TestFindExistingPr:
|
||||
def test_found(self) -> None:
|
||||
client = MagicMock()
|
||||
client.list_prs.return_value = [{"head": {"ref": "DEVX-42-fix"}, "number": 10}]
|
||||
result = find_existing_pr(client, "DEVX-42-fix")
|
||||
assert result is not None
|
||||
assert result["number"] == 10
|
||||
|
||||
def test_not_found(self) -> None:
|
||||
client = MagicMock()
|
||||
client.list_prs.return_value = [{"head": {"ref": "other"}, "number": 10}]
|
||||
result = find_existing_pr(client, "DEVX-42-fix")
|
||||
assert result is None
|
||||
|
||||
|
||||
class TestCreatePr:
|
||||
@patch("devx.tools.create_pr.GiteaClient")
|
||||
@patch("devx.tools.create_pr.get_vikunja_task_title", return_value="Add feature")
|
||||
@patch("devx.tools.create_pr.find_existing_pr", return_value=None)
|
||||
@patch.dict("os.environ", {"REPO_TOKEN": "tok"})
|
||||
def test_creates_new_pr(self, mock_find: MagicMock, mock_title: MagicMock, mock_gitea: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.create_pr.return_value = {"number": 15, "html_url": "https://git.example.com/pr/15"}
|
||||
mock_gitea.return_value = mock_client
|
||||
result = create_pr("DEVX-42-fix", "master", "body", "owner", "repo")
|
||||
assert result["number"] == 15
|
||||
mock_client.create_pr.assert_called_once_with(
|
||||
title="DEVX-42: Add feature",
|
||||
head="DEVX-42-fix",
|
||||
base="master",
|
||||
body="body",
|
||||
)
|
||||
|
||||
@patch("devx.tools.create_pr.GiteaClient")
|
||||
@patch("devx.tools.create_pr.get_vikunja_task_title", return_value="Add feature")
|
||||
@patch("devx.tools.create_pr.find_existing_pr")
|
||||
@patch.dict("os.environ", {"REPO_TOKEN": "tok"})
|
||||
def test_existing_pr_idempotent(self, mock_find: MagicMock, mock_title: MagicMock, mock_gitea: MagicMock) -> None:
|
||||
mock_find.return_value = {"number": 10, "html_url": "https://git.example.com/pr/10"}
|
||||
mock_client = MagicMock()
|
||||
mock_gitea.return_value = mock_client
|
||||
result = create_pr("DEVX-42-fix", "master", "", "owner", "repo")
|
||||
assert result["number"] == 10
|
||||
mock_client.create_pr.assert_not_called()
|
||||
|
||||
@patch.dict("os.environ", {}, clear=True)
|
||||
def test_no_repo_token(self) -> None:
|
||||
with pytest.raises(click.ClickException, match="REPO_TOKEN"):
|
||||
create_pr("DEVX-42-fix", "master", "", "owner", "repo")
|
||||
|
||||
@patch.dict("os.environ", {"REPO_TOKEN": "tok"})
|
||||
def test_no_task_id_in_branch(self) -> None:
|
||||
with pytest.raises(click.ClickException, match="does not contain a task ID"):
|
||||
create_pr("feature-branch", "master", "", "owner", "repo")
|
||||
|
||||
|
||||
class TestCli:
|
||||
@patch("devx.tools.create_pr.create_pr")
|
||||
@patch("devx.tools.create_pr.subprocess.run")
|
||||
@patch("devx.tools.create_pr.REPO_OWNER", "owner")
|
||||
@patch("devx.tools.create_pr.get_repo_name", return_value="repo")
|
||||
def test_auto_detect_branch(self, mock_repo: MagicMock, mock_run: MagicMock, mock_create: MagicMock) -> None:
|
||||
mock_run.return_value = MagicMock(stdout="DEVX-42-fix\n", returncode=0)
|
||||
mock_create.return_value = {"number": 1}
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, [])
|
||||
assert result.exit_code == 0
|
||||
mock_create.assert_called_once_with("DEVX-42-fix", "master", "", "owner", "repo")
|
||||
|
||||
@patch("devx.tools.create_pr.create_pr")
|
||||
@patch("devx.tools.create_pr.REPO_OWNER", "owner")
|
||||
@patch("devx.tools.create_pr.get_repo_name", return_value="repo")
|
||||
def test_explicit_branch(self, mock_repo: MagicMock, mock_create: MagicMock) -> None:
|
||||
mock_create.return_value = {"number": 1}
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--branch", "DEVX-42-fix"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
@patch("devx.tools.create_pr.create_pr")
|
||||
@patch("devx.tools.create_pr.REPO_OWNER", "owner")
|
||||
@patch("devx.tools.create_pr.get_repo_name", return_value="repo")
|
||||
def test_body_from_stdin(self, mock_repo: MagicMock, mock_create: MagicMock) -> None:
|
||||
mock_create.return_value = {"number": 1}
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--branch", "DEVX-42-fix", "--body", "-"], input="PR body text")
|
||||
assert result.exit_code == 0
|
||||
mock_create.assert_called_once()
|
||||
assert mock_create.call_args.args[2] == "PR body text"
|
||||
|
||||
@patch("devx.tools.create_pr.REPO_OWNER", "")
|
||||
@patch("devx.tools.create_pr.get_repo_name", return_value="repo")
|
||||
def test_missing_owner(self, mock_repo: MagicMock) -> None:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--branch", "DEVX-42-fix"])
|
||||
assert result.exit_code != 0
|
||||
assert "owner" in result.output.lower()
|
||||
|
||||
@patch("devx.tools.create_pr.create_pr")
|
||||
@patch("devx.tools.create_pr.get_repo_name", return_value="repo")
|
||||
def test_explicit_owner(self, mock_repo: MagicMock, mock_create: MagicMock) -> None:
|
||||
mock_create.return_value = {"number": 1}
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--branch", "DEVX-42-fix", "--owner", "custom"])
|
||||
assert result.exit_code == 0
|
||||
mock_create.assert_called_once_with("DEVX-42-fix", "master", "", "custom", "repo")
|
||||
|
||||
@patch("devx.tools.create_pr.subprocess.run")
|
||||
@patch("devx.tools.create_pr.REPO_OWNER", "owner")
|
||||
@patch("devx.tools.create_pr.get_repo_name", return_value="repo")
|
||||
def test_git_detect_failure(self, mock_repo: MagicMock, mock_run: MagicMock) -> None:
|
||||
mock_run.return_value = MagicMock(stdout="", stderr="fatal: not a git repository", returncode=128)
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, [])
|
||||
assert result.exit_code != 0
|
||||
assert "Could not detect" in result.output
|
||||
@@ -0,0 +1,83 @@
|
||||
"""Unit tests for devx.tools.create_task."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from devx.tools.create_task import cli
|
||||
|
||||
|
||||
class TestCreateTaskCli:
|
||||
@patch("devx.tools.create_task.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_success(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.create_task.return_value = {"identifier": "DEVX-60", "id": 60}
|
||||
mock_client_cls.return_value = mock_client
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--title", "Add feature X"])
|
||||
assert result.exit_code == 0
|
||||
assert "DEVX-60" in result.output
|
||||
mock_client.create_task.assert_called_once()
|
||||
|
||||
@patch.dict("os.environ", {}, clear=True)
|
||||
def test_missing_token(self) -> None:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--title", "Add feature X"])
|
||||
assert result.exit_code != 0
|
||||
assert "VIKUNJA_TOKEN" in result.output
|
||||
|
||||
@patch("devx.tools.create_task.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_with_description(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.create_task.return_value = {"identifier": "DEVX-61", "id": 61}
|
||||
mock_client_cls.return_value = mock_client
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli,
|
||||
["--title", "Add feature Y", "--description", "<p>desc</p>"],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
call_args = mock_client.create_task.call_args
|
||||
assert call_args.args[1] == "Add feature Y"
|
||||
assert call_args.args[2] == "<p>desc</p>"
|
||||
|
||||
@patch("devx.tools.create_task.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_description_from_stdin(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.create_task.return_value = {"identifier": "DEVX-62", "id": 62}
|
||||
mock_client_cls.return_value = mock_client
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli,
|
||||
["--title", "Add feature Z", "--description", "-"],
|
||||
input="<p>stdin desc</p>",
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
mock_client.create_task.assert_called_once()
|
||||
call_args = mock_client.create_task.call_args
|
||||
assert call_args.args[2] == "<p>stdin desc</p>"
|
||||
|
||||
@patch("devx.tools.create_task.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_custom_project_id(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.create_task.return_value = {"identifier": "GRM-10", "id": 10}
|
||||
mock_client_cls.return_value = mock_client
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--title", "Task", "--project-id", "3"])
|
||||
assert result.exit_code == 0
|
||||
mock_client.create_task.assert_called_once_with(3, "Task", "")
|
||||
|
||||
@patch("devx.tools.create_task.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_no_identifier_in_response(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.create_task.return_value = {"id": 99}
|
||||
mock_client_cls.return_value = mock_client
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--title", "Task"])
|
||||
assert result.exit_code == 0
|
||||
assert "id=99" in result.output
|
||||
@@ -237,3 +237,15 @@ class TestMain:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--github-output"])
|
||||
assert result.exit_code != 0
|
||||
|
||||
@patch("devx.ci.discover_runners.get_runner_count", return_value=2)
|
||||
def test_explicit_owner_and_repo(self, mock_count: MagicMock) -> None:
|
||||
"""When --owner and --repo are provided, env vars are not used."""
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--owner", "myorg", "--repo", "myrepo"])
|
||||
assert result.exit_code == 0
|
||||
mock_count.assert_called_once()
|
||||
# Verify owner/repo passed through
|
||||
args, kwargs = mock_count.call_args
|
||||
assert "myorg" in args
|
||||
assert "myrepo" in args
|
||||
|
||||
@@ -46,6 +46,21 @@ class TestExtractCliCommands:
|
||||
commands = extract_cli_commands()
|
||||
assert "my_command" in commands
|
||||
|
||||
def test_command_decorator_no_def_fallback(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When a command decorator has no name and no following def, it is skipped."""
|
||||
from devx.ci import doc_coverage
|
||||
|
||||
fake_cli = tmp_path / "cli.py"
|
||||
# The last @cli.command() has no explicit name and no def statement after it
|
||||
fake_cli.write_text(
|
||||
"@click.group()\ndef cli():\n pass\n@cli.command()\ndef real_cmd():\n pass\n@cli.command()\npass\n"
|
||||
)
|
||||
monkeypatch.setattr(doc_coverage, "CLI_FILE", fake_cli)
|
||||
commands = extract_cli_commands()
|
||||
# real_cmd should be found via def fallback; the bare @cli.command() is skipped
|
||||
assert "real_cmd" in commands
|
||||
assert "pass" not in commands
|
||||
|
||||
|
||||
class TestCheckCommandDocumented:
|
||||
def test_finds_command_in_heading(self) -> None:
|
||||
|
||||
@@ -97,6 +97,15 @@ class TestDetectCoverageTarget:
|
||||
def test_returns_none_when_no_package(self, tmp_path: Path) -> None: # type: ignore[no-untyped-def]
|
||||
assert detect_coverage_target(tmp_path) is None
|
||||
|
||||
def test_pyproject_without_cov_falls_back_to_package(self, tmp_path: Path) -> None: # type: ignore[no-untyped-def]
|
||||
"""When pyproject exists but has no --cov=, falls back to package name."""
|
||||
src = tmp_path / "src"
|
||||
pkg = src / "mypkg"
|
||||
pkg.mkdir(parents=True)
|
||||
(pkg / "__init__.py").write_text('__version__ = "1.0"\n')
|
||||
(tmp_path / "pyproject.toml").write_text('[tool.pytest.ini_options]\naddopts = "-ra"\n')
|
||||
assert detect_coverage_target(tmp_path) == "src/mypkg"
|
||||
|
||||
|
||||
class TestDetectTestpaths:
|
||||
def test_parses_from_pyproject(self, tmp_path: Path) -> None: # type: ignore[no-untyped-def]
|
||||
@@ -112,6 +121,14 @@ class TestDetectTestpaths:
|
||||
(tmp_path / "pyproject.toml").write_text('[tool.pytest.ini_options]\ntestpaths = ["tests", "nonexistent"]\n')
|
||||
assert detect_testpaths(tmp_path) == ["tests"]
|
||||
|
||||
def test_all_paths_nonexistent_falls_back_to_tests_dir(self, tmp_path: Path) -> None: # type: ignore[no-untyped-def]
|
||||
"""When all testpaths are non-existent, falls back to tests/ directory."""
|
||||
(tmp_path / "tests").mkdir()
|
||||
(tmp_path / "pyproject.toml").write_text(
|
||||
'[tool.pytest.ini_options]\ntestpaths = ["nonexistent1", "nonexistent2"]\n'
|
||||
)
|
||||
assert detect_testpaths(tmp_path) == ["tests"]
|
||||
|
||||
def test_falls_back_to_tests_dir(self, tmp_path: Path) -> None: # type: ignore[no-untyped-def]
|
||||
(tmp_path / "tests").mkdir()
|
||||
assert detect_testpaths(tmp_path) == ["tests"]
|
||||
|
||||
@@ -97,6 +97,11 @@ class TestBuildEnvForPair:
|
||||
env = build_env_for_pair("default|ubuntu-2204|img:latest|", {"MOLECULE_PLATFORM_COMMAND": "old"})
|
||||
assert "MOLECULE_PLATFORM_COMMAND" not in env
|
||||
|
||||
def test_preserves_existing_molecule_home(self) -> None:
|
||||
"""When MOLECULE_HOME is already set, it is not overridden."""
|
||||
env = build_env_for_pair("default|ubuntu-2204|img:latest|", {"MOLECULE_HOME": "/custom/home"})
|
||||
assert env["MOLECULE_HOME"] == "/custom/home"
|
||||
|
||||
|
||||
class TestPollForOtherFailures:
|
||||
def test_sets_failed_event_when_other_runner_fails(self) -> None:
|
||||
|
||||
@@ -208,3 +208,14 @@ class TestMain:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--github-output"])
|
||||
assert result.exit_code != 0
|
||||
|
||||
@patch("devx.molecule.discover_runners.get_runner_count", return_value=2)
|
||||
def test_explicit_owner_and_repo(self, mock_count: MagicMock) -> None:
|
||||
"""When --owner and --repo are provided, env vars are not used."""
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--owner", "myorg", "--repo", "myrepo"])
|
||||
assert result.exit_code == 0
|
||||
mock_count.assert_called_once()
|
||||
args, kwargs = mock_count.call_args
|
||||
assert "myorg" in args
|
||||
assert "myrepo" in args
|
||||
|
||||
@@ -129,6 +129,18 @@ class TestCheckArchitectureCompliance:
|
||||
assert result.has_issues
|
||||
assert "os.system" in result.issues[0]["body"]
|
||||
|
||||
def test_malformed_hunk_header_no_line_number(self) -> None:
|
||||
"""A @@ header without a +N line number is handled gracefully."""
|
||||
result = ReviewResult()
|
||||
files = [
|
||||
{
|
||||
"filename": "src/devx/cli.py",
|
||||
"patch": "@@ -1,2 @@\n+ subprocess.run(['ls'])\n",
|
||||
}
|
||||
]
|
||||
check_architecture_compliance(files, result)
|
||||
assert result.has_issues
|
||||
|
||||
|
||||
class TestCheckBestPractices:
|
||||
def test_print_triggers_warning(self) -> None:
|
||||
@@ -190,6 +202,19 @@ class TestCheckBestPractices:
|
||||
check_best_practices(files, result)
|
||||
assert not result.has_issues
|
||||
|
||||
def test_malformed_hunk_header_no_line_number(self) -> None:
|
||||
"""A @@ header without a +N line number is handled gracefully."""
|
||||
result = ReviewResult()
|
||||
files = [
|
||||
{
|
||||
"filename": "src/devx/cli.py",
|
||||
"patch": "@@ -1,2 @@\n+ print('hello')\n",
|
||||
}
|
||||
]
|
||||
check_best_practices(files, result)
|
||||
assert result.has_issues
|
||||
assert "print()" in result.issues[0]["body"]
|
||||
|
||||
|
||||
class TestCheckSecurity:
|
||||
def test_hardcoded_secret_triggers_error(self) -> None:
|
||||
@@ -239,6 +264,19 @@ class TestCheckSecurity:
|
||||
check_security(files, result)
|
||||
assert not result.has_issues
|
||||
|
||||
def test_malformed_hunk_header_no_line_number(self) -> None:
|
||||
"""A @@ header without a +N line number is handled gracefully."""
|
||||
result = ReviewResult()
|
||||
files = [
|
||||
{
|
||||
"filename": "src/devx/config.py",
|
||||
"patch": "@@ -1,2 @@\n+ token = 'abc123secrettoken456'\n",
|
||||
}
|
||||
]
|
||||
check_security(files, result)
|
||||
assert result.has_issues
|
||||
assert "secret" in result.issues[0]["body"].lower()
|
||||
|
||||
|
||||
class TestCheckI18n:
|
||||
def test_raw_string_in_echo_triggers_warning(self) -> None:
|
||||
@@ -295,6 +333,14 @@ class TestCheckI18n:
|
||||
check_i18n(files, result)
|
||||
assert any("i18n: OK" in s for s in result.summary)
|
||||
|
||||
def test_malformed_hunk_header_no_line_number(self) -> None:
|
||||
"""A @@ header without a +N line number is handled gracefully."""
|
||||
result = ReviewResult()
|
||||
files = [{"filename": "src/devx/cli.py", "patch": '@@ -1,2 @@\n+click.echo("Hello world")\n'}]
|
||||
check_i18n(files, result)
|
||||
assert result.has_issues
|
||||
assert any("i18n" in i["body"] for i in result.issues)
|
||||
|
||||
|
||||
class TestCheckResourceManagement:
|
||||
def test_open_without_with_triggers_warning(self) -> None:
|
||||
@@ -366,6 +412,14 @@ class TestCheckResourceManagement:
|
||||
check_resource_management(files, result)
|
||||
assert any("Resource management: OK" in s for s in result.summary)
|
||||
|
||||
def test_malformed_hunk_header_no_line_number(self) -> None:
|
||||
"""A @@ header without a +N line number is handled gracefully."""
|
||||
result = ReviewResult()
|
||||
files = [{"filename": "src/devx/cli.py", "patch": '@@ -1,2 @@\n+f = open("file.txt")\n'}]
|
||||
check_resource_management(files, result)
|
||||
assert result.has_issues
|
||||
assert any("resource" in i["body"].lower() for i in result.issues)
|
||||
|
||||
|
||||
class TestCheckFunctionLength:
|
||||
def test_long_function_triggers_warning(self) -> None:
|
||||
@@ -429,6 +483,13 @@ class TestCheckFunctionLength:
|
||||
assert result.has_issues
|
||||
assert "foo" in result.issues[0]["body"]
|
||||
|
||||
def test_malformed_hunk_header_no_line_number(self) -> None:
|
||||
"""A @@ header without a +N line number is handled gracefully."""
|
||||
result = ReviewResult()
|
||||
files = [{"filename": "src/devx/cli.py", "patch": "@@ -1,2 @@\n+def foo():\n+ pass\n"}]
|
||||
check_function_length(files, result)
|
||||
assert not result.has_issues
|
||||
|
||||
|
||||
class TestCheckDocumentation:
|
||||
def test_src_changes_without_docs_warns(self) -> None:
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
"""Unit tests for devx.tools.pre_push_check."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import click
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
from devx.tools.pre_push_check import (
|
||||
cli,
|
||||
extract_task_id,
|
||||
get_current_branch,
|
||||
task_exists,
|
||||
validate,
|
||||
)
|
||||
|
||||
|
||||
class TestExtractTaskId:
|
||||
def test_valid_branch(self) -> None:
|
||||
assert extract_task_id("DEVX-42-fix-bug") == "DEVX-42"
|
||||
|
||||
def test_no_task_id(self) -> None:
|
||||
assert extract_task_id("feature-branch") == ""
|
||||
|
||||
def test_empty_branch(self) -> None:
|
||||
assert extract_task_id("") == ""
|
||||
|
||||
|
||||
class TestGetCurrentBranch:
|
||||
@patch("devx.tools.pre_push_check.subprocess.run")
|
||||
def test_success(self, mock_run: MagicMock) -> None:
|
||||
mock_run.return_value = MagicMock(stdout="DEVX-42-fix\n", returncode=0)
|
||||
assert get_current_branch() == "DEVX-42-fix"
|
||||
|
||||
@patch("devx.tools.pre_push_check.subprocess.run")
|
||||
def test_failure(self, mock_run: MagicMock) -> None:
|
||||
mock_run.return_value = MagicMock(stdout="", returncode=1)
|
||||
assert get_current_branch() == ""
|
||||
|
||||
|
||||
class TestTaskExists:
|
||||
@patch("devx.tools.pre_push_check.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_found(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.list_project_tasks.return_value = [{"identifier": "DEVX-42"}]
|
||||
mock_client_cls.return_value = mock_client
|
||||
assert task_exists("DEVX-42") is True
|
||||
|
||||
@patch("devx.tools.pre_push_check.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_not_found(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.list_project_tasks.return_value = [{"identifier": "DEVX-99"}]
|
||||
mock_client_cls.return_value = mock_client
|
||||
assert task_exists("DEVX-42") is False
|
||||
|
||||
@patch.dict("os.environ", {}, clear=True)
|
||||
def test_no_token(self) -> None:
|
||||
assert task_exists("DEVX-42") is False
|
||||
|
||||
@patch("devx.tools.pre_push_check.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_pagination(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
# First page: full page (50 items, none matching), second page: match
|
||||
page1 = [{"identifier": f"OTHER-{i}"} for i in range(50)]
|
||||
page2 = [{"identifier": "DEVX-42"}]
|
||||
mock_client.list_project_tasks.side_effect = [page1, page2]
|
||||
mock_client_cls.return_value = mock_client
|
||||
assert task_exists("DEVX-42") is True
|
||||
|
||||
@patch("devx.tools.pre_push_check.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_empty_project(self, mock_client_cls: MagicMock) -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_client.list_project_tasks.return_value = []
|
||||
mock_client_cls.return_value = mock_client
|
||||
assert task_exists("DEVX-42") is False
|
||||
|
||||
@patch("devx.tools.pre_push_check.VikunjaClient")
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_pagination_not_found(self, mock_client_cls: MagicMock) -> None:
|
||||
from devx.config import DEFAULT_PER_PAGE
|
||||
|
||||
mock_client = MagicMock()
|
||||
page1 = [{"identifier": f"OTHER-{i}"} for i in range(DEFAULT_PER_PAGE)]
|
||||
page2 = [{"identifier": "OTHER-99"}]
|
||||
mock_client.list_project_tasks.side_effect = [page1, page2]
|
||||
mock_client_cls.return_value = mock_client
|
||||
assert task_exists("DEVX-42") is False
|
||||
|
||||
|
||||
class TestValidate:
|
||||
def test_master_branch_skips(self) -> None:
|
||||
validate("master")
|
||||
|
||||
def test_main_branch_skips(self) -> None:
|
||||
validate("main")
|
||||
|
||||
def test_empty_branch_skips(self) -> None:
|
||||
validate("")
|
||||
|
||||
def test_no_task_id_raises(self) -> None:
|
||||
with pytest.raises(click.ClickException, match="does not contain a task ID"):
|
||||
validate("feature-branch")
|
||||
|
||||
@patch.dict("os.environ", {}, clear=True)
|
||||
def test_no_token_warns(self) -> None:
|
||||
validate("DEVX-42-fix-bug")
|
||||
|
||||
@patch("devx.tools.pre_push_check.task_exists", return_value=True)
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_task_exists_passes(self, mock_exists: MagicMock) -> None:
|
||||
validate("DEVX-42-fix-bug")
|
||||
|
||||
@patch("devx.tools.pre_push_check.task_exists", return_value=False)
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_task_not_found_raises(self, mock_exists: MagicMock) -> None:
|
||||
with pytest.raises(click.ClickException, match="not found"):
|
||||
validate("DEVX-42-fix-bug")
|
||||
|
||||
|
||||
class TestCli:
|
||||
@patch("devx.tools.pre_push_check.get_current_branch", return_value="master")
|
||||
def test_auto_detect_master(self, mock_branch: MagicMock) -> None:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, [])
|
||||
assert result.exit_code == 0
|
||||
|
||||
@patch("devx.tools.pre_push_check.task_exists", return_value=True)
|
||||
@patch.dict("os.environ", {"VIKUNJA_TOKEN": "tok"})
|
||||
def test_explicit_branch(self, mock_exists: MagicMock) -> None:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--branch", "DEVX-42-fix"])
|
||||
assert result.exit_code == 0
|
||||
assert "passed" in result.output
|
||||
@@ -156,6 +156,13 @@ class TestDefaultGiteaRegistryUrl:
|
||||
url = _default_gitea_registry_url()
|
||||
assert "oblachno-oss" in url
|
||||
|
||||
@patch.dict("os.environ", {"DEVX_REPO_OWNER": "myorg"}, clear=True)
|
||||
@patch("devx.ci.publish.GITEA_API_URL", "https://git.example.com/")
|
||||
def test_no_api_suffix(self) -> None:
|
||||
"""URL without /api/v1 or /api suffix is used as-is."""
|
||||
url = _default_gitea_registry_url()
|
||||
assert url == "https://git.example.com/api/packages/myorg/pypi"
|
||||
|
||||
|
||||
class TestMain:
|
||||
@patch.dict("os.environ", {"REPO_TOKEN": "gitea-tok", "PYPI_TOKEN": "pypi-tok"})
|
||||
|
||||
@@ -508,6 +508,30 @@ class TestVerifyAlignment:
|
||||
mock_run_cmd.return_value = MagicMock(returncode=0, stdout="", stderr="")
|
||||
assert verify_alignment() == 1
|
||||
|
||||
@patch("devx.ci.release.run_cmd")
|
||||
@patch("devx.ci.release.get_changelog_versions")
|
||||
@patch("devx.ci.release.get_init_version")
|
||||
@patch("devx.ci.release.verify_tag_consistency")
|
||||
@patch("devx.ci.release.get_all_tags")
|
||||
@patch("devx.ci.release.get_latest_tag")
|
||||
def test_no_latest_tag_skips_changelog_tag_check(
|
||||
self,
|
||||
mock_lt: MagicMock,
|
||||
mock_tags: MagicMock,
|
||||
mock_vtc: MagicMock,
|
||||
mock_iv: MagicMock,
|
||||
mock_cv: MagicMock,
|
||||
mock_run_cmd: MagicMock,
|
||||
) -> None:
|
||||
"""When there is no latest tag, the CHANGELOG/tag match check is skipped."""
|
||||
mock_lt.return_value = None # no tags
|
||||
mock_tags.return_value = []
|
||||
mock_vtc.return_value = []
|
||||
mock_iv.return_value = "0.4.4"
|
||||
mock_cv.return_value = ["0.4.4"] # changelog has versions but no tag to compare
|
||||
mock_run_cmd.return_value = MagicMock(returncode=0, stdout="", stderr="")
|
||||
assert verify_alignment() == 0
|
||||
|
||||
@patch("devx.ci.release.run_cmd")
|
||||
@patch("devx.ci.release.get_changelog_versions")
|
||||
@patch("devx.ci.release.get_init_version")
|
||||
@@ -756,6 +780,16 @@ class TestUpdateChangelog:
|
||||
assert "# Changelog" not in content
|
||||
assert "## [0.2.0]" in content
|
||||
|
||||
def test_no_version_section_in_changelog(self, tmp_path, monkeypatch) -> None:
|
||||
"""Changelog input without any ## [ version section is inserted as-is."""
|
||||
changelog_file = tmp_path / "CHANGELOG.md"
|
||||
changelog_file.write_text("# Changelog\n\n## [0.1.0] - 2026-06-20\n\n### Features\n- old thing\n")
|
||||
monkeypatch.setattr("devx.ci.release.CHANGELOG_FILE", str(changelog_file))
|
||||
# No ## [ section in the cliff output — should not be stripped
|
||||
update_changelog("Some raw text without version header")
|
||||
content = changelog_file.read_text()
|
||||
assert "Some raw text without version header" in content
|
||||
|
||||
|
||||
class TestCommitReleaseChanges:
|
||||
@patch("devx.ci.release.run_cmd")
|
||||
|
||||
@@ -186,6 +186,12 @@ class TestVerify:
|
||||
mock_run.side_effect = subprocess.TimeoutExpired(cmd="devx", timeout=10)
|
||||
_verify(".venv/bin") # Should not raise
|
||||
|
||||
@patch("devx.tools.setup.subprocess.run")
|
||||
def test_verify_handles_nonzero_returncode(self, mock_run: MagicMock) -> None:
|
||||
"""When a tool returns non-zero, it is skipped without raising."""
|
||||
mock_run.return_value = MagicMock(returncode=1, stdout="", stderr="error")
|
||||
_verify(".venv/bin") # Should not raise
|
||||
|
||||
|
||||
class TestMain:
|
||||
@patch("devx.tools.setup._configure_tea_login")
|
||||
@@ -304,6 +310,28 @@ class TestMain:
|
||||
assert result.exit_code != 0
|
||||
assert "Bin directory not found" in result.output
|
||||
|
||||
@patch("devx.tools.setup._verify")
|
||||
@patch("devx.tools.setup._configure_tea_login")
|
||||
@patch("devx.tools.setup._install_pre_commit_hooks")
|
||||
@patch("devx.tools.setup._install_ansible_collections")
|
||||
@patch("devx.tools.setup._install_python_deps")
|
||||
def test_main_skip_install(
|
||||
self,
|
||||
mock_install_deps: MagicMock,
|
||||
mock_install_ansible: MagicMock,
|
||||
mock_install_hooks: MagicMock,
|
||||
mock_verify: MagicMock,
|
||||
mock_tea: MagicMock,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
bin_dir = tmp_path / "bin"
|
||||
bin_dir.mkdir()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--bin", str(bin_dir), "--skip-install"])
|
||||
assert result.exit_code == 0
|
||||
mock_install_deps.assert_not_called()
|
||||
assert "Skipping pip install" in result.output
|
||||
|
||||
|
||||
def test_main_module_block(tmp_path: Path) -> None:
|
||||
"""Test the __main__ block execution."""
|
||||
|
||||
@@ -69,6 +69,22 @@ class TestDiagnoseSocket:
|
||||
_diagnose_socket()
|
||||
mock_exists.assert_called_with(DOCKER_SOCK)
|
||||
|
||||
@patch("devx.molecule.start_docker.os.path.exists", return_value=True)
|
||||
@patch("devx.molecule.start_docker.os.stat")
|
||||
@patch("devx.molecule.start_docker.subprocess.run")
|
||||
def test_docker_info_no_matching_lines(
|
||||
self, mock_run: MagicMock, mock_stat: MagicMock, mock_exists: MagicMock
|
||||
) -> None:
|
||||
"""docker info succeeds but stdout has no Server Version/Storage Driver/Root Dir lines."""
|
||||
mock_stat.return_value = MagicMock(st_mode=0o660, st_uid=0, st_gid=0)
|
||||
mock_run.side_effect = [
|
||||
MagicMock(stdout="/dev/sda1 /var/lib/docker ext4\n", returncode=0, text=""),
|
||||
MagicMock(stdout="default\n", returncode=0, text=""),
|
||||
MagicMock(stdout="Containers: 0\nImages: 0\nKernel: 6.1\n", returncode=0, text=""),
|
||||
]
|
||||
_diagnose_socket()
|
||||
mock_exists.assert_called_with(DOCKER_SOCK)
|
||||
|
||||
|
||||
class TestStartDockerDaemon:
|
||||
@patch("devx.molecule.start_docker._diagnose_socket")
|
||||
|
||||
Reference in New Issue
Block a user