Coverage for structured_tutorials / models / tests.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-21 19:08 +0100
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-21 19:08 +0100
1# Copyright (c) 2025 Mathias Ertl
2# Licensed under the MIT License. See LICENSE file for details.
4"""Test specifications for commands."""
6import re
7from typing import Annotated, Literal
9from pydantic import BaseModel, BeforeValidator, ConfigDict, Field
11from structured_tutorials.models.base import CommandBaseModel, CommandType, TestSpecificationMixin
12from structured_tutorials.models.validators import validate_regex
15class TestCommandModel(TestSpecificationMixin, CommandBaseModel):
16 """Test a command by running another command."""
18 model_config = ConfigDict(extra="forbid")
20 command: CommandType = Field(description="The command to run.")
23class TestPortModel(TestSpecificationMixin, BaseModel):
24 """Test a command by checking if a port is open."""
26 model_config = ConfigDict(extra="forbid")
28 host: str = Field(description="The host to connect to.")
29 port: Annotated[int, Field(ge=0, le=65535)] = Field(description="The port to connect to.")
32class TestOutputModel(BaseModel):
33 """Test a command by checking the output of a command."""
35 model_config = ConfigDict(extra="forbid")
37 stream: Literal["stdout", "stderr"] = Field(default="stdout", description="The output stream to use.")
38 regex: Annotated[re.Pattern[bytes], BeforeValidator(validate_regex)] = Field(
39 description="A regular expression to test."
40 )