Repository navigation
Expand file tree
/
Copy pathexerciseTest.py
More file actions
51 lines (40 loc) · 1.53 KB
/
Copy pathexerciseTest.py
File metadata and controls
51 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import subprocess
def check_python_file(file_path):
try:
output = subprocess.check_output(['python', file_path], stderr=subprocess.STDOUT)
return True
except subprocess.CalledProcessError as e:
print(e.output)
return False
# Example usage
if check_python_file('exercise.py'):
print("The file runs without errors.")
import importlib
import openai
# load the student's script
student_script = importlib.import_module('exercise')
def test_fix_spelling():
# Prepare dummy inputs and expected outputs
input_texts = [
"I hve a bananna for brekfast.",
"The colur of the sky is rde.",
"The grass is greneer on the other side."
]
expected_outputs = [
"I have a banana for breakfast.",
"The color of the sky is red.",
"The grass is greener on the other side."
]
for input_text, expected_output in zip(input_texts, expected_outputs):
# Run the student's function
try:
output_text = student_script.fix_spelling(input_text)
if output_text != expected_output:
f"For input '{input_text}', expected '{expected_output}' but got '{output_text}'"
print(f"Test for input '{input_text}' passed!")
except Exception as e:
print(f"Test for input '{input_text}' failed: {e}")
# Run the test function
test_fix_spelling()
else:
print("The file generated errors.")