Skip to content

Commit ee10573

Browse files
authored
Move test_telemetry.py to mpa tests in external (#1580)
Signed-off-by: Yunchu Lee <[email protected]>
1 parent cb8cef2 commit ee10573

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default_language_version:
44

55
repos:
66
- repo: https://github.com/PyCQA/isort
7-
rev: "5.10.1"
7+
rev: "5.12.0"
88
hooks:
99
- id: isort
1010
alias: isort_ote_sdk
Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,74 @@
1-
import sys
2-
import subprocess
1+
import os
32
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+
)
611

712
from ote_sdk.test_suite.e2e_test_system import e2e_pytest_component
813

9-
from ote_cli.tools import ote
1014

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]
2019

2120

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)
2326

2427
@e2e_pytest_component
28+
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
2529
@patch("ote_cli.tools.ote.ote_demo", return_value=None)
2630
@patch("ote_cli.utils.telemetry.init_telemetry_session", return_value=None)
2731
@patch("ote_cli.utils.telemetry.close_telemetry_session", return_value=None)
2832
@patch("ote_cli.utils.telemetry.send_version", return_value=None)
2933
@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+
3737
backup_argv = sys.argv
3838
sys.argv = ["ote", "demo"]
3939
ret = ote.main()
4040
sys.argv = backup_argv
4141

42-
self.assertEqual(ret, 0)
42+
assert ret == 0
4343
mock_demo.assert_called_once()
4444
mock_init_tm.assert_called_once()
4545
mock_close_tm.assert_called_once()
4646
mock_send_cmd.assert_called_with(None, "demo", {"retcode": 0})
4747

4848
@e2e_pytest_component
49+
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
4950
@patch("ote_cli.tools.ote.ote_demo", side_effect=Exception())
5051
@patch("ote_cli.utils.telemetry.init_telemetry_session", return_value=None)
5152
@patch("ote_cli.utils.telemetry.close_telemetry_session", return_value=None)
5253
@patch("ote_cli.utils.telemetry.send_version", return_value=None)
5354
@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,
5557
mock_send_cmd,
5658
mock_send_version,
5759
mock_close_tm,
5860
mock_init_tm,
5961
mock_demo,
6062
):
63+
from ote_cli.tools import ote
64+
6165
backup_argv = sys.argv
6266
sys.argv = ["ote", "demo"]
6367
with pytest.raises(Exception) as e:
64-
ret = ote.main()
68+
ote.main()
6569
sys.argv = backup_argv
6670

67-
self.assertEqual(e.type, Exception, f"{e}")
71+
assert e.type == Exception, f"{e}"
6872
mock_init_tm.assert_called_once()
6973
mock_close_tm.assert_called_once()
7074
mock_send_cmd.assert_called_with(None, "demo", {"retcode": -1, "exception": repr(Exception())})

tests/ote_cli/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ def manage_tm_config_for_testing():
3636
isip_exist = os.path.exists(isip_path)
3737
otm_exist = os.path.exists(otm_path)
3838

39+
if not os.path.exists(cfg_dir):
40+
created_cfg_dir = True
41+
os.makedirs(cfg_dir)
42+
3943
isip_backup = None
44+
is_cfg_dir_existed = True
45+
4046
if not isip_exist:
4147
with open(isip_path, "w") as f:
4248
f.write("0")
@@ -68,3 +74,6 @@ def manage_tm_config_for_testing():
6874
if otm_backup is not None:
6975
with open(otm_path, "w") as f:
7076
f.write(otm_backup)
77+
78+
if created_cfg_dir:
79+
os.rmdir(cfg_dir)

0 commit comments

Comments
 (0)