Skip to content

Commit

Permalink
changes imports way
Browse files Browse the repository at this point in the history
  • Loading branch information
rnugmanx committed Oct 13, 2023
1 parent 4a3c131 commit 7f55716
Show file tree
Hide file tree
Showing 94 changed files with 485 additions and 386 deletions.
4 changes: 2 additions & 2 deletions tests/e2e_oss/collect_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import numpy as np
import logging as log
import os
from tests.e2e_oss.common_utils.parsers import pipeline_cfg_to_string
from tests.utils.e2e.common.pipeline import Pipeline
from e2e_oss.common_utils.parsers import pipeline_cfg_to_string
from utils.e2e.common.pipeline import Pipeline

pytest_plugins = ('e2e_oss.plugins.ref_collect.conftest', )

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e_oss/common_utils/e2e_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# pylint: disable=wrong-import-position,wrong-import-order,import-error,unused-import,no-name-in-module

from tests.utils.e2e.env_tools import Environment
from tests.utils.e2e.ir_provider.model_optimizer_runner import MORunner
from tests.utils.e2e.ref_collector.score_pytorch_onnx_runtime import PytorchPretrainedToONNXRunner,\
from utils.e2e.env_tools import Environment
from utils.e2e.ir_provider.model_optimizer_runner import MORunner
from utils.e2e.ref_collector.score_pytorch_onnx_runtime import PytorchPretrainedToONNXRunner,\
PytorchTorchvisionToONNXRunner
3 changes: 1 addition & 2 deletions tests/e2e_oss/common_utils/hook_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from _pytest.python import Function

from . import config
from .config import bug_ids, components_ids, req_ids, test_run_id, test_session_build_number
from .environment_info import EnvironmentInfo
from .config import bug_ids, components_ids, req_ids
from .logger import get_logger
from .marks import MarkGeneral, MarkRunType

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_oss/common_utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from datetime import datetime
from typing import cast, List, Union, Tuple, Generator

from tests.e2e_oss.common_utils import config
from e2e_oss.common_utils import config

SEPARATOR = "=" * 20
FIXTURE_SEPARATOR = "*" * 20
Expand Down
101 changes: 101 additions & 0 deletions tests/e2e_oss/common_utils/multiprocessing_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import logging as log
import os
import platform
import signal
import sys
import traceback
from logging.handlers import QueueHandler
from multiprocessing import Process, Queue, TimeoutError, ProcessError
from queue import Empty as QueueEmpty
from typing import Callable, Union

if platform.system() == "Darwin":
# Fix for MacOS
import multiprocessing
multiprocessing.set_start_method("forkserver", True)


def _mp_wrapped_func(func: Callable, func_args: list, queue: Queue, logger_queue: Queue):
"""
Wraps callable object with exception handling. Current wrapper is a target for
`multiprocessing_run` function
:param func: see `multiprocessing_run`
:param func_args: see `multiprocessing_run`
:param queue: multiprocessing.Queue(). Used for getting callable object return values
:param logger_queue: multiprocessing.Queue(). Used for getting logs from child process in parent process
:return:
"""

# Remove all handlers from root logger in child process in favor of `QueueHandler`
# to prevent double console logs in stdout
log.getLogger().handlers = [QueueHandler(logger_queue)]

error_message = ""
res = None
try:
res = func(*func_args)
except:
ex_type, ex_value, tb = sys.exc_info()
error_message = "{tb}\n{ex_type}: {ex_value}".format(tb=''.join(traceback.format_tb(tb)),
ex_type=ex_type.__name__, ex_value=ex_value)
queue.put((error_message, res))


def multiprocessing_run(func: Callable, func_args: list, func_log_name: str, timeout: Union[int, None] = None):
"""
Wraps callable object to a separate process using multiprocessing module
:param func: callable object
:param func_args: list of arguments for callable
:param func_log_name: name of callable used for logging
:param timeout: positive int to limit execution time
:return: return value (or values) from callable object
"""
queue = Queue()
logger_queue = Queue(-1)
process = Process(target=_mp_wrapped_func, args=(func, func_args, queue, logger_queue))
process.start()
try:
error_message, *ret_args = queue.get(timeout=timeout)
except QueueEmpty:
raise TimeoutError("{func} running timed out!".format(func=func_log_name))
finally:
queue.close()

# Extract logs from Queue and pass to root logger
while not logger_queue.empty():
rec = logger_queue.get()
log.getLogger().handle(rec)
logger_queue.close()

if process.is_alive():
process.terminate()
process.join()
else:
exit_signal = multiprocessing_exitcode_to_signal(process.exitcode)
if exit_signal:
raise ProcessError(
"{func} was killed with a signal {signal}".format(func=func_log_name, signal=exit_signal))

if error_message:
raise ProcessError("\n{func} running failed: \n{msg}".format(func=func_log_name, msg=error_message))

ret_args = ret_args[0] if len(ret_args) == 1 else ret_args # unwrap from list if only 1 item is returned
return ret_args


def multiprocessing_exitcode_to_signal(exitcode):
"""
Map multiprocessing exitcode to signals from "signal" module
:param exitcode: multiprocessing exitcode
:return: signal from "signal" if exitcode mapped on signal or None
"""
# Multiprocessing return negative values of signal of the process, but on Win they are positive.
# Bring the value to the positive format.
exit_code = exitcode if os.name == "nt" else -exitcode
if exit_code > 0:
code_map = {int(getattr(signal, sig)): str(getattr(signal, sig))
for sig in dir(signal) if sig.startswith("SIG")}
exit_signal = code_map[exit_code] if exit_code in code_map else exit_code
else:
exit_signal = None
return exit_signal
4 changes: 2 additions & 2 deletions tests/e2e_oss/common_utils/openvino_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from pathlib import Path
from distutils import spawn

from tests.e2e_oss.common_utils.config import openvino_root_dir
from tests.e2e_oss.common_utils.sys_info_utils import os_type_is_windows
from e2e_oss.common_utils.config import openvino_root_dir
from e2e_oss.common_utils.sys_info_utils import os_type_is_windows


class OpenVINOResourceNotFound(Exception):
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_oss/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from cpuinfo import get_cpu_info

from .common_utils.logger import get_logger
from e2e_oss.common_utils.logger import get_logger
from .common_utils.sys_info_utils import get_sys_info
from .common_utils.tf_helper import TFVersionHelper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import numpy as np
import pytest

from tests.e2e_oss._utils.path_utils import resolve_file_path
from e2e_oss._utils.path_utils import resolve_file_path
# import local modules:
from tests.e2e_oss._utils.test_utils import align_output_name
from tests.e2e_oss.common_utils.parsers import mapping_parser as mapping
from tests.utils.e2e.common.e2e_utils import get_tensor_names_dict
from tests.utils.e2e.env_tools import Environment
from e2e_oss._utils.test_utils import align_output_name
from e2e_oss.common_utils.parsers import mapping_parser as mapping
from utils.e2e.common.e2e_utils import get_tensor_names_dict
from utils.e2e.env_tools import Environment

log = getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from collections import OrderedDict

from tests.e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from tests.e2e_oss.pipelines.pipeline_templates.comparators_template import dummy_comparators
from tests.e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from tests.e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from tests.e2e_oss.pipelines.pipeline_templates.ir_gen_templates import common_ir_generation
from tests.e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc
from tests.e2e_oss._utils.path_utils import prepend_with_env_path, resolve_file_path
from tests.e2e_oss.common_utils.pytest_utils import mark
from e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from e2e_oss.pipelines.pipeline_templates.comparators_template import dummy_comparators
from e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from e2e_oss.pipelines.pipeline_templates.ir_gen_templates import common_ir_generation
from e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc
from e2e_oss._utils.path_utils import prepend_with_env_path, resolve_file_path
from e2e_oss.common_utils.pytest_utils import mark


class IE_Infer_Only_Base(CommonConfig):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
from collections import OrderedDict

from tests.e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from tests.e2e_oss.pipelines.pipeline_templates.comparators_template import eltwise_comparators
from tests.e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from tests.e2e_oss.pipelines.pipeline_templates.input_templates import read_pb_input, read_npy_input
from tests.e2e_oss.pipelines.pipeline_templates.ir_gen_templates import common_ir_generation
from tests.e2e_oss._utils.path_utils import prepend_with_env_path
from tests.e2e_oss.common_utils.pytest_utils import mark
from e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from e2e_oss.pipelines.pipeline_templates.comparators_template import eltwise_comparators
from e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from e2e_oss.pipelines.pipeline_templates.input_templates import read_pb_input, read_npy_input
from e2e_oss.pipelines.pipeline_templates.ir_gen_templates import common_ir_generation
from e2e_oss._utils.path_utils import prepend_with_env_path
from e2e_oss.common_utils.pytest_utils import mark


class ONNXPrecollectedProtobufBaseClass(CommonConfig):
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e_oss/pipelines/pipeline_base_classes/onnx_runtime.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os
from collections import OrderedDict

from tests.e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from tests.e2e_oss.pipelines.pipeline_templates.collect_reference_templates import get_refs_onnx_runtime
from tests.e2e_oss.pipelines.pipeline_templates.comparators_template import classification_comparators, eltwise_comparators, \
from e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from e2e_oss.pipelines.pipeline_templates.collect_reference_templates import get_refs_onnx_runtime
from e2e_oss.pipelines.pipeline_templates.comparators_template import classification_comparators, eltwise_comparators, \
dummy_comparators, object_detection_comparators, ssim_comparators
from tests.e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from tests.e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from tests.e2e_oss.pipelines.pipeline_templates.ir_gen_templates import common_ir_generation
from tests.e2e_oss.pipelines.pipeline_templates.postproc_template import parse_classification, parse_object_detection, \
from e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from e2e_oss.pipelines.pipeline_templates.ir_gen_templates import common_ir_generation
from e2e_oss.pipelines.pipeline_templates.postproc_template import parse_classification, parse_object_detection, \
parse_image_modification
from tests.e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc
from tests.e2e_oss._utils.path_utils import prepend_with_env_path, resolve_file_path
from tests.e2e_oss.common_utils.pytest_utils import mark
from e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc
from e2e_oss._utils.path_utils import prepend_with_env_path, resolve_file_path
from e2e_oss.common_utils.pytest_utils import mark


class ONNXRuntimeEltwiseBaseClass(CommonConfig):
Expand Down
18 changes: 9 additions & 9 deletions tests/e2e_oss/pipelines/pipeline_base_classes/paddlepaddle.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from collections import OrderedDict

from tests.e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from tests.e2e_oss.pipelines.pipeline_templates.collect_reference_templates import read_refs_pipeline, \
from e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from e2e_oss.pipelines.pipeline_templates.collect_reference_templates import read_refs_pipeline, \
collect_paddlepaddle_refs
from tests.e2e_oss.pipelines.pipeline_templates.comparators_template import eltwise_comparators, \
from e2e_oss.pipelines.pipeline_templates.comparators_template import eltwise_comparators, \
object_detection_comparators, segmentation_comparators
from tests.e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from tests.e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from tests.e2e_oss.pipelines.pipeline_templates.ir_gen_templates import common_ir_generation
from tests.e2e_oss.pipelines.pipeline_templates.postproc_template import paddlepaddle_od_postproc
from tests.e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc
from tests.e2e_oss._utils.path_utils import prepend_with_env_path, ref_from_model, resolve_file_path
from e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from e2e_oss.pipelines.pipeline_templates.ir_gen_templates import common_ir_generation
from e2e_oss.pipelines.pipeline_templates.postproc_template import paddlepaddle_od_postproc
from e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc
from e2e_oss._utils.path_utils import prepend_with_env_path, ref_from_model, resolve_file_path


class PaddlePaddleEltwise(CommonConfig):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import os
from collections import OrderedDict

from tests.e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from tests.e2e_oss.pipelines.pipeline_templates.collect_reference_templates import read_refs_pipeline
from tests.e2e_oss.pipelines.pipeline_templates.comparators_template import classification_comparators
from tests.e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from tests.e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from tests.e2e_oss.pipelines.pipeline_templates.ir_gen_templates import ir_pregenerated
from tests.e2e_oss.pipelines.pipeline_templates.postproc_template import parse_classification
from tests.e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc_caffe
from tests.e2e_oss._utils.path_utils import search_model_path_recursively, ref_from_model, resolve_file_path
from tests.e2e_oss.common_utils.pytest_utils import mark
from e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from e2e_oss.pipelines.pipeline_templates.collect_reference_templates import read_refs_pipeline
from e2e_oss.pipelines.pipeline_templates.comparators_template import classification_comparators
from e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from e2e_oss.pipelines.pipeline_templates.ir_gen_templates import ir_pregenerated
from e2e_oss.pipelines.pipeline_templates.postproc_template import parse_classification
from e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc_caffe
from e2e_oss._utils.path_utils import search_model_path_recursively, ref_from_model, resolve_file_path
from e2e_oss.common_utils.pytest_utils import mark


class Pregenerated_classification_base(CommonConfig):
Expand Down
18 changes: 9 additions & 9 deletions tests/e2e_oss/pipelines/pipeline_base_classes/pregen_eltwise.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
from collections import OrderedDict

from tests.e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from tests.e2e_oss.pipelines.pipeline_templates.collect_reference_templates import read_refs_pipeline
from tests.e2e_oss.pipelines.pipeline_templates.comparators_template import eltwise_comparators
from tests.e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from tests.e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from tests.e2e_oss.pipelines.pipeline_templates.ir_gen_templates import ir_pregenerated
from tests.e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc_caffe
from tests.e2e_oss._utils.path_utils import search_model_path_recursively, ref_from_model, resolve_file_path
from tests.e2e_oss.common_utils.pytest_utils import mark
from e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from e2e_oss.pipelines.pipeline_templates.collect_reference_templates import read_refs_pipeline
from e2e_oss.pipelines.pipeline_templates.comparators_template import eltwise_comparators
from e2e_oss.pipelines.pipeline_templates.infer_templates import common_infer_step
from e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from e2e_oss.pipelines.pipeline_templates.ir_gen_templates import ir_pregenerated
from e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc_caffe
from e2e_oss._utils.path_utils import search_model_path_recursively, ref_from_model, resolve_file_path
from e2e_oss.common_utils.pytest_utils import mark

people_input_file = resolve_file_path("test_data/inputs/caffe/object_detection_voc_people.npz")
car_input_file = resolve_file_path("test_data/inputs/caffe/car_1.npz")
Expand Down
16 changes: 8 additions & 8 deletions tests/e2e_oss/pipelines/pipeline_base_classes/pregen_od.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from collections import OrderedDict

from tests.e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from tests.e2e_oss.pipelines.pipeline_templates.comparators_template import object_detection_comparators
from tests.e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from tests.e2e_oss.pipelines.pipeline_templates.ir_gen_templates import ir_pregenerated
from tests.e2e_oss.pipelines.pipeline_templates.postproc_template import parse_object_detection
from tests.e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc_caffe
from tests.e2e_oss._utils.path_utils import search_model_path_recursively, ref_from_model, resolve_file_path
from tests.e2e_oss.common_utils.pytest_utils import mark
from e2e_oss.pipelines.pipeline_base_classes.common_base_class import CommonConfig
from e2e_oss.pipelines.pipeline_templates.comparators_template import object_detection_comparators
from e2e_oss.pipelines.pipeline_templates.input_templates import read_npz_input
from e2e_oss.pipelines.pipeline_templates.ir_gen_templates import ir_pregenerated
from e2e_oss.pipelines.pipeline_templates.postproc_template import parse_object_detection
from e2e_oss.pipelines.pipeline_templates.preproc_templates import assemble_preproc_caffe
from e2e_oss._utils.path_utils import search_model_path_recursively, ref_from_model, resolve_file_path
from e2e_oss.common_utils.pytest_utils import mark

people_input_file = resolve_file_path("test_data/inputs/caffe/object_detection_voc_people.npz")

Expand Down
Loading

0 comments on commit 7f55716

Please sign in to comment.