From ceab44eee61c0e3e04ea4440f1331602730619bf Mon Sep 17 00:00:00 2001 From: Anastasia Kuporosova Date: Thu, 19 Jan 2023 20:40:14 +0100 Subject: [PATCH] [Docs][PyOV] Add information about testing pyapi (#14645) * [Docs][PyOV] Add information about testing pyapi * apply comments and add links * apply comments * empty * apply changes * apply comments * comments --- src/bindings/python/docs/code_examples.md | 9 ++-- src/bindings/python/docs/contributing.md | 15 +++---- src/bindings/python/docs/test_examples.md | 51 +++++++++++++++++++++-- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/bindings/python/docs/code_examples.md b/src/bindings/python/docs/code_examples.md index 387e05d02dc..9194a8c5b38 100644 --- a/src/bindings/python/docs/code_examples.md +++ b/src/bindings/python/docs/code_examples.md @@ -84,7 +84,7 @@ from openvino.helpers.custom_module import top1_index ``` **Do not forget to include a license on the top of each file!** For demonstration purposes, it has been skipped in the snippets above. -To see changes taking effect, rebuild the project (CMake's install step should be good enough ) and run your solution: +To see the changes take effect, [rebuild the project](../../../../docs/dev/build.md) and run your solution: ```python import openvino.helpers as ov_helpers @@ -402,9 +402,8 @@ Great! Now the class has reached its destination, from C++, to Python, to Python This concludes developer work on OpenVINO™ Python API. Don't forget to recompile your builds and have a good time while writing your code!:) -#### Testing out new code -All of the code is now written. Let's move on to testing. +### Testing the new code -Please refer to the Test Guide available here: +Coding is now finished. Let's move on to testing. - openvino/src/bindings/python/docs/test_examples.md +To learn how to test your code, refer to the guide on [how to test OpenVINO™ Python API?](./test_examples.md#Running_OpenVINO™_Python_API_tests) diff --git a/src/bindings/python/docs/contributing.md b/src/bindings/python/docs/contributing.md index bd063865490..8ae057a6719 100644 --- a/src/bindings/python/docs/contributing.md +++ b/src/bindings/python/docs/contributing.md @@ -1,15 +1,14 @@ # Contributing to OpenVINO™ Python API #### Prerequisites -*To be added...* ##### Enviroment In case the Python version you have is not supported by OpenVINO, you can refer to [openvino/src/bindings/python/docs/python_version_upgrade.md](https://github.com/openvinotoolkit/openvino/blob/master/src/bindings/python/docs/python_version_upgrade.md) for instructions on how to download and build a newer, supported Python version. - -*To be added...* + +The environment setup is described as part of the pyenv example in [the build.md page](./build.md#Example:_using_pyenv_with_OpenVINO™_on_Linux_based_system). ##### Building -Building instructions can be found in [BUILDING.md](../BUILDING.md) +Building instructions can be found in [build.md](./build.md#_Building_the_OpenVINO™_Python_API). ## Contribution guidelines and best practices @@ -17,14 +16,12 @@ Building instructions can be found in [BUILDING.md](../BUILDING.md) It is nothing special... :) First, make sure that all prerequisites are met and focus on writing the code itself. A good starting point is to have some knowledge of the Python language. C++ is also a vital language for OpenVINO™, so it is not a surprise that it is used in this part of the project as well. Code snippets and detailed explanations can be found here: - - openvino/src/bindings/python/docs/code_example.md + +[Examples of OpenVINO™ Python API code](./code_example.md) ##### Always test out our code! Don't forget about it before pushing and triggering CIs. -Please refer to Test Guide available here: - - openvino/src/bindings/python/docs/test_examples.md +To learn how to test your code, refer to the guide on [how to test OpenVINO™ Python API?](./test_examples.md#Running_OpenVINO™_Python_API_tests) Moreover, the project utilizes *flake8* and *mypy* packages to run codestyle checks. Additionally OpenVINO™ uses the custom configuration file to exclude some strict rules. To run codestyle checks, navigate to the main Python API folder first and use following commands: ```shell diff --git a/src/bindings/python/docs/test_examples.md b/src/bindings/python/docs/test_examples.md index 10e0f6ae2d3..03aa18b00a0 100644 --- a/src/bindings/python/docs/test_examples.md +++ b/src/bindings/python/docs/test_examples.md @@ -3,18 +3,38 @@ #### Building and environment Instructions can be found in ["Building the OpenVINO™ Python API"](./build.md). -### Running OpenVINO™ Python API tests +Install the specific requirements file for testing: +``` +python -m pip install -r openvino/src/bindings/python/requirements_test.txt +``` + +Make sure that Python libraries are added to the user environment variables: +``` +export PYTHONPATH=PYTHONPATH:/bin/intel64/Release/python_api/python3.7 +``` +### Run OpenVINO™ Python API tests *For simplicity, all of these commands require to navigate to the main Python API folder first:* ```shell cd .../openvino/src/bindings/python/ ``` -To run **all tests**: +To run OpenVINO Python API 2.0 tests: ```shell pytest tests/ ``` -Test framework *pytest* allows to filter tests with `-k` flag. +To run OpenVINO Python API 1.0 tests, use this command: +``` +pytest tests_compatibility/ +``` + +By default, tests are run on the CPU plugin. If you want to run them on a different plugin, +you need to specify this environment variable: +``` +export TEST_DEVICE=GPU +``` + +The *pytest* test framework enables you to filter tests with the `-k` flag. ```shell pytest tests/test_runtime/test_core.py -k "test_available_devices" ``` @@ -35,6 +55,31 @@ To run full test suite one can utilize `tox` command: tox ``` +### Check the codestyle of Python API +There are two packages used in the project to check the codestyle of python code: *mypy* and *flake8*. +Besides, OpenVINO™ uses a custom configuration file to exclude some strict rules. + +To check the codestyle of the Python API 2.0, run the following commands: +``` +python -m flake8 ./src/openvino/ --config=setup.cfg +python -m mypy ./src/openvino --config-file ./setup.cfg +``` +To check the codestyle of the nGraph Python API, run the following commands: +``` +python -m flake8 ./src/compatibility/ngraph/ --config=setup.cfg +python -m mypy ./src/compatibility/ngraph --config-file ./setup.cfg +``` +To check the codestyle of the InferenceEngine Python API, run the following commands: +``` +cd src/compatibility/openvino +python -m flake8 ./ --config=setup.cfg +python -m mypy ./ --config-file ./setup.cfg +``` +It's recommended to run the mentioned codestyle check whenever new tests are added. +This check should be executed from the main Python API folder: +``` +python -m flake8 ./tests/ --config=setup.cfg +``` ### Writing OpenVINO™ Python API tests ###### Before start Follow and complete `openvino/src/bindings/python/docs/code_examples.md`.