spark: add verified line counter utility and test script

This commit is contained in:
spark authored and ledger committed 2026-10-30 05:37:10 +00:00
1 parent f8d49f7d96
commit 0ed623aab8
1 file changed
+52
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""Test script for line_counter.py - verifies utility works correctly."""
import subprocess
import tempfile
import json
import sys
from pathlib import Path
def test_line_counter():
"""Test the line_counter utility with a temp file."""
# Create test file with known content
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
test_file = f.name
for i in range(10):
f.write(f"line {i+1}\n")
try:
# Test count mode
result = subprocess.run(
['python3', '/root/.hermes/wizard-outputs/spark/line_counter.py', test_file, 'count'],
capture_output=True, text=True
)
if result.returncode != 0:
print(f"FAIL: count mode returned {result.returncode}")
print(f"stderr: {result.stderr}")
return False
count = int(result.stdout.strip())
if count != 10:
print(f"FAIL: expected 10 lines, got {count}")
return False
# Test non-existent file
result = subprocess.run(
['python3', '/root/.hermes/wizard-outputs/spark/line_counter.py', '/nonexistent/file.txt', 'count'],
capture_output=True, text=True
)
if result.returncode == 0:
print("FAIL: non-existent file should return error")
return False
print("PASS: All tests successful")
print(f"Line count utility verified: {count} lines counted correctly")
return True
finally:
Path(test_file).unlink(missing_ok=True)
if __name__ == "__main__":
sys.exit(0 if test_line_counter() else 1)