Skip to content

Commit 4d29c87

Browse files
authored
#290: Updated code to read ci.json instead of testconfig (#318)
* Added new function that reads ci.json using Pydantic, removed old testconfig and added unit test case
1 parent 507935c commit 4d29c87

File tree

8 files changed

+122
-29
lines changed

8 files changed

+122
-29
lines changed

doc/changes/changes_3.4.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
- #309: Relaxed exasol-bucketfs from "^2.0.0" to ">=1,<3"
66
- #289: Removed an obsolete param test-language of run-db-test
7+
- #290: Removed usage of testconfig by reading ci.json instead

exasol/slc/internal/tasks/test/test_runner_db_test_base_task.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import pathlib
23
from collections.abc import Generator
34
from typing import Any, Optional
@@ -54,6 +55,11 @@
5455
UploadExportedContainer,
5556
)
5657
from exasol.slc.internal.tasks.upload.language_definition import LanguageDefinition
58+
from exasol.slc.models.flavor_ci_model import (
59+
FlavorCiConfig,
60+
TestConfig,
61+
TestSet,
62+
)
5763
from exasol.slc.models.run_db_test_result import RunDBTestsInTestConfigResult
5864

5965

@@ -196,9 +202,10 @@ def _get_uploaded_container_name(self) -> str:
196202
def run_test(
197203
self, test_environment_info: EnvironmentInfo, uploaded_container_name: str
198204
) -> Generator[RunDBTestsInTestConfig, Any, RunDBTestsInTestConfigResult]:
199-
test_config = self.read_test_config()
200-
generic_language_tests = self.get_generic_language_tests(test_config)
201-
test_folders = self.get_test_folders(test_config)
205+
ci_json_file = pathlib.Path(self.flavor_path).joinpath("ci.json")
206+
ci_test_cfg = read_ci_json(ci_json_file)
207+
generic_language_tests = self.get_generic_language_tests(ci_test_cfg)
208+
test_folders = self.get_test_folders(ci_test_cfg)
202209
database_credentials = self.get_database_credentials()
203210
# "myudfs/containers/" + self.export_info.name + ".tar.gz"
204211
language_definition = LanguageDefinition(
@@ -238,8 +245,12 @@ def get_result_status(status):
238245

239246
def get_test_folders(self, test_config):
240247
test_folders = []
241-
if test_config["test_folders"] != "":
242-
test_folders = test_config["test_folders"].split(" ")
248+
for test_set in test_config.test_sets:
249+
test_set_goal = str(test_set.goal)
250+
luigi_param = str(TestRunnerDBTestBaseTask.release_goal)
251+
if test_set_goal.lower() == luigi_param.lower():
252+
for test_folder in test_set.folders:
253+
test_folders.append(test_folder)
243254
if self.tests_specified_in_parameters():
244255
test_folders = self.test_folders
245256
return test_folders
@@ -253,25 +264,20 @@ def tests_specified_in_parameters(self):
253264

254265
def get_generic_language_tests(self, test_config):
255266
generic_language_tests = []
256-
if test_config["generic_language_tests"] != "":
257-
generic_language_tests = test_config["generic_language_tests"].split(" ")
267+
for test_set in test_config.test_sets:
268+
test_set_goal = str(test_set.goal)
269+
luigi_param = str(TestRunnerDBTestBaseTask.release_goal)
270+
if test_set_goal.lower() == luigi_param.lower():
271+
for gen_lang_test in test_set.generic_language_tests:
272+
generic_language_tests.append(gen_lang_test)
258273
if self.tests_specified_in_parameters():
259274
generic_language_tests = self.generic_language_tests
260275
return generic_language_tests
261276

262-
def read_test_config(self):
263-
with (
264-
pathlib.Path(self.flavor_path)
265-
.joinpath("flavor_base")
266-
.joinpath("testconfig")
267-
.open("r") as file
268-
):
269-
test_config_str = file.read()
270-
test_config = {}
271-
for line in test_config_str.splitlines():
272-
if not line.startswith("#") and not line == "":
273-
split = line.split("=")
274-
key = split[0]
275-
value = "=".join(split[1:])
276-
test_config[key] = value
277-
return test_config
277+
278+
def read_ci_json(ci_json_file: pathlib.Path):
279+
if ci_json_file.exists() and ci_json_file.is_file():
280+
with ci_json_file.open("r") as json_file:
281+
ci_json_str = json_file.read()
282+
flavor_ci_cfg = FlavorCiConfig.model_validate_json(ci_json_str)
283+
return flavor_ci_cfg.test_config
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import List, Optional
2+
3+
from pydantic import BaseModel
4+
5+
from exasol.slc.models.accelerator import Accelerator
6+
7+
8+
class TestSet(BaseModel):
9+
name: str
10+
files: list[str]
11+
folders: list[str]
12+
goal: str
13+
generic_language_tests: list[str]
14+
test_runner: Optional[str] = None
15+
accelerator: Accelerator = Accelerator.NONE
16+
17+
18+
class TestConfig(BaseModel):
19+
default_test_runner: str
20+
test_sets: list[TestSet]
21+
22+
23+
class FlavorCiConfig(BaseModel):
24+
build_runner: str
25+
test_config: TestConfig
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"build_runner": "24.04",
3+
"test_config": {
4+
"default_test_runner": "24.04",
5+
"test_sets": [
6+
{
7+
"name": "python",
8+
"goal": "rel",
9+
"files": [],
10+
"folders": ["selftest"],
11+
"generic_language_tests": []
12+
}
13+
]
14+
}
15+
}

test/resources/flavors/real-test-flavor/real_flavor_base/testconfig

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"build_runner": "24.04",
3+
"test_config": {
4+
"default_test_runner": "24.04",
5+
"test_sets": [
6+
{
7+
"name": "python",
8+
"goal": "rel",
9+
"files": [],
10+
"folders": ["selftest"],
11+
"generic_language_tests": []
12+
}
13+
]
14+
}
15+
}

test/resources/flavors/test-flavor spaces/real-test-flavor/real_flavor_base/testconfig

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/unit/test_click_api_consistency.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import inspect
2+
import json
3+
from pathlib import Path
24

35
import pytest
46
from exasol_integration_test_docker_environment.testing.api_consistency_utils import ( # type: ignore
@@ -9,6 +11,10 @@
911
)
1012

1113
from exasol.slc import api
14+
from exasol.slc.internal.tasks.test.test_runner_db_test_base_task import (
15+
read_ci_json,
16+
)
17+
from exasol.slc.models.flavor_ci_model import FlavorCiConfig, TestConfig, TestSet
1218
from exasol.slc.tool import commands
1319

1420
IGNORE_LIST = ["compression_strategy", "accelerator"]
@@ -83,3 +89,34 @@ def test_same_functions():
8389
)
8490

8591
assert click_command_names == api_function_names
92+
93+
94+
def test_parse_ci_json(tmp_path: Path):
95+
ci_json_data = {
96+
"build_runner": "24.04",
97+
"test_config": {
98+
"default_test_runner": "24.04",
99+
"test_sets": [
100+
{
101+
"name": "python",
102+
"files": [],
103+
"folders": ["fld00", "fld01"],
104+
"goal": "rel",
105+
"generic_language_tests": ["py3.11", "py3.12"],
106+
},
107+
{
108+
"name": "python",
109+
"files": [],
110+
"folders": ["fld10", "fld11"],
111+
"goal": "rel",
112+
"generic_language_tests": ["py3.13", "py3.14"],
113+
},
114+
],
115+
},
116+
}
117+
json_file_path = tmp_path / "temp_data.json"
118+
with open(json_file_path, "w") as json_file:
119+
json.dump(ci_json_data, json_file)
120+
actual_res = read_ci_json(json_file_path)
121+
expected_res = FlavorCiConfig.model_validate(ci_json_data)
122+
assert actual_res == expected_res.test_config

0 commit comments

Comments
 (0)