Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.

Commit c78930c

Browse files
committed
Add tests for EyesBase.close()
1 parent d584182 commit c78930c

File tree

4 files changed

+149
-7
lines changed

4 files changed

+149
-7
lines changed

eyes_core/applitools/core/eyes_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def close(self, raise_ex=True):
307307
try:
308308
logger.debug("close({})".format(raise_ex))
309309
if not self._is_opened:
310-
raise ValueError("Eyes not open")
310+
raise EyesError("Eyes not open")
311311

312312
self._is_opened = False
313313

tests/unit/conftest.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
Configuration,
1212
ImageMatchSettings,
1313
RunningSession,
14+
SessionStartInfo,
15+
SessionType,
16+
BatchInfo,
17+
AppEnvironment,
18+
MatchLevel,
1419
)
1520
from applitools.common.utils.json_utils import attr_from_json
1621
from applitools.core import EyesBase, ServerConnector
@@ -73,6 +78,7 @@ def started_connector(configured_connector):
7378
timeout_sec=configured_connector.timeout_sec,
7479
)
7580
configured_connector._is_session_started = True
81+
7682
return configured_connector
7783

7884

@@ -93,7 +99,7 @@ def app_output_with_screenshot(app_output, screenshot):
9399
return AppOutputWithScreenshot(app_output, screenshot)
94100

95101

96-
@pytest.fixture
102+
@pytest.fixture(scope="function")
97103
def image_match_settings():
98104
return ImageMatchSettings()
99105

@@ -106,7 +112,7 @@ def app_output_provider(image, app_output_with_screenshot):
106112
return apo
107113

108114

109-
@pytest.fixture
115+
@pytest.fixture(scope="function")
110116
def running_session():
111117
RUNNING_SESSION_DATA = """{
112118
"id": "some id",
@@ -117,3 +123,27 @@ def running_session():
117123
}"""
118124
RUNNING_SESSION_OBJ = attr_from_json(RUNNING_SESSION_DATA, RunningSession)
119125
return RUNNING_SESSION_OBJ
126+
127+
128+
@pytest.fixture(scope="function")
129+
def session_start_info():
130+
return SessionStartInfo(
131+
agent_id="eyes.core.python/3.15.4",
132+
session_type=SessionType.SEQUENTIAL,
133+
app_id_or_name="TestApp",
134+
ver_id=None,
135+
scenario_id_or_name="TestName",
136+
batch_info=BatchInfo(),
137+
baseline_env_name="Baseline env name",
138+
environment_name="Env name",
139+
environment=AppEnvironment(),
140+
default_match_settings=ImageMatchSettings(match_level=MatchLevel.STRICT),
141+
branch_name="branch Name",
142+
parent_branch_name="parentBranchName",
143+
baseline_branch_name="baselineBranchName",
144+
compare_with_parent_branch=False,
145+
ignore_baseline=False,
146+
save_diffs=True,
147+
render=False,
148+
properties=[],
149+
)

tests/unit/eyes_selenium/test_eyes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ def test_get_set_cut_provider(eyes):
141141
assert isinstance(eyes.cut_provider, UnscaledFixedCutProvider)
142142

143143

144-
def test_eyes_abort(eyes):
145-
eyes.abort()
146-
147-
148144
def test_check_without_open_call(eyes):
149145
with pytest.raises(EyesError):
150146
eyes.check("Test", Target.window())
147+
148+
149+
def test_eyes_base_abort(eyes):
150+
eyes.abort()
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import os
2+
3+
import pytest
4+
from mock import MagicMock
5+
6+
from applitools.common import (
7+
EyesError,
8+
TestResults,
9+
DiffsFoundError,
10+
NewTestError,
11+
TestFailedError,
12+
)
13+
from applitools.selenium import Eyes
14+
15+
16+
@pytest.fixture(scope="function")
17+
def eyes():
18+
return Eyes()
19+
20+
21+
@pytest.fixture(scope="function")
22+
def eyes_opened(eyes, running_session, session_start_info):
23+
os.environ["APPLITOOLS_API_KEY"] = "SOME KEY"
24+
eyes._current_eyes._is_opened = True
25+
eyes._current_eyes._running_session = running_session
26+
eyes._current_eyes._session_start_info = session_start_info
27+
eyes._current_eyes._server_connector.stop_session = MagicMock(
28+
side_effect=lambda *args, **kwargs: TestResults(
29+
1, 2, 3, 4, 3, 4, 5, 6, 2, status="unresolved"
30+
)
31+
)
32+
return eyes
33+
34+
35+
@pytest.fixture(scope="function")
36+
def eyes_opened_unresolved_new(eyes_opened, started_connector, running_session):
37+
started_connector.stop_session = MagicMock(
38+
side_effect=lambda *args, **kwargs: TestResults(
39+
1, 2, 3, 4, 3, 4, 5, 6, 2, status="unresolved"
40+
)
41+
)
42+
eyes_opened._current_eyes._server_connector = started_connector
43+
running_session.is_new_session = True
44+
eyes_opened._current_eyes._running_session = running_session
45+
return eyes_opened
46+
47+
48+
@pytest.fixture(scope="function")
49+
def eyes_opened_unresolved_old(eyes_opened, started_connector):
50+
started_connector.stop_session = MagicMock(
51+
side_effect=lambda *args, **kwargs: TestResults(
52+
1, 2, 3, 4, 3, 4, 5, 6, 2, status="unresolved"
53+
)
54+
)
55+
eyes_opened._current_eyes._server_connector = started_connector
56+
return eyes_opened
57+
58+
59+
@pytest.fixture(scope="function")
60+
def eyes_opened_failed(eyes_opened, started_connector):
61+
started_connector.stop_session = MagicMock(
62+
side_effect=lambda *args, **kwargs: TestResults(
63+
1, 2, 3, 4, 3, 4, 5, 6, 2, status="failed"
64+
)
65+
)
66+
eyes_opened._current_eyes._server_connector = started_connector
67+
return eyes_opened
68+
69+
70+
def test_eyes_close_not_opened(eyes):
71+
with pytest.raises(EyesError):
72+
eyes.close()
73+
74+
75+
def test_eyes_close_opened_but_not_session_running(eyes_opened):
76+
eyes_opened._current_eyes._running_session = None
77+
test_results = eyes_opened.close()
78+
assert test_results == TestResults()
79+
80+
81+
def test_eyes_close_old_test_unresolved(eyes_opened_unresolved_old):
82+
with pytest.raises(DiffsFoundError):
83+
eyes_opened_unresolved_old.close()
84+
85+
86+
def test_eyes_close_old_test_unresolved_silent(eyes_opened_unresolved_old):
87+
eyes_opened_unresolved_old.close(False)
88+
89+
90+
def test_eyes_close_new_test_unresolved_should_fail(eyes_opened_unresolved_new):
91+
eyes_opened_unresolved_new.fail_on_new_test = True
92+
93+
with pytest.raises(NewTestError):
94+
eyes_opened_unresolved_new.close(False)
95+
96+
97+
def test_eyes_close_new_test_unresolved(eyes_opened_unresolved_new):
98+
with pytest.raises(NewTestError):
99+
eyes_opened_unresolved_new.close()
100+
101+
102+
def test_eyes_close_new_test_unresolved_silent(eyes_opened_unresolved_new):
103+
eyes_opened_unresolved_new.close(False)
104+
105+
106+
def test_eyes_close_old_test_failed(eyes_opened_failed):
107+
with pytest.raises(TestFailedError):
108+
eyes_opened_failed.close()
109+
110+
111+
def test_eyes_close_old_test_failed_silent(eyes_opened_failed):
112+
eyes_opened_failed.close(False)

0 commit comments

Comments
 (0)