diff --git a/wizard-work/spark/line_counter_test.py b/wizard-work/spark/line_counter_test.py new file mode 100644 index 0000000..06b8adf --- /dev/null +++ b/wizard-work/spark/line_counter_test.py @@ -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) \ No newline at end of file