forked from Rockachopa/Timmy-time-dashboard
refactor: Phase 3 — reorganize tests into module-mirroring subdirectories
Move 97 test files from flat tests/ into 13 subdirectories: tests/dashboard/ (8 files — routes, mobile, mission control) tests/swarm/ (17 files — coordinator, docker, routing, tasks) tests/timmy/ (12 files — agent, backends, CLI, tools) tests/self_coding/ (14 files — git safety, indexer, self-modify) tests/lightning/ (3 files — L402, LND, interface) tests/creative/ (8 files — assembler, director, image/music/video) tests/integrations/ (10 files — chat bridge, telegram, voice, websocket) tests/mcp/ (4 files — bootstrap, discovery, executor) tests/spark/ (3 files — engine, tools, events) tests/hands/ (3 files — registry, oracle, phase5) tests/scripture/ (1 file) tests/infrastructure/ (3 files — router cascade, API) tests/security/ (3 files — XSS, regression) Fix Path(__file__) reference in test_mobile_scenarios.py for new depth. Add __init__.py to all test subdirectories. Tests: 1503 passed, 9 failed (pre-existing), 53 errors (pre-existing) https://claude.ai/code/session_019oMFNvD8uSGSSmBMGkBfQN
This commit is contained in:
54
tests/self_coding/test_watchdog.py
Normal file
54
tests/self_coding/test_watchdog.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from 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_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_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_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_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_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_tdd.watchdog.subprocess.run", return_value=_mock_result(0)) as mock_run:
|
||||
_run_tests()
|
||||
assert mock_run.call_args.kwargs["timeout"] == 60
|
||||
Reference in New Issue
Block a user