Skip to content

Commit d732e18

Browse files
🐛 🧪 Fix e2e client tests (#73)
* avoid import of private method * fix postprocessing and generation of html table * minor change
1 parent dd58e66 commit d732e18

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

clients/python/test/e2e/ci/check_for_failures.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def main():
2323
raise typer.Exit(code=E2eExitCodes.CI_SCRIPT_FAILURE)
2424
for pth in result_jsons:
2525
df = pd.read_json(pth)
26-
df = df == pytest.ExitCode.TESTS_FAILED
26+
df = (df != pytest.ExitCode.OK) & (
27+
df != E2eExitCodes.INCOMPATIBLE_CLIENT_SERVER
28+
)
2729
if df.to_numpy().flatten().any():
2830
raise typer.Exit(code=pytest.ExitCode.TESTS_FAILED)
2931

clients/python/test/e2e/ci/generate_html_table.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@
44
import pytest
55
import typer
66
from _utils import E2eExitCodes
7+
from postprocess_e2e import exit_code_valid
78

89

910
def exitcode_to_text(exitcode: int) -> str:
1011
"""Turn exitcodes to string"""
11-
if exitcode == E2eExitCodes.INCOMPATIBLE_CLIENT_SERVER:
12-
return "incompatible"
13-
elif exitcode == pytest.ExitCode.OK:
14-
return "pass"
15-
elif exitcode == pytest.ExitCode.TESTS_FAILED:
16-
return "fail"
12+
if exitcode in set(E2eExitCodes):
13+
return E2eExitCodes(exitcode).name
14+
elif exitcode in set(pytest.ExitCode):
15+
return pytest.ExitCode(exitcode).name
1716
else:
1817
raise typer.Exit(code=E2eExitCodes.CI_SCRIPT_FAILURE)
1918

2019

2120
def make_pretty(entry: str):
2221
color: str
23-
if entry == "incompatible":
22+
if entry == E2eExitCodes.INCOMPATIBLE_CLIENT_SERVER.name:
2423
color = "#999999"
25-
elif entry == "pass":
24+
elif entry == pytest.ExitCode.OK.name:
2625
color = "#99FF99"
27-
elif entry == "fail":
26+
elif entry == pytest.ExitCode.TESTS_FAILED.name:
2827
color = "#FF9999"
2928
else:
30-
raise typer.Exit(code=E2eExitCodes.CI_SCRIPT_FAILURE)
29+
color = "#FF00FF"
3130
return "background-color: %s" % color
3231

3332

@@ -40,9 +39,10 @@ def main(e2e_artifacts_dir: str) -> None:
4039
df: pd.DataFrame = pd.DataFrame()
4140
for file in artifacts.glob("*.json"):
4241
df = pd.concat([df, pd.read_json(file)], axis=1)
43-
any_failure: bool = bool(
44-
(df == pytest.ExitCode.TESTS_FAILED).to_numpy().flatten().any()
45-
)
42+
43+
for exit_code in df.to_numpy().flatten():
44+
if not exit_code_valid(exit_code):
45+
raise typer.Exit(code=E2eExitCodes.CI_SCRIPT_FAILURE)
4646

4747
style = [
4848
{
@@ -62,9 +62,6 @@ def main(e2e_artifacts_dir: str) -> None:
6262
s.set_table_styles(style)
6363
s.set_caption("OSPARC e2e python client vs server tests")
6464
s.to_html(artifacts / "test_results.html")
65-
raise typer.Exit(
66-
code=pytest.ExitCode.TESTS_FAILED if any_failure else pytest.ExitCode.OK
67-
)
6865

6966

7067
if __name__ == "__main__":

clients/python/test/e2e/ci/postprocess_e2e.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import warnings
22
from pathlib import Path
3-
from typing import Set
43

54
import pandas as pd
65
import pytest
@@ -23,6 +22,16 @@ def log(exit_code: int):
2322
print_line()
2423

2524

25+
def exit_code_valid(exit_code: int) -> bool:
26+
if exit_code not in set(pytest.ExitCode).union(E2eExitCodes):
27+
warnings.warn(
28+
f"Received unexpected exitcode {exit_code}. See https://docs.pytest.org/en/7.1.x/reference/exit-codes.html",
29+
E2eScriptFailure,
30+
)
31+
return False
32+
return True
33+
34+
2635
def main(exit_code: int) -> None:
2736
"""
2837
Postprocess results from e2e pytests
@@ -41,17 +50,8 @@ def main(exit_code: int) -> None:
4150
None
4251
"""
4352
log(exit_code)
44-
expected_exitcodes: Set = {
45-
E2eExitCodes.INCOMPATIBLE_CLIENT_SERVER,
46-
pytest.ExitCode.OK,
47-
pytest.ExitCode.TESTS_FAILED,
48-
}
49-
if exit_code not in expected_exitcodes:
50-
warnings.warn(
51-
f"Received unexpected exitcode {exit_code}. See https://docs.pytest.org/en/7.1.x/reference/exit-codes.html",
52-
E2eScriptFailure,
53-
)
54-
typer.Exit(code=E2eExitCodes.CI_SCRIPT_FAILURE)
53+
if not exit_code_valid(exit_code):
54+
raise typer.Exit(code=E2eExitCodes.CI_SCRIPT_FAILURE)
5555

5656
# get config
5757
try:

clients/python/test/e2e/test_files_api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import osparc
55
import pytest
66
from conftest import _KB
7-
from osparc._utils import compute_sha256
87
from packaging.version import Version
98

109

@@ -51,8 +50,7 @@ def test_upload_file(tmp_file: Path, cfg: osparc.Configuration) -> None:
5150
def test_search_files(
5251
tmp_file: Path, cfg: osparc.Configuration, use_checksum: bool, use_id: bool
5352
) -> None:
54-
checksum: str = compute_sha256(tmp_file)
55-
assert checksum == _hash_file(tmp_file), "Could not compute correct checksum"
53+
checksum: str = _hash_file(tmp_file)
5654
results: osparc.PaginationGenerator
5755
with osparc.ApiClient(configuration=cfg) as api_client:
5856
files_api: osparc.FilesApi = osparc.FilesApi(api_client=api_client)

0 commit comments

Comments
 (0)