Skip to content

Commit ecec463

Browse files
committed
test: isolate build wrapper from project discovery
1 parent 059cf18 commit ecec463

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Test helpers for build execution command boundaries."""
2+
3+
from types import ModuleType
4+
from unittest.mock import Mock
5+
6+
import pytest
7+
8+
from sqlbuild.cli.commands.models import BuildInvocation
9+
from sqlbuild.spec.contracts.models import ExecutionLimitsConfig
10+
11+
12+
def stub_resolved_build_invocation(
13+
*, monkeypatch: pytest.MonkeyPatch, build_module: ModuleType
14+
) -> None:
15+
"""Keep command-wrapper tests isolated from project discovery."""
16+
17+
invocation: Mock = Mock(spec=BuildInvocation)
18+
invocation.execution_limits = ExecutionLimitsConfig()
19+
invocation.effective_target_name = None
20+
monkeypatch.setattr(build_module, "resolve_build_invocation", lambda **_kwargs: invocation)

‎tests/unit/src/sqlbuild/cli/commands/main/execution/test_build_process_resources.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
BuildPartialTimingOutputTestCase,
1616
BuildProcessReportTestCase,
1717
)
18+
from tests.unit.src.sqlbuild.cli.commands.main.execution.helpers import (
19+
stub_resolved_build_invocation,
20+
)
1821

1922

2023
@pytest.mark.parametrize(
@@ -31,6 +34,7 @@ def test_given_successful_debug_build_when_finishing_then_reports_process_resour
3134
test_case: BuildProcessReportTestCase,
3235
monkeypatch: pytest.MonkeyPatch,
3336
) -> None:
37+
stub_resolved_build_invocation(monkeypatch=monkeypatch, build_module=build_module)
3438
reporter: Mock = Mock()
3539
monkeypatch.setattr(build_module, "process_resource_reporting", reporter)
3640
reporter.return_value = nullcontext()
@@ -56,6 +60,7 @@ def test_given_failed_debug_build_when_unwinding_then_reports_process_resources(
5660
test_case: BuildProcessReportTestCase,
5761
monkeypatch: pytest.MonkeyPatch,
5862
) -> None:
63+
stub_resolved_build_invocation(monkeypatch=monkeypatch, build_module=build_module)
5964
reporter: Mock = Mock()
6065

6166
def fail_build(**_kwargs: object) -> int:
@@ -85,6 +90,7 @@ def test_given_interrupted_debug_build_when_unwinding_then_reports_process_resou
8590
test_case: BuildProcessReportTestCase,
8691
monkeypatch: pytest.MonkeyPatch,
8792
) -> None:
93+
stub_resolved_build_invocation(monkeypatch=monkeypatch, build_module=build_module)
8894
reporter: Mock = Mock()
8995

9096
def interrupt_build(**_kwargs: object) -> int:
@@ -157,6 +163,7 @@ def test_given_phase_failure_when_building_then_available_partial_timings_are_wr
157163
monkeypatch: pytest.MonkeyPatch,
158164
capsys: pytest.CaptureFixture[str],
159165
) -> None:
166+
stub_resolved_build_invocation(monkeypatch=monkeypatch, build_module=build_module)
160167
timing_tracker: Mock = Mock()
161168
timing_tracker.snapshot.return_value = PartialBuildPhaseTimings(
162169
compile_seconds=test_case.compile_seconds,
@@ -207,6 +214,7 @@ def test_given_json_cost_failure_when_building_then_partial_timing_only_uses_std
207214
monkeypatch: pytest.MonkeyPatch,
208215
capsys: pytest.CaptureFixture[str],
209216
) -> None:
217+
stub_resolved_build_invocation(monkeypatch=monkeypatch, build_module=build_module)
210218
timing_tracker: Mock = Mock()
211219
timing_tracker.snapshot.return_value = PartialBuildPhaseTimings(
212220
compile_seconds=test_case.compile_seconds,

0 commit comments

Comments
 (0)