Skip to content

add schema checking test #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"features": {
// add in eternal history and other bash features
"ghcr.io/diamondlightsource/devcontainer-features/bash-config:1.0.0": {}
"ghcr.io/diamondlightsource/devcontainer-features/bash-config:1": {}
},
// Create the config folder for the bash-config feature
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/bash-config",
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ lockfiles/

# Demo output path for vscode tasks
demo-output

# vscode workspaces are local only
*.code-workspace
16 changes: 8 additions & 8 deletions src/deploy_tools/models/schemas/deployment.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$defs": {
"Apptainer": {
"ApptainerApp": {
"additionalProperties": false,
"description": "Represents an Apptainer application or set of applications for a single image.\n\nThis uses Apptainer to deploy a portable image of the desired container. Several\nentrypoints can then be specified to allow for multiple commands run on the same\ncontainer image.",
"properties": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"container",
"entrypoints"
],
"title": "Apptainer",
"title": "ApptainerApp",
"type": "object"
},
"ContainerImage": {
Expand Down Expand Up @@ -197,17 +197,17 @@
"items": {
"discriminator": {
"mapping": {
"apptainer": "#/$defs/Apptainer",
"shell": "#/$defs/Shell"
"apptainer": "#/$defs/ApptainerApp",
"shell": "#/$defs/ShellApp"
},
"propertyName": "app_type"
},
"oneOf": [
{
"$ref": "#/$defs/Apptainer"
"$ref": "#/$defs/ApptainerApp"
},
{
"$ref": "#/$defs/Shell"
"$ref": "#/$defs/ShellApp"
}
]
},
Expand Down Expand Up @@ -281,7 +281,7 @@
},
"type": "object"
},
"Shell": {
"ShellApp": {
"additionalProperties": false,
"description": "Represents a Shell application.\n\nThis will run the code specified as a shell script. This currently uses Bash for\nimproved functionality while retaining high compatibility with various Linux\ndistributions.",
"properties": {
Expand All @@ -307,7 +307,7 @@
"name",
"script"
],
"title": "Shell",
"title": "ShellApp",
"type": "object"
}
},
Expand Down
16 changes: 8 additions & 8 deletions src/deploy_tools/models/schemas/module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$defs": {
"Apptainer": {
"ApptainerApp": {
"additionalProperties": false,
"description": "Represents an Apptainer application or set of applications for a single image.\n\nThis uses Apptainer to deploy a portable image of the desired container. Several\nentrypoints can then be specified to allow for multiple commands run on the same\ncontainer image.",
"properties": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"container",
"entrypoints"
],
"title": "Apptainer",
"title": "ApptainerApp",
"type": "object"
},
"ContainerImage": {
Expand Down Expand Up @@ -179,17 +179,17 @@
"items": {
"discriminator": {
"mapping": {
"apptainer": "#/$defs/Apptainer",
"shell": "#/$defs/Shell"
"apptainer": "#/$defs/ApptainerApp",
"shell": "#/$defs/ShellApp"
},
"propertyName": "app_type"
},
"oneOf": [
{
"$ref": "#/$defs/Apptainer"
"$ref": "#/$defs/ApptainerApp"
},
{
"$ref": "#/$defs/Shell"
"$ref": "#/$defs/ShellApp"
}
]
},
Expand Down Expand Up @@ -232,7 +232,7 @@
"title": "ModuleDependency",
"type": "object"
},
"Shell": {
"ShellApp": {
"additionalProperties": false,
"description": "Represents a Shell application.\n\nThis will run the code specified as a shell script. This currently uses Bash for\nimproved functionality while retaining high compatibility with various Linux\ndistributions.",
"properties": {
Expand All @@ -258,7 +258,7 @@
"name",
"script"
],
"title": "Shell",
"title": "ShellApp",
"type": "object"
}
},
Expand Down
16 changes: 8 additions & 8 deletions src/deploy_tools/models/schemas/release.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$defs": {
"Apptainer": {
"ApptainerApp": {
"additionalProperties": false,
"description": "Represents an Apptainer application or set of applications for a single image.\n\nThis uses Apptainer to deploy a portable image of the desired container. Several\nentrypoints can then be specified to allow for multiple commands run on the same\ncontainer image.",
"properties": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"container",
"entrypoints"
],
"title": "Apptainer",
"title": "ApptainerApp",
"type": "object"
},
"ContainerImage": {
Expand Down Expand Up @@ -179,17 +179,17 @@
"items": {
"discriminator": {
"mapping": {
"apptainer": "#/$defs/Apptainer",
"shell": "#/$defs/Shell"
"apptainer": "#/$defs/ApptainerApp",
"shell": "#/$defs/ShellApp"
},
"propertyName": "app_type"
},
"oneOf": [
{
"$ref": "#/$defs/Apptainer"
"$ref": "#/$defs/ApptainerApp"
},
{
"$ref": "#/$defs/Shell"
"$ref": "#/$defs/ShellApp"
}
]
},
Expand Down Expand Up @@ -232,7 +232,7 @@
"title": "ModuleDependency",
"type": "object"
},
"Shell": {
"ShellApp": {
"additionalProperties": false,
"description": "Represents a Shell application.\n\nThis will run the code specified as a shell script. This currently uses Bash for\nimproved functionality while retaining high compatibility with various Linux\ndistributions.",
"properties": {
Expand All @@ -258,7 +258,7 @@
"name",
"script"
],
"title": "Shell",
"title": "ShellApp",
"type": "object"
}
},
Expand Down
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import os
from pathlib import Path
from typing import Any

import pytest
from typer.testing import CliRunner

from deploy_tools.__main__ import app

runner = CliRunner()


def run_cli(*args):
result = runner.invoke(app, [str(x) for x in args])
if result.exception:
raise result.exception
assert result.exit_code == 0, result


# Prevent pytest from catching exceptions when debugging in vscode so that break on
# exception works correctly (see: https://github.com/pytest-dev/pytest/issues/7409)
Expand All @@ -19,3 +33,8 @@ def pytest_exception_interact(call: pytest.CallInfo[Any]):
@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo: pytest.ExceptionInfo[Any]):
raise excinfo.value


@pytest.fixture
def schemas():
return Path(__file__).parent.parent / "src" / "deploy_tools" / "models" / "schemas"
15 changes: 15 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import subprocess
import sys
import tempfile
from pathlib import Path

from conftest import run_cli
from deploy_tools import __version__


def test_cli_version():
cmd = [sys.executable, "-m", "deploy_tools", "--version"]
assert subprocess.check_output(cmd).decode().strip() == __version__


def test_schema(schemas: Path):
with tempfile.TemporaryDirectory() as tmp:
tmp_path = Path(tmp)
# Generate up to date schema files
run_cli("schema", tmp_path)
# Compare with the expected schema files
for schema in tmp_path.glob("*.json"):
expected = schemas / schema.name
if schema.read_text() != expected.read_text():
raise AssertionError(f"Schema file {expected} is out of date.")
Loading