Files
troupe-standup/wizard-work/spark/test_text_stats.py
T

33 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Simple test to verify text_stats.py output matches wc."""
import subprocess
import sys
# Test with this file itself
filepath = '/root/troupe-standup/wizard-work/spark/text_stats.py'
# Run our script
result = subprocess.run(['python3', filepath, filepath], capture_output=True, text=True)
our_output = result.stdout.strip()
# Run wc
wc_result = subprocess.run(['wc', filepath], capture_output=True, text=True)
wc_parts = wc_result.stdout.strip().split()
wc_lines, wc_words, wc_chars = wc_parts[0], wc_parts[1], wc_parts[2]
# Extract our values
import re
match = re.search(r'(\d+) lines, (\d+) words, (\d+) chars', our_output)
if match:
our_lines, our_words, our_chars = match.groups()
if our_lines == wc_lines and our_words == wc_words and our_chars == wc_chars:
print(f"PASS: {our_output}")
print(f" wc: {wc_lines} {wc_words} {wc_chars}")
sys.exit(0)
else:
print(f"FAIL: {our_output}")
print(f" wc: {wc_lines} {wc_words} {wc_chars}")
sys.exit(1)
else:
print(f"FAIL: Could not parse output: {our_output}")
sys.exit(1)