Reuse enonce groups if availabel in annotating_by_label
This commit is contained in:
@@ -80,6 +80,10 @@ class WorkspaceTests(unittest.TestCase):
|
||||
|
||||
self.assertFalse(workspace.metadata_dir.exists())
|
||||
self.assertEqual(workspace.labels_file, root / "labels")
|
||||
self.assertEqual(workspace.label_groups_file, root / "label_groups")
|
||||
self.assertEqual(
|
||||
workspace.gemini_exam_items_file, root / "Tmp" / "exam_items.txt"
|
||||
)
|
||||
self.assertEqual(workspace.copies_dir, root / "Copies")
|
||||
self.assertEqual(workspace.annotation_dir("grouped"), root / "BGnot")
|
||||
self.assertEqual(workspace.state_database, root / ".copienator" / "state.sqlite3")
|
||||
@@ -1400,6 +1404,65 @@ class StandardCliTests(unittest.TestCase):
|
||||
(previous / "sentinel.txt").read_text(encoding="utf-8"), "old"
|
||||
)
|
||||
|
||||
def test_grouped_annotations_default_to_gemini_question_groups(self) -> None:
|
||||
module = self.modules["annotating_by_label"]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
evaluation = Path(directory) / "Exam"
|
||||
items = evaluation / "Tmp" / "exam_items.txt"
|
||||
items.parent.mkdir(parents=True)
|
||||
items.write_text(
|
||||
"# edited Gemini groups\n"
|
||||
"Ex 1 ### First question\n"
|
||||
"CONTEXT ### Shared context\n"
|
||||
"Ex 2 ### Second question\n"
|
||||
"\n---\n\n"
|
||||
"Ex 3 ### Third question\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
workspace = EvaluationWorkspace(evaluation)
|
||||
|
||||
with patch.object(module.utils, "edit_file_and_enter") as editor:
|
||||
groups = module._load_label_groups(
|
||||
workspace, ["Ex 1", "Ex 2", "Ex 3"]
|
||||
)
|
||||
|
||||
self.assertEqual(groups, [["Ex 1", "Ex 2"], ["Ex 3"]])
|
||||
self.assertEqual(
|
||||
workspace.label_groups_file.read_text(encoding="utf-8"),
|
||||
"Ex 1,Ex 2\nEx 3\n",
|
||||
)
|
||||
editor.assert_called_once_with(workspace.label_groups_file)
|
||||
|
||||
def test_grouped_annotations_fall_back_when_gemini_was_not_run(self) -> None:
|
||||
module = self.modules["annotating_by_label"]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
workspace = EvaluationWorkspace(Path(directory) / "Exam")
|
||||
workspace.root.mkdir()
|
||||
labels = ["Ex 1 : a", "Ex 1 : b", "Ex 2"]
|
||||
|
||||
with patch.object(module.utils, "edit_file_and_enter"):
|
||||
groups = module._load_label_groups(workspace, labels)
|
||||
|
||||
self.assertEqual(groups, [["Ex 1 : a", "Ex 1 : b"], ["Ex 2"]])
|
||||
|
||||
def test_existing_label_groups_override_gemini_defaults(self) -> None:
|
||||
module = self.modules["annotating_by_label"]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
workspace = EvaluationWorkspace(Path(directory) / "Exam")
|
||||
workspace.gemini_exam_items_file.parent.mkdir(parents=True)
|
||||
workspace.gemini_exam_items_file.write_text(
|
||||
"Ex 1 ### First\nEx 2 ### Second\n", encoding="utf-8"
|
||||
)
|
||||
workspace.label_groups_file.write_text(
|
||||
"Ex 1\nEx 2\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
with patch.object(module.utils, "edit_file_and_enter") as editor:
|
||||
groups = module._load_label_groups(workspace, ["Ex 1", "Ex 2"])
|
||||
|
||||
self.assertEqual(groups, [["Ex 1"], ["Ex 2"]])
|
||||
editor.assert_not_called()
|
||||
|
||||
def test_grouped_batching_does_not_split_one_student(self) -> None:
|
||||
module = self.modules["annotating_by_label"]
|
||||
image = Image.new("RGB", (10, 60), "white")
|
||||
|
||||
Reference in New Issue
Block a user