Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.3
hooks:
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format

ci:
autoupdate_schedule: quarterly
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2023 [Your Name]

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:

1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# markus-autotesting-core
Core utilities for the MarkUs autotester.

`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.

## Installation
To install the package, you can use pip:

```
pip install markus-autotesting-core
```

## Usage
After installation, you can use the package in your Python scripts. Here is a simple example:

```python
from markus_autotesting_core import core

# Example usage of core functionality
result = core.some_function()
print(result)
```

## Running the Package
You can run the package as a script using the following command:

```
python -m markus_autotesting_core
```

## Testing
To run the tests, navigate to the project directory and use:

```
pytest tests/test_core.py
```

## Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

## License
This project is licensed under the MIT License. See the LICENSE file for more details.
Empty file.
15 changes: 15 additions & 0 deletions markus_autotesting_core/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .types import (
_AutotestSettings,
AutotestFile,
BaseTesterSettings,
BaseTestData,
create_autotest_settings_class,
)

__all__ = [
"_AutotestSettings",
"AutotestFile",
"BaseTesterSettings",
"BaseTestData",
"create_autotest_settings_class",
]
105 changes: 105 additions & 0 deletions markus_autotesting_core/types/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""This file defines the core types used in the Markus Autotesting system."""

from __future__ import annotations
from functools import reduce
from typing import Annotated, Any, Optional, Union

from msgspec import Meta, Struct


class _AutotestSettings(Struct, kw_only=True):
"""The main test settings data type."""

testers: Annotated[list, Meta(title="Testers", min_length=1)]
"""The list of testers configured for these settings."""

_user: Optional[str] = None
"""The user who last updated the test settings."""

_last_access: Optional[int] = None
"""The last time the test settings were updated."""

_files: Optional[str] = None
"""A list of test files associated with these settings."""

_env_status: Optional[str] = None
"""The status of the test environment creation for these settings."""

_error: Optional[str] = None
"""An error message, populated when creating a test environment fails."""


def create_autotest_settings_class(tester_classes: list[type]) -> type[Struct]:
"""Dynamically create an AutotestSettings data type.

This uses _AutotestSettings as the base class, replacing the `testers` annotation
with a union of the provided tester_classes.
"""
return type(
"AutotestSettings",
(_AutotestSettings,),
{
"__annotations__": {
"testers": Annotated[
list[reduce(lambda a, b: Union[a, b], tester_classes)],
Meta(title="Testers", min_length=1),
]
}
},
)


class BaseTesterSettings(
Struct,
kw_only=True,
tag_field="tester_type",
tag=lambda x: x.removesuffix("TesterSettings").lower(),
):
"""The settings for an individual tester.

This is a tagged union of various testers, using `tester_type` as the discriminator field.
"""

test_data: Optional[Any] = None
"""The settings for the tester."""

@property
def tester_type(self) -> str:
return self.__class__.__name__.removesuffix("TesterSettings").lower()

_env: Optional[dict[str, Any]] = None
"""Environment variables to pass to the tester."""


class BaseTestData(
Struct,
kw_only=True,
):
"""Base class for all `test_data` fields.

This is subclassed to specify tester-specific `test_data` settings.
"""

category: Annotated[
list[Annotated[str, Meta(extra_json_schema={"enum": [], "enumNames": []})]],
Meta(title="Category", extra_json_schema={"uniqueItems": True}),
]

script_files: Annotated[
list[AutotestFile],
Meta(title="Test files", min_length=1, extra_json_schema={"uniqueItems": True}),
]
"""The file(s) that contain the tests to execute."""

timeout: Annotated[int, Meta(title="Timeout")] = 30
"""The timeout in seconds for this test group."""

feedback_file_names: Annotated[list[str], Meta(title="Feedback files")]
"""A list of file paths generated by executing this test group."""

extra_info: dict = {}
"""TODO"""


AutotestFile = Annotated[str, Meta(extra_json_schema={"enum": []})]
"""A placeholder in the JSON schema representing one of the files provided to the autotesting environment."""
39 changes: 39 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[project]
name = "markus-autotesting-core"
version = "0.1.0"
description = "Core functionality for Markus Autotesting"
authors = [
{name = "David Liu", email = "david@cs.toronto.edu"}
]
license = "MIT"
readme = "README.md"
keywords = ["autotesting", "markus"]
dependencies = [
"msgspec"
]
requires-python = ">=3.9"

[project.urls]
Homepage = "https://github.com/MarkUsProject/markus-autotesting-core"
Repository = "https://github.com/MarkUsProject/markus-autotesting-core.git"

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = true
zip-safe = false

[tool.setuptools.dynamic]
version = {attr = "python_ta.__version__"}
#readme = {file = "README.md", content-type = "text/markdown"}

[tool.setuptools.packages.find]
include = ["markus_autotesting_core*"]

[dependency-groups]
dev = [
"pytest>=8.4.2",
"ruff>=0.14.3",
]
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup()
36 changes: 36 additions & 0 deletions tests/test_types/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from markus_autotesting_core.types import BaseTestData


def test_base_test_data_fields():
"""Test that the BaseTestData class has the expected fields."""
annotations = BaseTestData.__annotations__

assert "category" in annotations
assert "script_files" in annotations
assert "timeout" in annotations
assert "feedback_file_names" in annotations
assert "extra_info" in annotations


def test_base_test_data_decoding():
"""Test that an instance of BaseTestData can be dencoded from JSON."""
import msgspec
import json

json_data = json.dumps(
{
"category": ["unit", "integration"],
"script_files": ["test1.py", "test2.py"],
"timeout": 60,
"feedback_file_names": ["feedback.txt"],
"extra_info": {"note": "This is a test."},
}
)

decoded = msgspec.json.decode(json_data, type=BaseTestData)

assert decoded.category == ["unit", "integration"]
assert decoded.script_files == ["test1.py", "test2.py"]
assert decoded.timeout == 60
assert decoded.feedback_file_names == ["feedback.txt"]
assert decoded.extra_info == {"note": "This is a test."}
Loading