From 32ede50ba5760d9cb4d63fb22888df940c9511d9 Mon Sep 17 00:00:00 2001
From: Yoann Schneider <yschneider@teklia.com>
Date: Thu, 1 Dec 2022 10:11:51 +0100
Subject: [PATCH] add tests

---
 tests/conftest.py                              |  5 +++++
 tests/samples/root_folder/model_file.pth       |  1 +
 .../root_folder/subfolder1/model_file.pth      |  1 +
 .../root_folder/subfolder2/model_file.pth      |  1 +
 tests/test_elements_worker/test_training.py    | 18 ++++++++++++++++++
 5 files changed, 26 insertions(+)
 create mode 100644 tests/samples/root_folder/model_file.pth
 create mode 100644 tests/samples/root_folder/subfolder1/model_file.pth
 create mode 100644 tests/samples/root_folder/subfolder2/model_file.pth

diff --git a/tests/conftest.py b/tests/conftest.py
index d058dc87..1ab4047a 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -280,6 +280,11 @@ def model_file_dir():
     return SAMPLES_DIR / "model_files"
 
 
+@pytest.fixture
+def model_file_dir_with_subfolder():
+    return SAMPLES_DIR / "root_folder"
+
+
 @pytest.fixture
 def fake_dummy_worker():
     api_client = MockApiClient()
diff --git a/tests/samples/root_folder/model_file.pth b/tests/samples/root_folder/model_file.pth
new file mode 100644
index 00000000..cc78ba30
--- /dev/null
+++ b/tests/samples/root_folder/model_file.pth
@@ -0,0 +1 @@
+Wow this is actually the data of the best model ever created on Arkindex
\ No newline at end of file
diff --git a/tests/samples/root_folder/subfolder1/model_file.pth b/tests/samples/root_folder/subfolder1/model_file.pth
new file mode 100644
index 00000000..cc78ba30
--- /dev/null
+++ b/tests/samples/root_folder/subfolder1/model_file.pth
@@ -0,0 +1 @@
+Wow this is actually the data of the best model ever created on Arkindex
\ No newline at end of file
diff --git a/tests/samples/root_folder/subfolder2/model_file.pth b/tests/samples/root_folder/subfolder2/model_file.pth
new file mode 100644
index 00000000..cc78ba30
--- /dev/null
+++ b/tests/samples/root_folder/subfolder2/model_file.pth
@@ -0,0 +1 @@
+Wow this is actually the data of the best model ever created on Arkindex
\ No newline at end of file
diff --git a/tests/test_elements_worker/test_training.py b/tests/test_elements_worker/test_training.py
index e8f41962..551fdf6d 100644
--- a/tests/test_elements_worker/test_training.py
+++ b/tests/test_elements_worker/test_training.py
@@ -45,6 +45,24 @@ def test_create_archive(model_file_dir):
     assert not os.path.exists(zst_archive_path), "Auto removal failed"
 
 
+def test_create_archive_with_subfolder(model_file_dir_with_subfolder):
+    """Create an archive when the model's file is in a folder containing a subfolder"""
+
+    with create_archive(path=model_file_dir_with_subfolder) as (
+        zst_archive_path,
+        hash,
+        size,
+        archive_hash,
+    ):
+        assert os.path.exists(zst_archive_path), "The archive was not created"
+        assert (
+            hash == "3e453881404689e6e125144d2db3e605"
+        ), "Hash was not properly computed"
+        assert 300 < size < 1500
+
+    assert not os.path.exists(zst_archive_path), "Auto removal failed"
+
+
 @pytest.mark.parametrize(
     "tag, description",
     [
-- 
GitLab