fix sorting
This commit is contained in:
@@ -910,6 +910,39 @@ class StandardCliTests(unittest.TestCase):
|
||||
)
|
||||
self.assertIsNone(viewer.accumulated_results)
|
||||
|
||||
def test_plotting_validation_preserves_manually_edited_order(self) -> None:
|
||||
module = self.modules["plotting"]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
json_path = Path(directory) / "Copie01_01.json"
|
||||
manually_ordered = [
|
||||
{"box_2d": [100, 600, 130, 700], "label": "Ex 2"},
|
||||
{"box_2d": [500, 100, 530, 200], "label": "Ex 1"},
|
||||
]
|
||||
atomic_write_json(
|
||||
json_path,
|
||||
{"name": "Student", "list": manually_ordered},
|
||||
)
|
||||
viewer = module.ImageViewer.__new__(module.ImageViewer)
|
||||
viewer.is_viewing = True
|
||||
viewer.current_json_path = json_path
|
||||
viewer.current_meta = {
|
||||
"schema": {"columns_per_file": [2]},
|
||||
"part": 1,
|
||||
}
|
||||
viewer.valid_labels = {"Ex 1", "Ex 2"}
|
||||
viewer.accumulated_results = {"name": "Student", "list": []}
|
||||
viewer.history = []
|
||||
viewer.current_pil_image = Mock()
|
||||
viewer.label = Mock()
|
||||
|
||||
viewer.on_enter(None)
|
||||
|
||||
self.assertEqual(read_json(json_path)["list"], manually_ordered)
|
||||
self.assertEqual(
|
||||
[item["label"] for item in viewer.accumulated_results["list"]],
|
||||
["Ex 2", "Ex 1"],
|
||||
)
|
||||
|
||||
def test_plotting_validates_plain_and_directional_labels(self) -> None:
|
||||
module = self.modules["plotting"]
|
||||
self.assertEqual(
|
||||
@@ -1008,6 +1041,50 @@ class StandardCliTests(unittest.TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_label_detection_writes_boxes_in_column_reading_order(self) -> None:
|
||||
module = self.modules["gemini_for_labels"]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
evaluation = Path(directory) / "Exam"
|
||||
copies = evaluation / "Copies"
|
||||
cutleft = evaluation / "Cutleft"
|
||||
copies.mkdir(parents=True)
|
||||
cutleft.mkdir()
|
||||
image = cutleft / "Copie03_02.jpg"
|
||||
image.write_bytes(b"image")
|
||||
atomic_write_json(
|
||||
cutleft / "Copie03_schema.json",
|
||||
{"columns_per_file": [2, 2]},
|
||||
)
|
||||
client = Mock()
|
||||
client.models.generate_content.return_value = Mock(
|
||||
text=(
|
||||
'{"name":"Continued","list":['
|
||||
'{"box_2d":[100,600,130,700],"label":"Ex 2"},'
|
||||
'{"box_2d":[500,100,530,200],"label":"Ex 1"},'
|
||||
'{"box_2d":[300,620,330,720],"label":"Ex 3"}]}'
|
||||
)
|
||||
)
|
||||
|
||||
module.process_copy_group(
|
||||
EvaluationWorkspace(evaluation),
|
||||
"Copie03",
|
||||
[image],
|
||||
client=client,
|
||||
labels_text="Ex 1\nEx 2\nEx 3\n",
|
||||
names_text="Student\n",
|
||||
valid_labels={"Ex 1", "Ex 2", "Ex 3"},
|
||||
valid_names={"Student", "Unknown", "Continued"},
|
||||
overwrite=True,
|
||||
sleep=lambda _seconds: None,
|
||||
target_interval=0,
|
||||
)
|
||||
|
||||
result = read_json(copies / "Copie03_02.json")
|
||||
self.assertEqual(
|
||||
[item["label"] for item in result["list"]],
|
||||
["Ex 1", "Ex 2", "Ex 3"],
|
||||
)
|
||||
|
||||
def test_label_detection_retries_unknown_labels(self) -> None:
|
||||
module = self.modules["gemini_for_labels"]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
|
||||
Reference in New Issue
Block a user