|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
5 | | -from app import validate |
6 | 5 | from app.verify import hosts, offline |
7 | 6 | from app.verify.common import Record |
8 | 7 |
|
9 | 8 | NOW = 2026 |
10 | 9 | NO_SOC: dict[str, str] = {} |
11 | 10 |
|
12 | 11 |
|
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 | | - |
59 | 12 | def _score(category, data): |
60 | 13 | return offline.score_record(Record(category, f"{category}/x.json", data), NOW, NO_SOC) |
61 | 14 |
|
@@ -148,3 +101,32 @@ def test_model_key_of_a_standalone_record_is_itself(): |
148 | 101 | rec = Record("cpu", "cpu/intel/2023/desktop/core-i9-14900k.json", |
149 | 102 | {"slug": "core-i9-14900k"}) |
150 | 103 | assert rec.model_key == ("cpu", "core-i9-14900k") |
| 104 | + |
| 105 | + |
| 106 | +@pytest.mark.parametrize("category,fields", [ |
| 107 | + ("laptop", {"cpu_name": "Example CPU", "ram_gb": 16, "storage_gb": 512, |
| 108 | + "display": {"size_inch": 14, "resolution": "1920x1080", "ppi": 157}, |
| 109 | + "weight_g": 1400, "gpu_name": "Integrated", "os": "Linux"}), |
| 110 | + ("monitor", {"size_inch": 24, "resolution": "1920x1080", "refresh_hz": 144, |
| 111 | + "panel_type": "IPS", "ppi": 92, "aspect_ratio": "16:9", |
| 112 | + "features": {"ports": ["HDMI"], "response_time_ms": 1}}), |
| 113 | +]) |
| 114 | +@pytest.mark.parametrize("url", ["https://intel.com/example", "https://wikidata.org/wiki/Q1"]) |
| 115 | +def test_complete_laptop_monitor_can_be_green(category, fields, url): |
| 116 | + data = {**fields, "release_date": "2023-01-01", "source_urls": [url]} |
| 117 | + score = _score(category, data) |
| 118 | + assert score.band == "green" |
| 119 | + assert score.subscores["consistency"] == 35 |
| 120 | + assert score.flags == [] |
| 121 | + # A physical impossibility overrides an otherwise rich, well-sourced record. |
| 122 | + data["ram_gb" if category == "laptop" else "size_inch"] = 0 |
| 123 | + assert _score(category, data).band == "red" |
| 124 | + |
| 125 | + |
| 126 | +@pytest.mark.parametrize("category", ["laptop", "monitor"]) |
| 127 | +def test_sparse_bulk_laptop_monitor_stays_yellow(category): |
| 128 | + data = {"release_date": "2023-01-01", "source_urls": ["https://kaggle.com/example"]} |
| 129 | + score = _score(category, data) |
| 130 | + assert score.band == "yellow" |
| 131 | + assert "domain_rules_unavailable" not in score.flags |
| 132 | + assert score.subscores["consistency"] == 35 |
0 commit comments