|
1 | 1 | """Tier 0 scorer + host classification tests.""" |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
| 5 | +from app import validate |
3 | 6 | from app.verify import hosts, offline |
4 | 7 | from app.verify.common import Record |
5 | 8 |
|
6 | 9 | NOW = 2026 |
7 | 10 | NO_SOC: dict[str, str] = {} |
8 | 11 |
|
9 | 12 |
|
| 13 | +@pytest.mark.parametrize("category,slug,fields,url,expected", [ |
| 14 | + ("laptop", "acer-chromebook-14-ammok-691", |
| 15 | + {"ram_gb": 4, "os": "Chrome OS"}, |
| 16 | + "https://huggingface.co/datasets/Ammok/laptop_price_prediction", 53.8), |
| 17 | + ("monitor", "acer-nitro-monitor-amazonmon-636", |
| 18 | + {"size_inch": 23.8, "resolution": "1920x1080"}, |
| 19 | + "https://www.kaggle.com/datasets/durjoychandrapaul/amazon-products-sales-monitor-dataset", |
| 20 | + 58.5), |
| 21 | +]) |
| 22 | +def test_structurally_valid_variants_are_yellow(category, slug, fields, url, expected): |
| 23 | + base = "acer-chromebook-14" if category == "laptop" else "acer-nitro-monitor" |
| 24 | + data = { |
| 25 | + "slug": slug, "base_model_slug": base, "name": "Example", "brand": "acer", |
| 26 | + "release_date": "2023-01-01", "verified": False, "source_urls": [url], **fields, |
| 27 | + } |
| 28 | + path = f"{category}/acer/2023/{base}/{slug}.json" |
| 29 | + required = getattr(validate, f"{category.upper()}_REQUIRED") |
| 30 | + errors = [] |
| 31 | + validate._check_required(path, data, required, errors) |
| 32 | + validate._check_slug(path, slug, errors) |
| 33 | + validate._check_source_urls(path, data, errors) |
| 34 | + validate._check_variant_path(path, data, category, errors, allow_flat=True) |
| 35 | + assert errors == [] |
| 36 | + |
| 37 | + def score(): |
| 38 | + return offline.score_record(Record(category, path, data), NOW, NO_SOC) |
| 39 | + |
| 40 | + result = score() |
| 41 | + assert result.band == "yellow" |
| 42 | + assert result.score == expected |
| 43 | + assert result.subscores["consistency"] == 0 |
| 44 | + assert result.flags == ["domain_rules_unavailable"] |
| 45 | + |
| 46 | + # Strong sources can increase the normalized score, but cannot earn green |
| 47 | + # without domain consistency rules. |
| 48 | + data["source_urls"] = ["https://intel.com/example", "https://en.wikipedia.org/wiki/x"] |
| 49 | + assert score().score >= offline.GREEN_MIN |
| 50 | + assert score().band == "yellow" |
| 51 | + |
| 52 | + del data[next(iter(fields))] |
| 53 | + broken = score() |
| 54 | + assert broken.score >= offline.RED_MAX # hard fail, despite a good numeric score |
| 55 | + assert broken.band == "red" |
| 56 | + assert "!structural_integrity" in broken.flags |
| 57 | + |
| 58 | + |
10 | 59 | def _score(category, data): |
11 | 60 | return offline.score_record(Record(category, f"{category}/x.json", data), NOW, NO_SOC) |
12 | 61 |
|
|
0 commit comments