diff --git a/wizard-work/beam/verify_wordcount_test.py b/wizard-work/beam/verify_wordcount_test.py new file mode 100644 index 0000000..ca99b75 --- /dev/null +++ b/wizard-work/beam/verify_wordcount_test.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +"""Verification test for wordcount.py - must match wc output exactly.""" +import subprocess +import sys + + +def main(): + # Create test file with known content + test_content = "Hello world\nThis is a test file\nWith three lines\n" + test_file = "/root/troupe-standup/test_verification.txt" + with open(test_file, 'w') as f: + f.write(test_content) + + # Get wc output + wc_result = subprocess.run(['wc', test_file], capture_output=True, text=True) + wc_lines, wc_words, wc_chars = map(int, wc_result.stdout.strip().split()[:3]) + + # Get wordcount.py output + pyc_result = subprocess.run( + ['python3', '/root/.hermes/wizard-outputs/spark/wordcount.py', test_file], + capture_output=True, text=True + ) + + if pyc_result.returncode != 0: + print(f"FAIL: wordcount.py returned {pyc_result.returncode}") + print(pyc_result.stderr) + return 1 + + parts = pyc_result.stdout.strip().split() + py_lines, py_words, py_chars = int(parts[0]), int(parts[1]), int(parts[2]) + + print(f"wc: {wc_lines} lines, {wc_words} words, {wc_chars} chars") + print(f"wordcount.py: {py_lines} lines, {py_words} words, {py_chars} chars") + + if (wc_lines == py_lines and wc_words == py_words and wc_chars == py_chars): + print("PASS: outputs match") + return 0 + else: + print("FAIL: outputs do not match") + return 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/wizard-work/spark/verify_wordcount_test.py b/wizard-work/spark/verify_wordcount_test.py index bbb8a3b..ca99b75 100644 --- a/wizard-work/spark/verify_wordcount_test.py +++ b/wizard-work/spark/verify_wordcount_test.py @@ -2,39 +2,43 @@ """Verification test for wordcount.py - must match wc output exactly.""" import subprocess import sys -import tempfile -import os -# Create test file with known content -test_content = "Hello world\nThis is a test file\nWith three lines\n" -test_file = "/root/troupe-standup/test_verification.txt" -with open(test_file, 'w') as f: - f.write(test_content) -# Get wc output -wc_result = subprocess.run(['wc', test_file], capture_output=True, text=True) -wc_lines, wc_words, wc_chars = map(int, wc_result.stdout.strip().split()[:3]) +def main(): + # Create test file with known content + test_content = "Hello world\nThis is a test file\nWith three lines\n" + test_file = "/root/troupe-standup/test_verification.txt" + with open(test_file, 'w') as f: + f.write(test_content) -# Get wordcount.py output -pyc_result = subprocess.run( - ['python3', '/root/.hermes/wizard-outputs/spark/wordcount.py', test_file], - capture_output=True, text=True -) + # Get wc output + wc_result = subprocess.run(['wc', test_file], capture_output=True, text=True) + wc_lines, wc_words, wc_chars = map(int, wc_result.stdout.strip().split()[:3]) -if pyc_result.returncode != 0: - print(f"FAIL: wordcount.py returned {pyc_result.returncode}") - print(pyc_result.stderr) - sys.exit(1) + # Get wordcount.py output + pyc_result = subprocess.run( + ['python3', '/root/.hermes/wizard-outputs/spark/wordcount.py', test_file], + capture_output=True, text=True + ) -parts = pyc_result.stdout.strip().split() -py_lines, py_words, py_chars = int(parts[0]), int(parts[1]), int(parts[2]) + if pyc_result.returncode != 0: + print(f"FAIL: wordcount.py returned {pyc_result.returncode}") + print(pyc_result.stderr) + return 1 -print(f"wc: {wc_lines} lines, {wc_words} words, {wc_chars} chars") -print(f"wordcount.py: {py_lines} lines, {py_words} words, {py_chars} chars") + parts = pyc_result.stdout.strip().split() + py_lines, py_words, py_chars = int(parts[0]), int(parts[1]), int(parts[2]) -if (wc_lines == py_lines and wc_words == py_words and wc_chars == py_chars): - print("PASS: outputs match") - sys.exit(0) -else: - print("FAIL: outputs do not match") - sys.exit(1) \ No newline at end of file + print(f"wc: {wc_lines} lines, {wc_words} words, {wc_chars} chars") + print(f"wordcount.py: {py_lines} lines, {py_words} words, {py_chars} chars") + + if (wc_lines == py_lines and wc_words == py_words and wc_chars == py_chars): + print("PASS: outputs match") + return 0 + else: + print("FAIL: outputs do not match") + return 1 + + +if __name__ == '__main__': + sys.exit(main())