feat(skill): gsc_signal_delta helper + tests + code notes
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tests for gsc_signal_delta. Run: `python3 test_gsc_signal_delta.py`
|
||||
(also pytest-compatible). Stdlib only."""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from gsc_signal_delta import compute_delta # noqa: E402
|
||||
|
||||
# Genesis fixture: JHR "호텔" — flat head term, growth all brand (2026-06 case).
|
||||
RECENT = [
|
||||
{"query": "호텔", "clicks": 5, "impressions": 572, "position": 11.6},
|
||||
{"query": "grand josun busan", "clicks": 250, "impressions": 4000, "position": 1.2},
|
||||
{"query": "조선호텔", "clicks": 300, "impressions": 6000, "position": 1.1},
|
||||
]
|
||||
PRIOR = [
|
||||
{"query": "호텔", "clicks": 9, "impressions": 371, "position": 18.1},
|
||||
{"query": "grand josun busan", "clicks": 49, "impressions": 1500, "position": 3.4},
|
||||
{"query": "조선호텔", "clicks": 150, "impressions": 5000, "position": 1.3},
|
||||
]
|
||||
|
||||
|
||||
def test_claim_term_flagged_artifact():
|
||||
out = compute_delta(RECENT, PRIOR, 28, 30, claim_term="호텔")
|
||||
ct = out["claim_term"]
|
||||
assert ct["found"] is True
|
||||
assert ct["in_top_movers"] is False
|
||||
assert ct["click_share_pct"] < 1.0
|
||||
assert "ARTIFACT" in out["verdict_hint"]
|
||||
|
||||
|
||||
def test_top_gainer_is_brand_term():
|
||||
out = compute_delta(RECENT, PRIOR, 28, 30, claim_term="호텔")
|
||||
assert out["top_gainers"][0]["query"] == "grand josun busan"
|
||||
assert out["top_gainers"][0]["delta_clicks"] == 201
|
||||
|
||||
|
||||
def test_day_normalization():
|
||||
out = compute_delta(RECENT, PRIOR, 28, 30)
|
||||
assert out["site_totals"]["recent"]["clicks_per_day"] == 19.82 # 555/28
|
||||
assert out["site_totals"]["prior"]["clicks_per_day"] == 6.93 # 208/30
|
||||
|
||||
|
||||
def test_positive_days_required():
|
||||
try:
|
||||
compute_delta(RECENT, PRIOR, 0, 30)
|
||||
except ValueError:
|
||||
return
|
||||
raise AssertionError("expected ValueError for non-positive days")
|
||||
|
||||
|
||||
def _run():
|
||||
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
|
||||
for fn in fns:
|
||||
fn(); print(f"PASS {fn.__name__}")
|
||||
print(f"\n{len(fns)} passed")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
_run()
|
||||
Reference in New Issue
Block a user