Skip to content

Commit 8284ab5

Browse files
committed
add header & footer to the question
1 parent 39d96c2 commit 8284ab5

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

ai_tutor.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,14 @@ def get_initial_instruction(questions:List[str],language:str) -> str:
142142
initial_instruction = f'In {language}, please comment on the student code given the assignment instruction.'
143143
return initial_instruction
144144

145-
questions = [get_initial_instruction(questions, human_language)] + questions
146-
147-
# Add the code and instructions
148-
questions.append(get_code_instruction(student_files, readme_file, human_language))
145+
146+
questions = (
147+
# Add the initial instruction
148+
[get_initial_instruction(questions, human_language), get_question_header(human_language)]
149+
+ questions
150+
# Add the code and instructions
151+
+ [get_question_footer(human_language), get_code_instruction(student_files, readme_file, human_language)]
152+
)
149153

150154
# Join all questions into a single string
151155
consolidated_question = "\n\n".join(questions)

tests/test_ai_tutor.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222

2323

2424
@pytest.fixture
25-
def json_dict() -> Dict[str, Union[str, List]]:
26-
with open(test_folder/'sample_report.json', 'r') as f:
25+
def sample_report_path() -> pathlib.Path:
26+
return test_folder/'sample_report.json'
27+
28+
29+
@pytest.fixture
30+
def json_dict(sample_report_path) -> Dict[str, Union[str, List]]:
31+
with sample_report_path.open('rt') as f:
2732
result = json.load(f)
2833
return result
2934

@@ -35,8 +40,13 @@ def test_collect_longrepr(json_dict):
3540

3641

3742
@pytest.fixture
38-
def json_dict_div_zero_try_except() -> Dict[str, Union[str, List]]:
39-
with open(test_folder/'json_dict_div_zero_try_except.json', 'r') as f:
43+
def div_zero_report_path() -> pathlib.Path:
44+
return test_folder/'json_dict_div_zero_try_except.json'
45+
46+
47+
@pytest.fixture
48+
def json_dict_div_zero_try_except(div_zero_report_path:pathlib.Path) -> Dict[str, Union[str, List]]:
49+
with div_zero_report_path.open('rt') as f:
4050
result = json.load(f)
4151
return result
4252

@@ -139,5 +149,26 @@ def test_get_code_instruction(
139149
assert instruction in result
140150

141151

152+
def test_get_the_question(
153+
sample_report_path:pathlib.Path,
154+
div_zero_report_path:pathlib.Path,
155+
sample_student_code_path:pathlib.Path,
156+
sample_readme_path:pathlib.Path,
157+
human_language:str,
158+
homework:str, msg:str,
159+
instruction:str,
160+
):
161+
result = ai_tutor.get_the_question(
162+
report_paths=(sample_report_path,div_zero_report_path),
163+
student_files=(sample_student_code_path,),
164+
readme_file=sample_readme_path,
165+
human_language=human_language,
166+
).lower()
167+
168+
assert homework in result
169+
assert msg in result
170+
assert instruction in result
171+
172+
142173
if '__main__' == __name__:
143174
pytest.main([__file__])

0 commit comments

Comments
 (0)