|
1 | | -import sys |
2 | | -import subprocess |
| 1 | +import os |
3 | 2 | import pytest |
4 | | -import unittest |
5 | | -from unittest.mock import MagicMock, patch |
| 3 | +import sys |
| 4 | +from unittest.mock import patch |
| 5 | + |
| 6 | +from ote_cli.registry import Registry |
| 7 | +from ote_cli.utils.tests import ( |
| 8 | + create_venv, |
| 9 | + get_some_vars, |
| 10 | +) |
6 | 11 |
|
7 | 12 | from ote_sdk.test_suite.e2e_test_system import e2e_pytest_component |
8 | 13 |
|
9 | | -from ote_cli.tools import ote |
10 | 14 |
|
11 | | -from ote_cli.tools.ote import ( |
12 | | - ote_demo, |
13 | | - ote_deploy, |
14 | | - ote_eval, |
15 | | - ote_export, |
16 | | - ote_find, |
17 | | - ote_optimize, |
18 | | - ote_train |
19 | | -) |
| 15 | +TT_STABILITY_TESTS = os.environ.get("TT_STABILITY_TESTS", False) |
| 16 | +root = "/tmp/ote_cli/" |
| 17 | +templates = Registry("external/model-preparation-algorithm").filter(task_type="CLASSIFICATION").templates |
| 18 | +templates_ids = [template.model_template_id for template in templates] |
20 | 19 |
|
21 | 20 |
|
22 | | -class TestTelemetry(unittest.TestCase): |
| 21 | +class TestToolsMPATelemetry: |
| 22 | + @e2e_pytest_component |
| 23 | + def test_create_venv(self): |
| 24 | + work_dir, _, algo_backend_dir = get_some_vars(templates[0], root) |
| 25 | + create_venv(algo_backend_dir, work_dir) |
23 | 26 |
|
24 | 27 | @e2e_pytest_component |
| 28 | + @pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS") |
25 | 29 | @patch("ote_cli.tools.ote.ote_demo", return_value=None) |
26 | 30 | @patch("ote_cli.utils.telemetry.init_telemetry_session", return_value=None) |
27 | 31 | @patch("ote_cli.utils.telemetry.close_telemetry_session", return_value=None) |
28 | 32 | @patch("ote_cli.utils.telemetry.send_version", return_value=None) |
29 | 33 | @patch("ote_cli.utils.telemetry.send_cmd_results", return_value=None) |
30 | | - def test_tm_integration_exit_0(self, |
31 | | - mock_send_cmd, |
32 | | - mock_send_version, |
33 | | - mock_close_tm, |
34 | | - mock_init_tm, |
35 | | - mock_demo |
36 | | - ): |
| 34 | + def test_tm_integration_exit_0(self, mock_send_cmd, mock_send_version, mock_close_tm, mock_init_tm, mock_demo): |
| 35 | + from ote_cli.tools import ote |
| 36 | + |
37 | 37 | backup_argv = sys.argv |
38 | 38 | sys.argv = ["ote", "demo"] |
39 | 39 | ret = ote.main() |
40 | 40 | sys.argv = backup_argv |
41 | 41 |
|
42 | | - self.assertEqual(ret, 0) |
| 42 | + assert ret == 0 |
43 | 43 | mock_demo.assert_called_once() |
44 | 44 | mock_init_tm.assert_called_once() |
45 | 45 | mock_close_tm.assert_called_once() |
46 | 46 | mock_send_cmd.assert_called_with(None, "demo", {"retcode": 0}) |
47 | 47 |
|
48 | 48 | @e2e_pytest_component |
| 49 | + @pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS") |
49 | 50 | @patch("ote_cli.tools.ote.ote_demo", side_effect=Exception()) |
50 | 51 | @patch("ote_cli.utils.telemetry.init_telemetry_session", return_value=None) |
51 | 52 | @patch("ote_cli.utils.telemetry.close_telemetry_session", return_value=None) |
52 | 53 | @patch("ote_cli.utils.telemetry.send_version", return_value=None) |
53 | 54 | @patch("ote_cli.utils.telemetry.send_cmd_results", return_value=None) |
54 | | - def test_tm_integration_exit_exception(self, |
| 55 | + def test_tm_integration_exit_exception( |
| 56 | + self, |
55 | 57 | mock_send_cmd, |
56 | 58 | mock_send_version, |
57 | 59 | mock_close_tm, |
58 | 60 | mock_init_tm, |
59 | 61 | mock_demo, |
60 | 62 | ): |
| 63 | + from ote_cli.tools import ote |
| 64 | + |
61 | 65 | backup_argv = sys.argv |
62 | 66 | sys.argv = ["ote", "demo"] |
63 | 67 | with pytest.raises(Exception) as e: |
64 | | - ret = ote.main() |
| 68 | + ote.main() |
65 | 69 | sys.argv = backup_argv |
66 | 70 |
|
67 | | - self.assertEqual(e.type, Exception, f"{e}") |
| 71 | + assert e.type == Exception, f"{e}" |
68 | 72 | mock_init_tm.assert_called_once() |
69 | 73 | mock_close_tm.assert_called_once() |
70 | 74 | mock_send_cmd.assert_called_with(None, "demo", {"retcode": -1, "exception": repr(Exception())}) |
0 commit comments