From 70389acaf4d7bcac0d24c359bd05c757a7b84f61 Mon Sep 17 00:00:00 2001 From: NolanB <nboukachab@teklia.com> Date: Tue, 29 Nov 2022 12:10:42 +0100 Subject: [PATCH] update code and modif the path of SAMPLES_DIR and tests --- arkindex_worker/worker/training.py | 15 +++------------ tests/conftest.py | 2 +- tests/test_elements_worker/test_training.py | 2 +- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/arkindex_worker/worker/training.py b/arkindex_worker/worker/training.py index c33c13d1..ffe52d6f 100644 --- a/arkindex_worker/worker/training.py +++ b/arkindex_worker/worker/training.py @@ -50,23 +50,15 @@ def create_archive(path: DirPath) -> Tuple[Path, Hash, FileSize, Hash]: # Create an uncompressed tar archive with all the needed files # Files hierarchy ifs kept in the archive. - file_list = [] - with tarfile.open(path_to_tar_archive, "w") as tar: - for p in path.glob("**/*"): - x = p.relative_to(path) - - tar.add(p, arcname=x, recursive=False) - if p.is_dir(): - continue - - file_list.append(p) + with tarfile.open(path_to_tar_archive, "w") as tar: + tar.add(path) + file_list = [member for member in tar.getnames() if os.path.isfile(member)] # Sort by path file_list.sort() # Compute hash of the files for file_path in file_list: - print("BOOM PATH", file_path) with open(file_path, "rb") as file_data: for chunk in iter(lambda: file_data.read(CHUNK_SIZE), b""): content_hasher.update(chunk) @@ -102,7 +94,6 @@ class TrainingMixin(object): model_id: str, tag: Optional[str] = None, description: Optional[str] = None, - use_parent_folder=False, ): """ This method creates a model archive and its associated hash, diff --git a/tests/conftest.py b/tests/conftest.py index 03a1b841..8b6f16ef 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,7 +26,7 @@ from arkindex_worker.worker import BaseWorker, ElementsWorker from arkindex_worker.worker.transcription import TextOrientation FIXTURES_DIR = Path(__file__).resolve().parent / "data" -SAMPLES_DIR = Path(__file__).resolve().parent / "samples" +SAMPLES_DIR = Path("tests") / "samples" __yaml_cache = {} diff --git a/tests/test_elements_worker/test_training.py b/tests/test_elements_worker/test_training.py index 519db44b..4448554d 100644 --- a/tests/test_elements_worker/test_training.py +++ b/tests/test_elements_worker/test_training.py @@ -58,7 +58,7 @@ def test_create_archive_with_subfolder(model_file_dir_with_subfolder): assert ( hash == "e2fa86cefc33b24502ad4151a638dd29" ), "Hash was not properly computed" - assert 300 < size < 1200 + assert 300 < size < 1500 assert not os.path.exists(zst_archive_path), "Auto removal failed" -- GitLab