extension de export/import aux autres modes de génération
This commit is contained in:
+90
-2
@@ -32,9 +32,11 @@ from copienator.annotation_actions import apply_checkbox_actions, apply_score_ov
|
||||
from copienator.annotation_data import AnnotationLoadResult, load_annotation_data
|
||||
from copienator.filesystem import staged_directory, staged_files
|
||||
from copienator_gui.app import (
|
||||
CopienatorApp,
|
||||
DEFAULT_HTTPS_PROXY,
|
||||
build_runner_environment,
|
||||
copy_pdf_paths,
|
||||
detected_annotation_directories,
|
||||
has_manual_conflicts,
|
||||
plotting_shortcut_lines,
|
||||
process_status,
|
||||
@@ -453,8 +455,16 @@ class StandardCliTests(unittest.TestCase):
|
||||
"personal",
|
||||
{"target": evaluation},
|
||||
),
|
||||
"export": ("export", "default", {"target": evaluation, "refaire": True}),
|
||||
"import": ("import", "default", {"target": evaluation, "refaire": True}),
|
||||
"export": (
|
||||
"export",
|
||||
"default",
|
||||
{"target": evaluation, "annotation_dir": "Bnot", "refaire": True},
|
||||
),
|
||||
"import": (
|
||||
"import",
|
||||
"default",
|
||||
{"target": evaluation, "annotation_dir": "Anot", "refaire": True},
|
||||
),
|
||||
"giving_names": (
|
||||
"giving_names",
|
||||
"default",
|
||||
@@ -596,6 +606,23 @@ class StandardCliTests(unittest.TestCase):
|
||||
exported = base / "Export" / "Exam" / "Ex 1.pdf"
|
||||
self.assertEqual(exported.read_bytes(), b"annotated")
|
||||
|
||||
def test_export_accepts_each_annotation_directory(self) -> None:
|
||||
module = self.modules["export"]
|
||||
for annotation_dir in ("Anot", "Bnot"):
|
||||
with self.subTest(annotation_dir=annotation_dir), tempfile.TemporaryDirectory() as directory:
|
||||
base = Path(directory)
|
||||
evaluation = base / "Exam"
|
||||
source = evaluation / annotation_dir / "Copie01"
|
||||
source.mkdir(parents=True)
|
||||
suffix = ".jpg" if annotation_dir == "Anot" else ".pdf"
|
||||
(source / f"Concat{suffix}").write_bytes(annotation_dir.encode())
|
||||
with patch.object(module, "EXPORT_DIR", base / "Export"):
|
||||
self.assertEqual(module.main([str(evaluation), annotation_dir]), 0)
|
||||
self.assertEqual(
|
||||
(base / "Export" / "Exam" / f"Copie01{suffix}").read_bytes(),
|
||||
annotation_dir.encode(),
|
||||
)
|
||||
|
||||
def test_import_main_copies_handwritten_annotations(self) -> None:
|
||||
module = self.modules["import"]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
@@ -612,6 +639,24 @@ class StandardCliTests(unittest.TestCase):
|
||||
(target / "Concat_annotated.pdf").read_bytes(), b"handwritten"
|
||||
)
|
||||
|
||||
def test_import_accepts_each_annotation_directory(self) -> None:
|
||||
module = self.modules["import"]
|
||||
for annotation_dir in ("Anot", "Bnot"):
|
||||
with self.subTest(annotation_dir=annotation_dir), tempfile.TemporaryDirectory() as directory:
|
||||
base = Path(directory)
|
||||
evaluation = base / "Exam"
|
||||
target = evaluation / annotation_dir / "Copie01"
|
||||
target.mkdir(parents=True)
|
||||
import_dir = base / "Import"
|
||||
import_dir.mkdir()
|
||||
suffix = ".jpg" if annotation_dir == "Anot" else ".pdf"
|
||||
(import_dir / f"Copie01{suffix}").write_bytes(b"handwritten")
|
||||
with patch.object(module, "IMPORT_DIR", import_dir):
|
||||
self.assertEqual(module.main([str(evaluation), annotation_dir]), 0)
|
||||
self.assertEqual(
|
||||
(target / f"Concat_annotated{suffix}").read_bytes(), b"handwritten"
|
||||
)
|
||||
|
||||
def test_giving_names_main_builds_return_directory(self) -> None:
|
||||
module = self.modules["giving_names"]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
@@ -1406,6 +1451,15 @@ class WorkflowTests(unittest.TestCase):
|
||||
def test_review_persp_has_shorter_title(self) -> None:
|
||||
self.assertEqual(self.steps["review_persp"].title, "Relire les barèmes")
|
||||
|
||||
def test_export_has_shorter_title_and_annotation_argument(self) -> None:
|
||||
self.assertEqual(self.steps["export"].title, "Exporter")
|
||||
command = self.command(
|
||||
"export",
|
||||
"default",
|
||||
{"target": self.evaluation, "annotation_dir": "Bnot"},
|
||||
)
|
||||
self.assertEqual(command[3:], [self.evaluation, "Bnot"])
|
||||
|
||||
def test_copy_listing_prefers_processed_copies(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
evaluation = Path(directory)
|
||||
@@ -1421,6 +1475,40 @@ class WorkflowTests(unittest.TestCase):
|
||||
["Copie01.pdf", "Copie02.pdf"],
|
||||
)
|
||||
|
||||
def test_annotation_directory_detection_uses_known_directories(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
evaluation = Path(directory)
|
||||
(evaluation / "Bnot").mkdir()
|
||||
(evaluation / "Anot").mkdir()
|
||||
(evaluation / "Other").mkdir()
|
||||
self.assertEqual(
|
||||
detected_annotation_directories(evaluation), ("Bnot", "Anot")
|
||||
)
|
||||
|
||||
def test_export_and_import_defaults_follow_previous_runs(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
evaluation = Path(directory)
|
||||
(evaluation / "Bnot").mkdir()
|
||||
(evaluation / "Anot").mkdir()
|
||||
store = StateStore()
|
||||
store.load(evaluation)
|
||||
store.update_step("annotation", last_run_variant="simple")
|
||||
app = SimpleNamespace(evaluation=evaluation, state_store=store)
|
||||
|
||||
choices, default = CopienatorApp._annotation_directory_choices(
|
||||
app, "export"
|
||||
)
|
||||
self.assertEqual(choices, ("Bnot", "Anot"))
|
||||
self.assertEqual(default, "Anot")
|
||||
|
||||
store.update_step(
|
||||
"export", last_run_values={"annotation_dir": "Bnot"}
|
||||
)
|
||||
_choices, default = CopienatorApp._annotation_directory_choices(
|
||||
app, "import"
|
||||
)
|
||||
self.assertEqual(default, "Bnot")
|
||||
|
||||
def test_plotting_shortcuts_describe_open_actions(self) -> None:
|
||||
rendered = "\n".join(plotting_shortcut_lines())
|
||||
self.assertIn("ouvrir l’énoncé", rendered)
|
||||
|
||||
Reference in New Issue
Block a user