Skip to content

Commit bd0f4a5

Browse files
committed
Merge remote-tracking branch 'vlad/vs/bindings_tests' into rhecker/py-bindings-tests
2 parents a229e7f + 6cbce37 commit bd0f4a5

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

.github/workflows/test_accuracy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ jobs:
4747
- name: Run CPP Test
4848
run: |
4949
build/test_accuracy -d data -p tests/python/accuracy/public_scope.json
50+
- name: Run CPP-PY Bindings Test
51+
run: |
52+
source venv/bin/activate
53+
PYTHONPATH="$PYTHONPATH:build/model_api/cpp/py_bindings/" pytest --data=./data --config=./tests/python/accuracy/public_scope.json tests/cpp/accuracy/test_bindings.py

examples/cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ endmacro()
9292

9393
find_package(OpenCV REQUIRED COMPONENTS imgcodecs)
9494

95-
set (ENABLE_PY_BINDINGS OFF)
95+
set(ENABLE_PY_BINDINGS OFF)
9696
add_subdirectory(../../src/cpp ${Samples_BINARY_DIR}/src/cpp)
9797

9898
add_example(NAME asynchronous_api SOURCES ./asynchronous_api/main.cpp DEPENDENCIES model_api)

tests/cpp/accuracy/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ include(../cmake/common.cmake)
6767

6868
find_package(OpenCV REQUIRED COMPONENTS core highgui videoio imgproc imgcodecs)
6969

70-
set(ENABLE_PY_BINDINGS OFF)
70+
set(ENABLE_PY_BINDINGS ON)
7171
add_subdirectory(../../../src/cpp ${tests_BINARY_DIR}/model_api/cpp)
7272

7373
add_test(NAME test_accuracy SOURCES test_accuracy.cpp DEPENDENCIES model_api)

tests/cpp/accuracy/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Copyright (C) 2025 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
7+
def pytest_addoption(parser):
8+
parser.addoption("--data", action="store", help="data folder with dataset")
9+
parser.addoption("--config", action="store", help="path to models config")
Lines changed: 56 additions & 0 deletions
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)

tests/cpp/cmake/common.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ macro(add_test)
4141
target_link_libraries(${TEST_NAME} PRIVATE pthread)
4242
endif()
4343

44-
target_link_libraries(${TEST_NAME} PRIVATE gtest gtest_main)
45-
target_link_libraries(${TEST_NAME} PRIVATE nlohmann_json::nlohmann_json)
44+
target_link_libraries(${TEST_NAME} PRIVATE gtest_main gmock_main nlohmann_json::nlohmann_json)
4645

4746
endmacro()

0 commit comments

Comments
 (0)