Skip to content

Commit 4e8394a

Browse files
authored
Populate with initial project structure (#1)
- Set up Python project structure - Add basic data types - Use ruff for linting and formatting, including pre-commit and CI integration
1 parent c00d7c2 commit 4e8394a

File tree

11 files changed

+516
-1
lines changed

11 files changed

+516
-1
lines changed

.github/workflows/ruff.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Ruff
2+
on: [ push, pull_request ]
3+
jobs:
4+
ruff:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: astral-sh/ruff-action@v3

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.14.3
5+
hooks:
6+
# Run the linter.
7+
- id: ruff-check
8+
args: [ --fix ]
9+
# Run the formatter.
10+
- id: ruff-format
11+
12+
ci:
13+
autoupdate_schedule: quarterly

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2023 [Your Name]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
2. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
11
# markus-autotesting-core
2-
Core utilities for the MarkUs autotester.
2+
3+
`markus-autotesting-core` is a Python package containing core utilities for the MarkUs autotester. In particular, it defines common data types used by different components of the autotester.
4+
5+
## Installation
6+
To install the package, you can use pip:
7+
8+
```
9+
pip install markus-autotesting-core
10+
```
11+
12+
## Usage
13+
After installation, you can use the package in your Python scripts. Here is a simple example:
14+
15+
```python
16+
from markus_autotesting_core import core
17+
18+
# Example usage of core functionality
19+
result = core.some_function()
20+
print(result)
21+
```
22+
23+
## Running the Package
24+
You can run the package as a script using the following command:
25+
26+
```
27+
python -m markus_autotesting_core
28+
```
29+
30+
## Testing
31+
To run the tests, navigate to the project directory and use:
32+
33+
```
34+
pytest tests/test_core.py
35+
```
36+
37+
## Contributing
38+
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
39+
40+
## License
41+
This project is licensed under the MIT License. See the LICENSE file for more details.

markus_autotesting_core/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .types import (
2+
_AutotestSettings,
3+
AutotestFile,
4+
BaseTesterSettings,
5+
BaseTestData,
6+
create_autotest_settings_class,
7+
)
8+
9+
__all__ = [
10+
"_AutotestSettings",
11+
"AutotestFile",
12+
"BaseTesterSettings",
13+
"BaseTestData",
14+
"create_autotest_settings_class",
15+
]
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"""This file defines the core types used in the Markus Autotesting system."""
2+
3+
from __future__ import annotations
4+
from functools import reduce
5+
from typing import Annotated, Any, Optional, Union
6+
7+
from msgspec import Meta, Struct
8+
9+
10+
class _AutotestSettings(Struct, kw_only=True):
11+
"""The main test settings data type."""
12+
13+
testers: Annotated[list, Meta(title="Testers", min_length=1)]
14+
"""The list of testers configured for these settings."""
15+
16+
_user: Optional[str] = None
17+
"""The user who last updated the test settings."""
18+
19+
_last_access: Optional[int] = None
20+
"""The last time the test settings were updated."""
21+
22+
_files: Optional[str] = None
23+
"""A list of test files associated with these settings."""
24+
25+
_env_status: Optional[str] = None
26+
"""The status of the test environment creation for these settings."""
27+
28+
_error: Optional[str] = None
29+
"""An error message, populated when creating a test environment fails."""
30+
31+
32+
def create_autotest_settings_class(tester_classes: list[type]) -> type[Struct]:
33+
"""Dynamically create an AutotestSettings data type.
34+
35+
This uses _AutotestSettings as the base class, replacing the `testers` annotation
36+
with a union of the provided tester_classes.
37+
"""
38+
return type(
39+
"AutotestSettings",
40+
(_AutotestSettings,),
41+
{
42+
"__annotations__": {
43+
"testers": Annotated[
44+
list[reduce(lambda a, b: Union[a, b], tester_classes)],
45+
Meta(title="Testers", min_length=1),
46+
]
47+
}
48+
},
49+
)
50+
51+
52+
class BaseTesterSettings(
53+
Struct,
54+
kw_only=True,
55+
tag_field="tester_type",
56+
tag=lambda x: x.removesuffix("TesterSettings").lower(),
57+
):
58+
"""The settings for an individual tester.
59+
60+
This is a tagged union of various testers, using `tester_type` as the discriminator field.
61+
"""
62+
63+
test_data: Optional[Any] = None
64+
"""The settings for the tester."""
65+
66+
@property
67+
def tester_type(self) -> str:
68+
return self.__class__.__name__.removesuffix("TesterSettings").lower()
69+
70+
_env: Optional[dict[str, Any]] = None
71+
"""Environment variables to pass to the tester."""
72+
73+
74+
class BaseTestData(
75+
Struct,
76+
kw_only=True,
77+
):
78+
"""Base class for all `test_data` fields.
79+
80+
This is subclassed to specify tester-specific `test_data` settings.
81+
"""
82+
83+
category: Annotated[
84+
list[Annotated[str, Meta(extra_json_schema={"enum": [], "enumNames": []})]],
85+
Meta(title="Category", extra_json_schema={"uniqueItems": True}),
86+
]
87+
88+
script_files: Annotated[
89+
list[AutotestFile],
90+
Meta(title="Test files", min_length=1, extra_json_schema={"uniqueItems": True}),
91+
]
92+
"""The file(s) that contain the tests to execute."""
93+
94+
timeout: Annotated[int, Meta(title="Timeout")] = 30
95+
"""The timeout in seconds for this test group."""
96+
97+
feedback_file_names: Annotated[list[str], Meta(title="Feedback files")]
98+
"""A list of file paths generated by executing this test group."""
99+
100+
extra_info: dict = {}
101+
"""TODO"""
102+
103+
104+
AutotestFile = Annotated[str, Meta(extra_json_schema={"enum": []})]
105+
"""A placeholder in the JSON schema representing one of the files provided to the autotesting environment."""

pyproject.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[project]
2+
name = "markus-autotesting-core"
3+
version = "0.1.0"
4+
description = "Core functionality for Markus Autotesting"
5+
authors = [
6+
{name = "David Liu", email = "[email protected]"}
7+
]
8+
license = "MIT"
9+
readme = "README.md"
10+
keywords = ["autotesting", "markus"]
11+
dependencies = [
12+
"msgspec"
13+
]
14+
requires-python = ">=3.9"
15+
16+
[project.urls]
17+
Homepage = "https://github.com/MarkUsProject/markus-autotesting-core"
18+
Repository = "https://github.com/MarkUsProject/markus-autotesting-core.git"
19+
20+
[build-system]
21+
requires = ["setuptools", "wheel"]
22+
build-backend = "setuptools.build_meta"
23+
24+
[tool.setuptools]
25+
include-package-data = true
26+
zip-safe = false
27+
28+
[tool.setuptools.dynamic]
29+
version = {attr = "python_ta.__version__"}
30+
#readme = {file = "README.md", content-type = "text/markdown"}
31+
32+
[tool.setuptools.packages.find]
33+
include = ["markus_autotesting_core*"]
34+
35+
[dependency-groups]
36+
dev = [
37+
"pytest>=8.4.2",
38+
"ruff>=0.14.3",
39+
]

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from setuptools import setup
2+
3+
setup()

tests/test_types/test_core.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from markus_autotesting_core.types import BaseTestData
2+
3+
4+
def test_base_test_data_fields():
5+
"""Test that the BaseTestData class has the expected fields."""
6+
annotations = BaseTestData.__annotations__
7+
8+
assert "category" in annotations
9+
assert "script_files" in annotations
10+
assert "timeout" in annotations
11+
assert "feedback_file_names" in annotations
12+
assert "extra_info" in annotations
13+
14+
15+
def test_base_test_data_decoding():
16+
"""Test that an instance of BaseTestData can be dencoded from JSON."""
17+
import msgspec
18+
import json
19+
20+
json_data = json.dumps(
21+
{
22+
"category": ["unit", "integration"],
23+
"script_files": ["test1.py", "test2.py"],
24+
"timeout": 60,
25+
"feedback_file_names": ["feedback.txt"],
26+
"extra_info": {"note": "This is a test."},
27+
}
28+
)
29+
30+
decoded = msgspec.json.decode(json_data, type=BaseTestData)
31+
32+
assert decoded.category == ["unit", "integration"]
33+
assert decoded.script_files == ["test1.py", "test2.py"]
34+
assert decoded.timeout == 60
35+
assert decoded.feedback_file_names == ["feedback.txt"]
36+
assert decoded.extra_info == {"note": "This is a test."}

0 commit comments

Comments
 (0)