forked from Rockachopa/Timmy-time-dashboard
Complete the module consolidation planned in REFACTORING_PLAN.md: Modules merged: - work_orders/ + task_queue/ → swarm/ (subpackages) - self_modify/ + self_tdd/ + upgrades/ → self_coding/ (subpackages) - tools/ → creative/tools/ - chat_bridge/ + telegram_bot/ + shortcuts/ + voice/ → integrations/ (new) - ws_manager/ + notifications/ + events/ + router/ → infrastructure/ (new) - agents/ + agent_core/ + memory/ → timmy/ (subpackages) Updated across codebase: - 66 source files: import statements rewritten - 13 test files: import + patch() target strings rewritten - pyproject.toml: wheel includes (28→14), entry points updated - CLAUDE.md: singleton paths, module map, entry points table - AGENTS.md: file convention updates - REFACTORING_PLAN.md: execution status, success metrics Extras: - Module-level CLAUDE.md added to 6 key packages (Phase 6.2) - Zero test regressions: 1462 tests passing https://claude.ai/code/session_01JNjWfHqusjT3aiN4vvYgUk
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from unittest.mock import MagicMock, patch
|
|
|
|
from self_coding.self_tdd.watchdog import _run_tests
|
|
|
|
|
|
def _mock_result(returncode: int, stdout: str = "", stderr: str = "") -> MagicMock:
|
|
m = MagicMock()
|
|
m.returncode = returncode
|
|
m.stdout = stdout
|
|
m.stderr = stderr
|
|
return m
|
|
|
|
|
|
def test_run_tests_returns_true_when_suite_passes():
|
|
with patch("self_coding.self_tdd.watchdog.subprocess.run", return_value=_mock_result(0, "5 passed")):
|
|
passed, _ = _run_tests()
|
|
assert passed is True
|
|
|
|
|
|
def test_run_tests_returns_false_when_suite_fails():
|
|
with patch("self_coding.self_tdd.watchdog.subprocess.run", return_value=_mock_result(1, "1 failed")):
|
|
passed, _ = _run_tests()
|
|
assert passed is False
|
|
|
|
|
|
def test_run_tests_output_includes_stdout():
|
|
with patch("self_coding.self_tdd.watchdog.subprocess.run", return_value=_mock_result(0, stdout="5 passed")):
|
|
_, output = _run_tests()
|
|
assert "5 passed" in output
|
|
|
|
|
|
def test_run_tests_output_combines_stdout_and_stderr():
|
|
with patch(
|
|
"self_coding.self_tdd.watchdog.subprocess.run",
|
|
return_value=_mock_result(1, stdout="FAILED test_foo", stderr="ImportError: no module named bar"),
|
|
):
|
|
_, output = _run_tests()
|
|
assert "FAILED test_foo" in output
|
|
assert "ImportError" in output
|
|
|
|
|
|
def test_run_tests_invokes_pytest_with_correct_flags():
|
|
with patch("self_coding.self_tdd.watchdog.subprocess.run", return_value=_mock_result(0)) as mock_run:
|
|
_run_tests()
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "pytest" in cmd
|
|
assert "tests/" in cmd
|
|
assert "--tb=short" in cmd
|
|
|
|
|
|
def test_run_tests_uses_60s_timeout():
|
|
with patch("self_coding.self_tdd.watchdog.subprocess.run", return_value=_mock_result(0)) as mock_run:
|
|
_run_tests()
|
|
assert mock_run.call_args.kwargs["timeout"] == 60
|