generated from dopt-python/py311
Cython Integration and Test Case Enhancements #1
BIN
tests/_img/failures/window_15_fail_electrode.bmp
Normal file
BIN
tests/_img/failures/window_15_fail_electrode.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 MiB |
BIN
tests/_img/failures/window_19_fail_model.bmp
Normal file
BIN
tests/_img/failures/window_19_fail_model.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 MiB |
BIN
tests/_models/patchcore_model_left_hand_side.pth
Normal file
BIN
tests/_models/patchcore_model_left_hand_side.pth
Normal file
Binary file not shown.
BIN
tests/_models/patchcore_model_right_hand_side.pth
Normal file
BIN
tests/_models/patchcore_model_right_hand_side.pth
Normal file
Binary file not shown.
1
tests/_results/window_19_fail_model.csv
Normal file
1
tests/_results/window_19_fail_model.csv
Normal file
@ -0,0 +1 @@
|
||||
1177,318;804,803;947509,0;876,575;808,853;709020,9;952,191;804,781;766305,3;944,223;792,829;748607,2;838,797;804,902;675148,9;1203,187;792,829;953921,4;0;0
|
||||
|
BIN
tests/_results/window_19_fail_model_Heatmap.png
Normal file
BIN
tests/_results/window_19_fail_model_Heatmap.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
62
tests/conftest.py
Normal file
62
tests/conftest.py
Normal file
@ -0,0 +1,62 @@
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from dopt_sensor_anomalies.constants import MODEL_FOLDER_NAME
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def setup_temp_dir(tmp_path_factory):
|
||||
tmp_dir = tmp_path_factory.mktemp("root")
|
||||
folder_structure = "lib/folder"
|
||||
pth = tmp_dir / folder_structure
|
||||
pth.mkdir(parents=True, exist_ok=True)
|
||||
# models
|
||||
pth_models = tmp_dir / MODEL_FOLDER_NAME
|
||||
pth_models.mkdir(parents=True, exist_ok=True)
|
||||
_root_imgs = (Path(__file__).parent / "_models").glob("*.pth")
|
||||
for model in _root_imgs:
|
||||
dst = pth_models / model.name
|
||||
shutil.copy(model, dst)
|
||||
# images
|
||||
pth_img = tmp_dir / "images"
|
||||
pth_img.mkdir(parents=True, exist_ok=True)
|
||||
_root_imgs = (Path(__file__).parent / "_img").glob("**/*.bmp")
|
||||
for img in _root_imgs:
|
||||
dst = pth_img / img.name
|
||||
shutil.copy(img, dst)
|
||||
|
||||
with patch("dopt_sensor_anomalies._find_paths.LIB_ROOT_PATH", pth):
|
||||
yield tmp_dir
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def results_folder(setup_temp_dir) -> Path:
|
||||
if os.getenv("DOPT_WRITE_RESULTS", False):
|
||||
results_base = Path(__file__).parent
|
||||
else:
|
||||
results_base = setup_temp_dir
|
||||
results = results_base / "_results"
|
||||
if not results.exists():
|
||||
results.mkdir()
|
||||
|
||||
return results
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def path_img_with_failure_ElectrodeCount(setup_temp_dir) -> Path:
|
||||
filename = "window_15_fail_electrode.bmp"
|
||||
pth_img = setup_temp_dir / f"images/{filename}"
|
||||
assert pth_img.exists(), "failure image not existing"
|
||||
return pth_img
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def path_img_with_failure_TrainedModel(setup_temp_dir) -> Path:
|
||||
filename = "window_19_fail_model.bmp"
|
||||
pth_img = setup_temp_dir / f"images/{filename}"
|
||||
assert pth_img.exists(), "failure image not existing"
|
||||
return pth_img
|
||||
@ -1,10 +1,14 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import dopt_sensor_anomalies._find_paths
|
||||
import dopt_sensor_anomalies.detection as detect
|
||||
import dopt_sensor_anomalies.types as t
|
||||
from dopt_sensor_anomalies import constants
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@ -84,3 +88,40 @@ def test_measure_length(single_img_path):
|
||||
assert 235 < img_right.shape[0] < 260
|
||||
assert 910 < img_right.shape[1] < 960
|
||||
assert img_right.shape[2] == 3
|
||||
|
||||
|
||||
@pytest.mark.new
|
||||
@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib")
|
||||
def test_isolated_pipeline(results_folder, path_img_with_failure_TrainedModel):
|
||||
pixels_per_metric_X: float = 0.251
|
||||
pixels_per_metric_Y: float = 0.251
|
||||
MODEL_FOLDER = dopt_sensor_anomalies._find_paths.get_model_folder()
|
||||
assert MODEL_FOLDER.exists(), "model folder not existing"
|
||||
DETECTION_MODELS = dopt_sensor_anomalies._find_paths.get_detection_models(MODEL_FOLDER)
|
||||
assert DETECTION_MODELS["left"].exists()
|
||||
assert DETECTION_MODELS["right"].exists()
|
||||
data_csv, sensor_images = detect.measure_length(
|
||||
path_img_with_failure_TrainedModel,
|
||||
pixels_per_metric_X,
|
||||
pixels_per_metric_Y,
|
||||
)
|
||||
print(">>>>>>> Data: ", data_csv)
|
||||
# measured sizes
|
||||
assert len(data_csv) == 18
|
||||
assert sensor_images["left"] is not None
|
||||
assert sensor_images["right"] is not None
|
||||
detect.anomaly_detection(
|
||||
file_path=path_img_with_failure_TrainedModel,
|
||||
detection_models=DETECTION_MODELS,
|
||||
data_csv=data_csv,
|
||||
sensor_images=sensor_images,
|
||||
)
|
||||
# check files for existence
|
||||
root_img = path_img_with_failure_TrainedModel.parent
|
||||
file_stem = path_img_with_failure_TrainedModel.stem
|
||||
csv_file = root_img / f"{file_stem}.csv"
|
||||
heatmap_file = root_img / f"{file_stem}{constants.HEATMAP_FILENAME_SUFFIX}.png"
|
||||
assert csv_file.exists()
|
||||
assert heatmap_file.exists()
|
||||
shutil.copy(csv_file, (results_folder / csv_file.name))
|
||||
shutil.copy(heatmap_file, (results_folder / heatmap_file.name))
|
||||
|
||||
@ -5,16 +5,23 @@ import pytest
|
||||
|
||||
from dopt_sensor_anomalies import _find_paths
|
||||
|
||||
# @pytest.fixture(scope="session", autouse=True)
|
||||
# def setup_temp_dir(tmp_path_factory):
|
||||
# tmp_dir = tmp_path_factory.mktemp("root")
|
||||
# folder_structure = "lib/folder"
|
||||
# pth = tmp_dir / folder_structure
|
||||
# pth.mkdir(parents=True, exist_ok=True)
|
||||
# # models
|
||||
# folder_models = "lib/models"
|
||||
# pth_models = tmp_dir / folder_models
|
||||
# pth_models.mkdir(parents=True, exist_ok=True)
|
||||
# _root_models = (Path(__file__).parent / "_models").glob("*.pth")
|
||||
# for model in _root_models:
|
||||
# dst = pth_models / model.name
|
||||
# shutil.copy(model, dst)
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_temp_dir(tmp_path_factory):
|
||||
tmp_dir = tmp_path_factory.mktemp("root")
|
||||
folder_structure = "lib/folder"
|
||||
pth = tmp_dir / folder_structure
|
||||
pth.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with patch("dopt_sensor_anomalies._find_paths.LIB_ROOT_PATH", pth):
|
||||
yield
|
||||
# with patch("dopt_sensor_anomalies._find_paths.LIB_ROOT_PATH", pth):
|
||||
# yield
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user