30 lines
1.2 KiB
Python
Executable File
30 lines
1.2 KiB
Python
Executable File
import unittest
|
|
import subprocess
|
|
|
|
class TestOutputComparison(unittest.TestCase):
|
|
|
|
def test_compare_output(self):
|
|
# Define the Python script to run and the expected output file
|
|
script_to_run = 'interpolation_error.py' # Replace with your script's name
|
|
expected_file = 'reference_output.txt'
|
|
|
|
# Run the script and capture the output
|
|
result = subprocess.run(['python3', script_to_run], capture_output=True, text=True)
|
|
output_lines = result.stdout.splitlines()
|
|
|
|
# Open and read the expected output file
|
|
with open(expected_file, 'r') as expected:
|
|
expected_lines = expected.read().splitlines()
|
|
|
|
# Ensure the number of lines is the same
|
|
self.assertEqual(len(output_lines), len(expected_lines),
|
|
"The number of lines in the output does not match the expected output.")
|
|
|
|
# Compare each line
|
|
for i, (output_line, expected_line) in enumerate(zip(output_lines, expected_lines)):
|
|
self.assertEqual(output_line.strip(), expected_line.strip(),
|
|
f"Line {i+1} does not match:\nOutput: {output_line}\nExpected: {expected_line}")
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|