Skip to content

Commit 6322b53

Browse files
committed
Updated tester schema generation to use msgspec data types
1 parent 37c410f commit 6322b53

38 files changed

+573
-644
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ __pycache__
88
.eggs
99
venv
1010
venv2
11+
.venv
1112
build
1213
docker-compose.override.yml
1314
/workspace
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from setuptools import setup
2+
3+
4+
setup(name='pre-commit-placeholder-package', version='0.0.0', py_modules=[])

Changelog.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented here.
66
- Improved robustness of tester installation scripts and Docker configuration (#688)
77
- Moved tidyverse installation steps from server Dockerfile into R tester requirements.system (#688)
88
- Fixed Haskell tester installation using ghcup to install stack system-wide (#688)
9+
- Updated tester schema generation to use msgspec datatypes (#689)
910

1011
## [v2.9.0]
1112
- Install stack with GHCup (#626)
@@ -45,13 +46,13 @@ All notable changes to this project will be documented here.
4546
- Update R tester to allow a renv.lock file (#581)
4647
- Improve display of Python package installation errors when creating environment (#585)
4748
- Update "setting up test environment" message with http response of status code 503 (#589)
48-
- Change rlimit resource settings to apply each worker individually (#587)
49+
- Change rlimit resource settings to apply each worker individually (#587)
4950
- Drop support for Python 3.8 (#590)
5051
- Use Python 3.13 in development (#590)
5152
- Update Docker configuration to install dependencies in a separate service (#590)
5253
- Improve error reporting with handled assertion errors (#591)
5354
- Add custom pytest markers to Python tester to record MarkUs metadata (#592)
54-
- Stop the autotester from running tests if there are errors in test settings (#593)
55+
- Stop the autotester from running tests if there are errors in test settings (#593)
5556
- Implement Redis backoff strategy (#594)
5657

5758
## [v2.6.0]
@@ -125,7 +126,7 @@ All notable changes to this project will be documented here.
125126
- Add ability to clean up test scripts that haven't been used for X days (#379)
126127

127128
## [v2.1.2]
128-
- Support dependencies on specific package versions and non-CRAN sources for R tester (#323)
129+
- Support dependencies on specific package versions and non-CRAN sources for R tester (#323)
129130

130131
## [v2.1.1]
131132
- Remove the requirement for clients to send unique user name (#318)
@@ -146,7 +147,7 @@ All notable changes to this project will be documented here.
146147
- Add Jupyter tester (#284)
147148

148149
## [v1.10.3]
149-
- Fix bug where zip archive was unpacked two levels deep instead of just one (#271)
150+
- Fix bug where zip archive was unpacked two levels deep instead of just one (#271)
150151
- Pass PGHOST and PGINFO environment variables to tests (#272)
151152
- Update to new version of markus-api that supports uploading binary files (#273)
152153
- Fix bug where environment variables were not string types (#274)
Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
from __future__ import annotations
2+
3+
import importlib
14
import os
25

36
_TESTERS = ("ai", "custom", "haskell", "java", "jupyter", "py", "pyta", "r", "racket")
47

58

6-
def install(testers=_TESTERS):
7-
import importlib
8-
9-
settings = {}
9+
def install(testers: list[str] = _TESTERS) -> tuple[dict, dict]:
10+
installed_testers = []
1011
for tester in testers:
1112
mod = importlib.import_module(f".{tester}.setup", package="autotest_server.testers")
1213
try:
@@ -20,5 +21,25 @@ def install(testers=_TESTERS):
2021
" and then rerunning this function."
2122
)
2223
raise Exception(msg) from e
23-
settings[tester] = mod.settings()
24-
return settings
24+
installed_testers.append(tester)
25+
return get_settings(installed_testers)
26+
27+
28+
def get_settings(testers: list[str] = _TESTERS) -> tuple[dict, dict]:
29+
"""Return JSON schemas for the settings for the given testers.
30+
31+
The return values are:
32+
1. A dictionary mapping tester name to JSON schema
33+
2. A dictionary of JSON schema definitions used by the tester schemas
34+
"""
35+
schemas = {}
36+
definitions = {}
37+
for tester in testers:
38+
mod = importlib.import_module(f".{tester}.setup", package="autotest_server.testers")
39+
tester_schema, tester_definitions = mod.settings()
40+
if "title" in tester_schema and f"{tester_schema["title"]}TesterSettings" in tester_definitions:
41+
tester_definitions.pop(f"{tester_schema["title"]}TesterSettings")
42+
schemas[tester] = tester_schema
43+
definitions.update(tester_definitions)
44+
45+
return schemas, definitions

server/autotest_server/testers/ai/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def create_environment(settings_, env_dir, _default_env_dir):
4848
def settings():
4949
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "settings_schema.json")) as f:
5050
settings_ = json.load(f)
51-
return settings_
51+
return settings_, {}
5252

5353

5454
def install():
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
from typing import Annotated
3+
4+
from msgspec import Meta
5+
from markus_autotesting_core.types import AutotestFile, BaseTestData, BaseTesterSettings
6+
7+
8+
class CustomTesterSettings(BaseTesterSettings, tag="custom"):
9+
"""The settings for the custom tester."""
10+
11+
test_data: Annotated[list[CustomTestData], Meta(title="Test Groups", min_length=1)]
12+
13+
14+
class CustomTestData(BaseTestData, kw_only=True):
15+
"""The `test_data` specification for the custom tester."""
16+
17+
script_files: Annotated[
18+
list[AutotestFile],
19+
Meta(title="Test files", min_length=1, extra_json_schema={"uniqueItems": True}),
20+
]
21+
"""The file(s) that contain the tests to execute."""

server/autotest_server/testers/custom/settings_schema.json

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

server/autotest_server/testers/custom/setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
2-
import json
2+
3+
from ..schema import generate_schema
4+
from .schema import CustomTesterSettings
35

46

57
def create_environment(_settings, _env_dir, default_env_dir):
@@ -11,5 +13,4 @@ def install():
1113

1214

1315
def settings():
14-
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "settings_schema.json")) as f:
15-
return json.load(f)
16+
return generate_schema(CustomTesterSettings)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import annotations
2+
from typing import Annotated
3+
4+
from msgspec import Meta, Struct
5+
from markus_autotesting_core.types import BaseTestData, BaseTesterSettings
6+
7+
8+
class HaskellTesterSettings(BaseTesterSettings):
9+
"""The settings for the Haskell tester."""
10+
11+
env_data: Annotated[HaskellEnvData, Meta(title="Haskell environment")]
12+
test_data: Annotated[list[HaskellTestData], Meta(title="Test Groups", min_length=1)]
13+
14+
15+
class HaskellTestData(BaseTestData, kw_only=True):
16+
"""The `test_data` specification for the Haskell tester."""
17+
18+
test_timeout: Annotated[int, Meta(title="Per-test timeout")] = 10
19+
test_cases: Annotated[int, Meta(title="Number of test cases (QuickCheck)")] = 100
20+
21+
22+
class HaskellEnvData(Struct, kw_only=True):
23+
"""Settings for the Haskell environment"""
24+
25+
resolver_version: Annotated[str, Meta(title="Stackage LTS resolver version")] = "lts-21.21"

server/autotest_server/testers/haskell/settings_schema.json

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

0 commit comments

Comments
 (0)