44
55
66def test_cnn_example_openai_stdout (capsys , mock_and_capture ):
7- """
8- Example 1:
7+ """Example 1:
98 Evaluate cnn_example test using openAI model and print to stdout.
109 python -m ai_feedback --prompt code_lines --scope code \
1110 --submission test_submissions/cnn_example/cnn_submission \
@@ -30,13 +29,12 @@ def test_cnn_example_openai_stdout(capsys, mock_and_capture):
3029
3130 assert "Compare the student's code and solution code. For each mistake" in output
3231 assert "(Line 1) import numpy as np" in output
33- assert "=== cnn_submission.py ===" in output
34- assert "=== cnn_solution.py ===" in output
32+ assert '<submission file=" cnn_submission.py">' in output
33+ assert '<solution file=" cnn_solution.py">' in output
3534
3635
3736def test_cnn_example_custom_prompt_stdout (capsys , mock_and_capture ):
38- """
39- Example 2:
37+ """Example 2:
4038 Evaluate cnn_example test using openAI model and a custom prompt text, printing to stdout.
4139 python -m ai_feedback --prompt_text "Evaluate the student's code readability." \
4240 --scope code \
@@ -58,13 +56,12 @@ def test_cnn_example_custom_prompt_stdout(capsys, mock_and_capture):
5856 ]
5957 output = run_cli_and_capture (args , capsys )
6058 assert "Evaluate the student's code readability." in output
61- assert "=== cnn_submission.py ===" in output
59+ assert '<submission file=" cnn_submission.py">' in output
6260 assert "(Line 1) import numpy as np" in output
6361
6462
6563def test_pdf_example_openai_direct (capsys , mock_and_capture ):
66- """
67- Example 3:
64+ """Example 3:
6865 Evaluate pdf_example test using openAI model and direct output mode.
6966 python -m ai_feedback --prompt text_pdf_analyze --scope text \
7067 --submission test_submissions/pdf_example/student_pdf_submission.pdf \
@@ -86,3 +83,67 @@ def test_pdf_example_openai_direct(capsys, mock_and_capture):
8683 assert "Does the student correctly respond to the question, and meet all the" in output
8784 assert "student_pdf_submission.pdf" in output
8885 assert "Normalization allows each feature to have an equal influence on the mode" in output
86+
87+
88+ def test_xml_formatting_code_scope (capsys , mock_and_capture ):
89+ """
90+ Test XML formatting for file contents in code scope.
91+ Verifies that file contents use XML tags while file references remain plain text.
92+ """
93+ parent = Path (__file__ ).parent .parent .parent
94+
95+ args = [
96+ "--prompt_text" ,
97+ "File references: {file_references}\n \n File contents:\n {file_contents}" ,
98+ "--scope" ,
99+ "code" ,
100+ "--submission" ,
101+ str (parent / "test_submissions/csc108/correct_submission/correct_submission.py" ),
102+ "--solution" ,
103+ str (parent / "test_submissions/csc108/solution.py" ),
104+ "--model" ,
105+ "openai"
106+ ]
107+ output = run_cli_and_capture (args , capsys )
108+
109+ assert "The student's submission file is correct_submission.py." in output
110+ assert "The instructor's solution file is solution.py." in output
111+
112+ assert '<submission file="correct_submission.py">' in output
113+ assert '</submission>' in output
114+ assert '<solution file="solution.py">' in output
115+ assert '</solution>' in output
116+
117+ assert "(Line 1) def fizzbuzz(n: int) -> list:" in output
118+
119+
120+ def test_xml_formatting_text_scope_with_test_output (capsys , mock_and_capture ):
121+ """
122+ Test XML formatting for file contents in text scope with all file types.
123+ Verifies submission, solution, and test_output files all use XML formatting.
124+ """
125+ parent = Path (__file__ ).parent .parent .parent
126+
127+ args = [
128+ "--prompt_text" ,
129+ "File references: {file_references}\n \n File contents:\n {file_contents}" ,
130+ "--submission_type" ,
131+ "python" ,
132+ "--scope" ,
133+ "text" ,
134+ "--submission" ,
135+ str (parent / "test_submissions/ggr274_homework5/test1/student_submission.txt" ),
136+ "--solution" ,
137+ str (parent / "test_submissions/ggr274_homework5/test1/Homework_5_solution.txt" ),
138+ "--model" ,
139+ "openai"
140+ ]
141+ output = run_cli_and_capture (args , capsys )
142+
143+ assert "The student's submission file is student_submission.txt." in output
144+ assert "The instructor's solution file is Homework_5_solution.txt." in output
145+
146+ assert '<submission file="student_submission.txt">' in output
147+ assert '</submission>' in output
148+ assert '<solution file="Homework_5_solution.txt">' in output
149+ assert '</solution>' in output
0 commit comments