Files
troupe-standup/wizard-work/spark/test_counter_util.py
T
ledger b14d73a8f4 volt: Q126 -- gate 9/9: nine host-bound test files rebound to the repo module, 225 census paths ledgered
(a) import-resolve: 9 OUTSIDE_REPO faults -> 0 over 138 graded files. The eight
lanes' test files now insert str(Path(__file__).resolve().parent) and resolve
their data paths from __file__; test_hermes.py is rewritten as the host probe it
always was (skills root from HERMES_SKILLS_DIR/HERMES_HOME/~/.hermes/skills, rc 0
found / 77 SKIP / 1 FAIL) instead of binding a module that does not exist.
Falsified: poisoning the repo copy reds the rebound test (rc 1) and leaves HEAD's
host-bound copy green (rc 0), both restored.

(b) path-claims: 225 new -> 0. All 225 came from sol's untracked-file census; each
was measured (0 add-commits on any ref, present on disk untracked, listed verbatim
in the census) and is a NOT_ADDED row under a batch note. One CLEARED row dropped
(spark/lwc_counter.py, resurrected at 3e667eb after Q125 retired it).

Carried in, not authored here: tools/verify.py's ninth leg and the two-line Q98
record (Sentinel's Q98 artifact), so HEAD agrees with Q98's own text.

verify --repo .: 9 legs, 9 pass, 0 fault -- gate OK. Report:
/root/.hermes/wizard-outputs/volt/2026-10-30-q126.md
2026-10-30 05:37:30 +00:00

78 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Verification tests for counter_util.py"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from counter_util import count_words, count_items, most_common, counter_to_dict, extract_counter_description
from collections import Counter
def test_word_counting():
"""Test word counting functionality."""
text = "the quick brown fox jumps over the lazy dog the fox is quick"
c = count_words(text)
assert counter_to_dict(c)['the'] == 3, "Word count 'the' failed"
assert counter_to_dict(c)['fox'] == 2, "Word count 'fox' failed"
assert most_common(c, 3) == [('the', 3), ('quick', 2), ('fox', 2)], "Most common failed"
return True
def test_counter_missing_key():
"""Test that Counter returns 0 for missing keys."""
items = ['a', 'b', 'a', 'c']
c = count_items(items)
assert c['a'] == 2, "Counter 'a' count failed"
assert c['missing'] == 0, "Counter should return 0 for missing keys"
return True
def test_counter_operations():
"""Test Counter arithmetic operations."""
c1 = Counter(['a', 'b', 'a'])
c2 = Counter(['a', 'b', 'b'])
assert counter_to_dict(c1 + c2)['a'] == 3, "Addition failed"
assert counter_to_dict(c1 & c2)['a'] == 1, "Intersection failed"
assert counter_to_dict(c1 | c2)['b'] == 2, "Union failed"
return True
def test_extraction():
"""Test documentation extraction from actual web-extracted format."""
# This matches the actual format from docs.python.org/web_extract
doc_content = """| `namedtuple()` | factory function for creating tuple subclasses with named fields |
| `deque` | list-like container with fast appends and pops on either end |
| `ChainMap` | dict-like class for creating a single view of multiple mappings |
| `Counter` | dict subclass for counting [hashable](https://docs.python.org/3/glossary.html) objects |"""
result = extract_counter_description(doc_content)
# Should extract description mentioning Counter
assert 'Counter' in result['description'] or 'description' in result, "Extraction failed - no content"
return True
if __name__ == "__main__":
tests = [
("word_counting", test_word_counting),
("counter_missing_key", test_counter_missing_key),
("counter_operations", test_counter_operations),
("extraction", test_extraction),
]
passed = 0
failed = 0
for name, test in tests:
try:
if test():
print(f"PASS: {name}")
passed += 1
else:
print(f"FAIL: {name}")
failed += 1
except AssertionError as e:
print(f"FAIL: {name} - {e}")
failed += 1
except Exception as e:
print(f"ERROR: {name} - {e}")
failed += 1
print(f"\nResults: {passed} passed, {failed} failed")
sys.exit(0 if failed == 0 else 1)