Skip to content
Snippets Groups Projects
Commit b4add821 authored by Alessia Saccardo's avatar Alessia Saccardo
Browse files

complete fixing of unit tests

parent 406a5c49
No related branches found
No related tags found
2 merge requests!145Refactor tests for processing and adapt it to new library structure, plus fix...,!140Fix unit tests
This commit is part of merge request !145. Comments created here will be created in the context of that merge request.
...@@ -8,7 +8,7 @@ import tifffile as tiff ...@@ -8,7 +8,7 @@ import tifffile as tiff
import zarr import zarr
from tqdm import tqdm from tqdm import tqdm
from qim3d.utils import stringify_path from qim3d.utils._misc import stringify_path
from qim3d.io import save from qim3d.io import save
......
...@@ -24,9 +24,9 @@ from PIL import Image, UnidentifiedImageError ...@@ -24,9 +24,9 @@ from PIL import Image, UnidentifiedImageError
import qim3d import qim3d
from qim3d.utils import log from qim3d.utils import log
from qim3d.utils import get_file_size, sizeof, stringify_path from qim3d.utils._misc import get_file_size, sizeof, stringify_path
from qim3d.utils import Memory from qim3d.utils import Memory
from qim3d.utils import FileLoadingProgressBar from qim3d.utils._progress_bar import FileLoadingProgressBar
import trimesh import trimesh
dask.config.set(scheduler="processes") dask.config.set(scheduler="processes")
...@@ -716,7 +716,7 @@ class DataLoader: ...@@ -716,7 +716,7 @@ class DataLoader:
# Fails # Fails
else: else:
# Find the closest matching path to warn the user # Find the closest matching path to warn the user
similar_paths = qim3d.utils.find_similar_paths(path) similar_paths = qim3d.utils._misc.find_similar_paths(path)
if similar_paths: if similar_paths:
suggestion = similar_paths[0] # Get the closest match suggestion = similar_paths[0] # Get the closest match
......
...@@ -32,7 +32,7 @@ from skimage.transform import ( ...@@ -32,7 +32,7 @@ from skimage.transform import (
) )
from qim3d.utils import log from qim3d.utils import log
from qim3d.utils import OmeZarrExportProgressBar from qim3d.utils._progress_bar import OmeZarrExportProgressBar
from qim3d.utils._ome_zarr import get_n_chunks from qim3d.utils._ome_zarr import get_n_chunks
......
...@@ -38,7 +38,7 @@ from pydicom.uid import UID ...@@ -38,7 +38,7 @@ from pydicom.uid import UID
import trimesh import trimesh
from qim3d.utils import log from qim3d.utils import log
from qim3d.utils import sizeof, stringify_path from qim3d.utils._misc import sizeof, stringify_path
class DataSaver: class DataSaver:
......
import qim3d import qim3d
import os import os
import pytest
from pathlib import Path
import shutil
def test_download(): @pytest.fixture
folder = 'Cowry_Shell' def setup_temp_folder():
file = 'Cowry_DOWNSAMPLED.tif' """Fixture to create and clean up a temporary folder for tests."""
path = os.path.join(folder,file) folder = "Cowry_Shell"
file = "Cowry_DOWNSAMPLED.tif"
path = Path(folder) / file
dl = qim3d.io.Downloader() # Ensure clean environment before running tests
if Path(folder).exists():
shutil.rmtree(folder)
yield folder, path
# Cleanup after tests
if path.exists():
path.unlink()
if Path(folder).exists():
shutil.rmtree(folder)
dl.Cowry_Shell.Cowry_DOWNSAMPLED()
def test_download(setup_temp_folder):
folder, path = setup_temp_folder
img = qim3d.io.load(path) dl = qim3d.io.Downloader()
dl.Cowry_Shell.Cowry_DOWNSAMPLED()
# Remove temp file # Verify the file was downloaded correctly
os.remove(path) assert path.exists(), f"{path} does not exist after download."
os.rmdir(folder)
img = qim3d.io.load(str(path))
assert img.shape == (500, 350, 350) assert img.shape == (500, 350, 350)
def test_get_file_size_right(): # Cleanup is handled by the fixture
coal_file = 'https://archive.compute.dtu.dk/download/public/projects/viscomp_data_repository/Coal/CoalBrikett.tif'
size = qim3d.io.downloader._get_file_size(coal_file)
assert size == 2_400_082_900
def test_get_file_size():
"""Tests for correct and incorrect file size retrieval."""
coal_file = "https://archive.compute.dtu.dk/download/public/projects/viscomp_data_repository/Coal/CoalBrikett.tif"
folder_url = "https://archive.compute.dtu.dk/files/public/projects/viscomp_data_repository/"
def test_get_file_size_wrong(): # Correct file size
file_to_folder = 'https://archive.compute.dtu.dk/files/public/projects/viscomp_data_repository/' size = qim3d.io._downloader._get_file_size(coal_file)
size = qim3d.io.downloader._get_file_size(file_to_folder) assert size == 2_400_082_900, f"Expected size mismatch for {coal_file}."
assert size == -1 # Wrong URL (not a file)
size = qim3d.io._downloader._get_file_size(folder_url)
assert size == -1, "Expected size -1 for non-file URL."
def test_extract_html(): def test_extract_html():
url = 'https://archive.compute.dtu.dk/files/public/projects/viscomp_data_repository' url = "https://archive.compute.dtu.dk/files/public/projects/viscomp_data_repository"
html = qim3d.io.downloader._extract_html(url) html = qim3d.io._downloader._extract_html(url)
assert 'data-path="/files/public/projects/viscomp_data_repository"' in html, \
"Expected HTML content not found in extracted HTML."
assert 'data-path="/files/public/projects/viscomp_data_repository"' in html
...@@ -13,15 +13,6 @@ from ._misc import ( ...@@ -13,15 +13,6 @@ from ._misc import (
get_css, get_css,
downscale_img, downscale_img,
scale_to_float16, scale_to_float16,
stringify_path,
find_similar_paths
) )
from ._server import start_http_server from ._server import start_http_server
from ._progress_bar import (
FileLoadingProgressBar,
OmeZarrExportProgressBar,
)
from ._ome_zarr import get_chunk_size
\ No newline at end of file
...@@ -153,7 +153,7 @@ def get_file_size(file_path: str) -> int: ...@@ -153,7 +153,7 @@ def get_file_size(file_path: str) -> int:
try: try:
file_size = os.path.getsize(file_path) file_size = os.path.getsize(file_path)
except FileNotFoundError: except FileNotFoundError:
similar_paths = qim3d.utils.find_similar_paths(file_path) similar_paths = qim3d.utils._misc.find_similar_paths(file_path)
if similar_paths: if similar_paths:
suggestion = similar_paths[0] # Get the closest match suggestion = similar_paths[0] # Get the closest match
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment