Try to fix badly encoded json tex commands from the flash-lite calls
This commit is contained in:
1 parent
32764c101b
commit
6a6ed178ef
4 files changed
+75
-8
No files matched your search
@@ -190,7 +190,9 @@ class GuiConvenienceTests(unittest.TestCase):
|
||||
command = self.app._make_command()
|
||||
self.assertEqual(command[-4:], ["crop-margins", str(source), "--workers", "5"])
|
||||
self.app._skip_step()
|
||||
self.app.update()
|
||||
self.assertEqual(self.app.state_store.step("crop_blank_margins")["status"], "skipped")
|
||||
self.assertNotEqual(self.app.current_step.id, "crop_blank_margins")
|
||||
|
||||
def test_optional_answer_bottom_crop_uses_parallel_workers_and_can_be_skipped(self):
|
||||
answers = self.evaluation / "Copies" / "Copie01"
|
||||
@@ -207,9 +209,11 @@ class GuiConvenienceTests(unittest.TestCase):
|
||||
["crop-answer-bottoms", self.app._evaluation_arg(), "--workers", "5"],
|
||||
)
|
||||
self.app._skip_step()
|
||||
self.app.update()
|
||||
self.assertEqual(
|
||||
self.app.state_store.step("crop_exercise_bottoms")["status"], "skipped"
|
||||
)
|
||||
self.assertNotEqual(self.app.current_step.id, "crop_exercise_bottoms")
|
||||
|
||||
def test_redo_targets_selected_copy_and_copies_runnable_command(self):
|
||||
for folder in ("Copies", "Copies Originales"):
|
||||
|
||||
@@ -134,6 +134,42 @@ class SelectiveGeminiTests(unittest.TestCase):
|
||||
gemini.refine_existing(self.workspace, "persp", api_client=self.client)
|
||||
self.assertEqual(self.snapshot(), before)
|
||||
|
||||
def test_rubric_latex_and_line_breaks_survive_json_and_file_writes(self):
|
||||
expected = (
|
||||
r'Barème : $f \circ g \rightarrow \frac{1}{2} \not= 0$.'
|
||||
'\n' + r'$\begin{matrix}a & b \\ c & d\end{matrix}$, $\theta$, $\beta$, $\nu$.'
|
||||
'\nUne "justification" vaut 1 point.'
|
||||
)
|
||||
self.client.models.generate_content.side_effect = [
|
||||
self.response({'rubrics': [{'label': label, 'rubric_content': expected} for label in group]})
|
||||
for group in (self.labels[:2], self.labels[2:])
|
||||
]
|
||||
gemini.refine_existing(self.workspace, 'persp', api_client=self.client)
|
||||
for label in self.labels:
|
||||
self.assertEqual((self.root / 'Persp' / label).read_bytes(),
|
||||
(label + '\n' + expected).encode('utf-8'))
|
||||
|
||||
def test_invalid_latex_escapes_are_repaired_without_retry(self):
|
||||
for command in (r'\circ', r'\rightarrow', r'\frac', r'\not', r'\theta', r'\beta'):
|
||||
with self.subTest(command=command):
|
||||
# Deliberately malformed wire JSON: do not json.dumps the command.
|
||||
broken = SimpleNamespace(text='{"rubrics":[{"label":"Ex 2","rubric_content":"$'
|
||||
+ command + '$"}]}')
|
||||
self.client.models.generate_content.reset_mock()
|
||||
self.client.models.generate_content.side_effect = [broken]
|
||||
self.assertEqual(gemini.generate_rubrics(self.client, 'context'),
|
||||
{'Ex 2': '$' + command + '$'})
|
||||
self.assertEqual(self.client.models.generate_content.call_count, 1)
|
||||
|
||||
def test_unrepairable_control_character_preserves_all_existing_rubrics(self):
|
||||
before = self.snapshot()
|
||||
broken = self.response({'rubrics': [{'label': 'Ex 2', 'rubric_content': 'invalid \x01 control'}]})
|
||||
self.client.models.generate_content.side_effect = [
|
||||
self.rubric_response(self.labels[:2]), broken]
|
||||
with self.assertRaisesRegex(ValueError, 'control characters'):
|
||||
gemini.refine_existing(self.workspace, 'persp', api_client=self.client)
|
||||
self.assertEqual(self.snapshot(), before)
|
||||
|
||||
def test_cli_dispatches_selective_modes_without_full_extraction(self):
|
||||
with patch.object(gemini, "refine_existing", return_value=ExitCode.SUCCESS) as refine, patch.object(
|
||||
gemini, "process_exam"
|
||||
|
||||
Reference in new issue
Block a user