This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Timmy-time-dashboard/tests/self_coding/test_watchdog_functional.py
Claude 9f4c809f70 refactor: Phase 2b — consolidate 28 modules into 14 packages
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
2026-02-26 22:07:41 +00:00

101 lines
3.6 KiB
Python

"""Functional tests for self_tdd.watchdog — continuous test runner.
All subprocess calls are mocked to avoid running real pytest.
"""
from unittest.mock import patch, MagicMock, call
import pytest
from self_coding.self_tdd.watchdog import _run_tests, watch
class TestRunTests:
@patch("self_coding.self_tdd.watchdog.subprocess.run")
def test_run_tests_passing(self, mock_run):
mock_run.return_value = MagicMock(
returncode=0,
stdout="5 passed\n",
stderr="",
)
passed, output = _run_tests()
assert passed is True
assert "5 passed" in output
@patch("self_coding.self_tdd.watchdog.subprocess.run")
def test_run_tests_failing(self, mock_run):
mock_run.return_value = MagicMock(
returncode=1,
stdout="2 failed, 3 passed\n",
stderr="ERRORS",
)
passed, output = _run_tests()
assert passed is False
assert "2 failed" in output
assert "ERRORS" in output
@patch("self_coding.self_tdd.watchdog.subprocess.run")
def test_run_tests_command_format(self, mock_run):
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
_run_tests()
cmd = mock_run.call_args[0][0]
assert "pytest" in " ".join(cmd)
assert "tests/" in cmd
assert "-q" in cmd
assert "--tb=short" in cmd
assert mock_run.call_args[1]["capture_output"] is True
assert mock_run.call_args[1]["text"] is True
class TestWatch:
@patch("self_coding.self_tdd.watchdog.time.sleep")
@patch("self_coding.self_tdd.watchdog._run_tests")
@patch("self_coding.self_tdd.watchdog.typer")
def test_watch_first_pass(self, mock_typer, mock_tests, mock_sleep):
"""First iteration: None→passing → should print green message."""
call_count = 0
def side_effect():
nonlocal call_count
call_count += 1
if call_count >= 2:
raise KeyboardInterrupt
return (True, "all good")
mock_tests.side_effect = side_effect
watch(interval=10)
# Should have printed green "All tests passing" message
mock_typer.secho.assert_called()
@patch("self_coding.self_tdd.watchdog.time.sleep")
@patch("self_coding.self_tdd.watchdog._run_tests")
@patch("self_coding.self_tdd.watchdog.typer")
def test_watch_regression(self, mock_typer, mock_tests, mock_sleep):
"""Regression: passing→failing → should print red message + output."""
results = [(True, "ok"), (False, "FAILED: test_foo"), KeyboardInterrupt]
idx = 0
def side_effect():
nonlocal idx
if idx >= len(results):
raise KeyboardInterrupt
r = results[idx]
idx += 1
if isinstance(r, type) and issubclass(r, BaseException):
raise r()
return r
mock_tests.side_effect = side_effect
watch(interval=5)
# Should have printed red "Regression detected" at some point
secho_calls = [str(c) for c in mock_typer.secho.call_args_list]
assert any("Regression" in c for c in secho_calls) or any("RED" in c for c in secho_calls)
@patch("self_coding.self_tdd.watchdog.time.sleep")
@patch("self_coding.self_tdd.watchdog._run_tests")
@patch("self_coding.self_tdd.watchdog.typer")
def test_watch_keyboard_interrupt(self, mock_typer, mock_tests, mock_sleep):
mock_tests.side_effect = KeyboardInterrupt
watch(interval=60)
mock_typer.echo.assert_called() # "Watchdog stopped"