generated from dopt-python/py311
add C# interface module, closes #4
This commit is contained in:
parent
a41cc5a312
commit
712a1f534a
14
src/dopt_sensor_anomalies/_csharp_interface.py
Normal file
14
src/dopt_sensor_anomalies/_csharp_interface.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from dopt_sensor_anomalies import detection
|
||||||
|
|
||||||
|
|
||||||
|
def sensor_anomalies_detection(
|
||||||
|
user_img_path: str,
|
||||||
|
pixels_per_metric_X: float,
|
||||||
|
pixels_per_metric_Y: float,
|
||||||
|
) -> None:
|
||||||
|
res = detection.pipeline(
|
||||||
|
user_img_path=user_img_path,
|
||||||
|
pixels_per_metric_X=pixels_per_metric_X,
|
||||||
|
pixels_per_metric_Y=pixels_per_metric_Y,
|
||||||
|
)
|
||||||
|
res.unwrap()
|
||||||
1
tests/_results/csharp_interface/window_19_fail_model.csv
Normal file
1
tests/_results/csharp_interface/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/csharp_interface/window_19_fail_model_Heatmap.png
Normal file
BIN
tests/_results/csharp_interface/window_19_fail_model_Heatmap.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
64
tests/test_csharp_interface.py
Normal file
64
tests/test_csharp_interface.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import shutil
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from dopt_sensor_anomalies import _csharp_interface, constants, errors
|
||||||
|
|
||||||
|
|
||||||
|
@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib")
|
||||||
|
def test_sensor_anomalies_detection_FailImagePath(setup_temp_dir):
|
||||||
|
img_path = str(setup_temp_dir / "not-existing.bmp")
|
||||||
|
pixels_per_metric_X: float = 0.251
|
||||||
|
pixels_per_metric_Y: float = 0.251
|
||||||
|
|
||||||
|
MESSAGE = "The provided path seems not to exist"
|
||||||
|
|
||||||
|
with pytest.raises(FileNotFoundError, match=MESSAGE):
|
||||||
|
_csharp_interface.sensor_anomalies_detection(
|
||||||
|
img_path, pixels_per_metric_X, pixels_per_metric_Y
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib")
|
||||||
|
def test_sensor_anomalies_detection_FailElectrodeCount(path_img_with_failure_ElectrodeCount):
|
||||||
|
img_path = str(path_img_with_failure_ElectrodeCount)
|
||||||
|
pixels_per_metric_X: float = 0.251
|
||||||
|
pixels_per_metric_Y: float = 0.251
|
||||||
|
|
||||||
|
MESSAGE = "Number of counted electrodes does not match the"
|
||||||
|
|
||||||
|
with pytest.raises(errors.InvalidElectrodeCount, match=MESSAGE):
|
||||||
|
_csharp_interface.sensor_anomalies_detection(
|
||||||
|
img_path, pixels_per_metric_X, pixels_per_metric_Y
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib")
|
||||||
|
def test_sensor_anomalies_detection_Success(
|
||||||
|
results_folder, path_img_with_failure_TrainedModel
|
||||||
|
):
|
||||||
|
# paths: check files for existence and delete because of other tests
|
||||||
|
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"
|
||||||
|
if csv_file.exists():
|
||||||
|
csv_file.unlink()
|
||||||
|
if heatmap_file.exists():
|
||||||
|
heatmap_file.unlink()
|
||||||
|
|
||||||
|
img_path = str(path_img_with_failure_TrainedModel)
|
||||||
|
pixels_per_metric_X: float = 0.251
|
||||||
|
pixels_per_metric_Y: float = 0.251
|
||||||
|
|
||||||
|
_csharp_interface.sensor_anomalies_detection(
|
||||||
|
img_path, pixels_per_metric_X, pixels_per_metric_Y
|
||||||
|
)
|
||||||
|
|
||||||
|
assert csv_file.exists()
|
||||||
|
assert heatmap_file.exists()
|
||||||
|
target_folder = results_folder / "csharp_interface"
|
||||||
|
target_folder.mkdir(exist_ok=True)
|
||||||
|
shutil.copy(csv_file, (target_folder / csv_file.name))
|
||||||
|
shutil.copy(heatmap_file, (target_folder / heatmap_file.name))
|
||||||
@ -150,6 +150,16 @@ def test_full_pipeline_wrapped_FailElectrodeCount(path_img_with_failure_Electrod
|
|||||||
|
|
||||||
@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib")
|
@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "lib")
|
||||||
def test_full_pipeline_wrapped_Success(results_folder, path_img_with_failure_TrainedModel):
|
def test_full_pipeline_wrapped_Success(results_folder, path_img_with_failure_TrainedModel):
|
||||||
|
# paths: check files for existence and delete because of other tests
|
||||||
|
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"
|
||||||
|
if csv_file.exists():
|
||||||
|
csv_file.unlink()
|
||||||
|
if heatmap_file.exists():
|
||||||
|
heatmap_file.unlink()
|
||||||
|
|
||||||
img_path = str(path_img_with_failure_TrainedModel)
|
img_path = str(path_img_with_failure_TrainedModel)
|
||||||
pixels_per_metric_X: float = 0.251
|
pixels_per_metric_X: float = 0.251
|
||||||
pixels_per_metric_Y: float = 0.251
|
pixels_per_metric_Y: float = 0.251
|
||||||
@ -159,11 +169,6 @@ def test_full_pipeline_wrapped_Success(results_folder, path_img_with_failure_Tra
|
|||||||
assert ret.status.code == 0
|
assert ret.status.code == 0
|
||||||
assert ret.status.ExceptionType is None
|
assert ret.status.ExceptionType is None
|
||||||
|
|
||||||
# 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 csv_file.exists()
|
||||||
assert heatmap_file.exists()
|
assert heatmap_file.exists()
|
||||||
shutil.copy(csv_file, (results_folder / csv_file.name))
|
shutil.copy(csv_file, (results_folder / csv_file.name))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user