-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_smoke.py
More file actions
58 lines (40 loc) · 2.01 KB
/
Copy pathtest_smoke.py
File metadata and controls
58 lines (40 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Environment smoke test — the honest "is Python set up correctly?" check.
These should ALL PASS once `setup.sh` has run. They verify the interpreter,
package imports, config module, and mock data — without needing any API keys.
(Contrast with sample_service/test_app.py, which intentionally FAILS to
demonstrate the planted bug the agent will fix.)
Run: pytest test_smoke.py
"""
import json
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent
def test_python_version_is_supported():
assert sys.version_info[:2] >= (3, 11), (
f"Python 3.11+ required, found {sys.version_info.major}.{sys.version_info.minor}"
)
def test_third_party_dependencies_import():
# The runtime deps from requirements.txt must be installed in the venv.
import anthropic # noqa: F401
import dotenv # noqa: F401
import requests # noqa: F401
def test_project_modules_import():
# Core package modules should import cleanly.
import agent # noqa: F401
from agent import config, models # noqa: F401
# Config module exposes the loader and Config type (we don't call it here,
# so the check passes even before .env keys are filled in).
assert hasattr(config, "load_config")
assert hasattr(config, "Config")
def test_sample_service_happy_path():
# The non-buggy code path works (empty-list path is the planted bug).
from sample_service.app import calculate_average_order_value
assert calculate_average_order_value([{"total": 10.0}, {"total": 20.0}]) == 15.0
def test_mock_logs_parse_and_have_errors():
data = json.loads((REPO_ROOT / "mock_data" / "logs.json").read_text())
events = data["events"]
assert isinstance(events, list) and events, "expected a non-empty events list"
errors = [e for e in events if e["level"] == "ERROR"]
assert errors, "expected at least one ERROR event for the demo"
# At least one error should point at a file we can fix.
assert any(e.get("culprit") for e in errors), "expected an error with a culprit file"