(root: Path, graph: Graph, cats: str)
| 495 | # ------------------------------------------------------------------ measuring |
| 496 | |
| 497 | def measure(root: Path, graph: Graph, cats: str) -> dict[str, dict]: |
| 498 | result: dict[str, dict] = {} |
| 499 | for cat in cats: |
| 500 | covered = 0 |
| 501 | failures: list[list] = [] |
| 502 | warnings: list[list] = [] |
| 503 | cases: list = [] |
| 504 | |
| 505 | def hit(file: str, line: int, key: str) -> bool: |
| 506 | if any(norm(n.get("label")) == key for n in graph.targets(file, line)): |
| 507 | return True |
| 508 | return any(norm(n.get("label")) == key for n in graph.nodes_at.get((file, line), [])) |
| 509 | |
| 510 | if cat == "a": |
| 511 | for file, line, name, expected in cases_a(root): |
| 512 | cases.append(1) |
| 513 | found = graph.targets(file, line) |
| 514 | if (root / expected).is_file(): |
| 515 | ok = any(graph.rel(n.get("source_file")) == expected for n in found) |
| 516 | else: # a call to a file the theme lacks: Shopify errors at runtime, the graph must say unresolved |
| 517 | ok = any(_is_unresolved(n) and norm(n.get("label")) == expected for n in found) |
| 518 | if ok: |
| 519 | covered += 1 |
| 520 | else: |
| 521 | failures.append([file, line, f"{name} -> {expected}"]) |
| 522 | elif cat == "b": |
| 523 | for file, line, key in cases_b(root): |
| 524 | cases.append(1) |
| 525 | if hit(file, line, key): |
| 526 | covered += 1 |
| 527 | else: |
| 528 | failures.append([file, line, key]) |
| 529 | elif cat == "c": |
| 530 | for file, line, key in cases_c(root): |
| 531 | cases.append(1) |
| 532 | if any(norm(n.get("label")) == key and not _is_unresolved(n) for n in graph.targets(file, line)): |
| 533 | covered += 1 |
| 534 | else: |
| 535 | failures.append([file, line, key]) |
| 536 | elif cat == "d": |
| 537 | glob_ids = _global_setting_ids(root) |
| 538 | callers = _callers(root) |
| 539 | schema_cache: dict[str, set[str]] = {} |
| 540 | |
| 541 | def schema_of(f: str, scope: str) -> set[str]: |
| 542 | """Ids ``scope`` (section|block) can read from the schema of ``f``: a section's ``settings`` are |
| 543 | ``section.settings``, its ``blocks[].settings`` are ``block.settings``; a block file's own |
| 544 | ``settings`` are ``block.settings``.""" |
| 545 | if f not in schema_cache: |
| 546 | p = root / f |
| 547 | schema_cache[f] = _schema_scoped(_read(p)) if p.is_file() else (set(), set()) |
| 548 | own, blocks = schema_cache[f] |
| 549 | if f.startswith("sections/"): |
| 550 | return own if scope == "section.settings" else blocks |
| 551 | if f.startswith("blocks/"): |
| 552 | return own if scope == "block.settings" else set() |
| 553 | return set() |
| 554 |
no test coverage detected