Skip to content

Commit db91495

Browse files
committed
Add tests for py bindings
1 parent f6126ba commit db91495

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

.github/workflows/test_accuracy.yml

+4
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ jobs:
4949
run: |
5050
build/test_accuracy -d data -p tests/python/accuracy/public_scope.json
5151
DATA=data build/test_YOLOv8
52+
- name: Run CPP-PY Bindings Test
53+
run: |
54+
source venv/bin/activate
55+
PYTHONPATH="$PYTHONPATH:build/py_bindings" pytest --data=./data --config=./tests/python/accuracy/public_scope.json tests/cpp/accuracy/test_bindings.py

tests/cpp/accuracy/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (C) 2020-2024 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
def pytest_addoption(parser):
7+
parser.addoption("--data", action="store", help="data folder with dataset")
8+
parser.addoption("--config", action="store", help="path to models config")

tests/cpp/accuracy/test_bindings.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
# Copyright (C) 2025 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
import pytest
7+
import json
8+
from pathlib import Path
9+
10+
import cv2
11+
12+
from model_api.models import Model
13+
from py_model_api import ClassificationModel
14+
15+
16+
def read_config(models_config: str, model_type: str):
17+
with open(models_config, "r") as f:
18+
data = json.load(f)
19+
for item in data:
20+
if item["type"] == model_type:
21+
yield item
22+
23+
24+
@pytest.fixture(scope="session")
25+
def data(pytestconfig) -> str:
26+
return pytestconfig.getoption("data")
27+
28+
29+
@pytest.fixture(scope="session")
30+
def models_config(pytestconfig) -> str:
31+
return pytestconfig.getoption("config")
32+
33+
34+
@pytest.fixture()
35+
def classification_configs(models_config: str):
36+
return read_config(models_config, "ClassificationModel")
37+
38+
39+
def test_classification_models(data: str, classification_configs):
40+
for model_data in classification_configs:
41+
name = model_data["name"]
42+
if ".xml" not in name:
43+
continue
44+
if name.endswith(".xml") or name.endswith(".onnx"):
45+
name = f"{data}/{name}"
46+
47+
model = Model.create_model(name, preload=True)
48+
cpp_model = ClassificationModel.create_model(name, preload=True)
49+
50+
image_path = Path(data) / next(iter(model_data["test_data"]))["image"]
51+
image = cv2.imread(str(image_path))
52+
53+
py_result = model(image)
54+
cpp_result = cpp_model(image)
55+
56+
assert str(py_result) == str(cpp_result)

0 commit comments

Comments
 (0)