Skip to content

Commit

Permalink
Merge pull request #5891 from clebergnu/runnable_recipe_schema
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Richter <[email protected]>
  • Loading branch information
richtja committed Mar 28, 2024
2 parents 6ae2f01 + 2edd3e3 commit 76199b2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
35 changes: 35 additions & 0 deletions contrib/schemas/runnable-recipe.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://avocado-project.org/runnable-recipe.schema.json",
"title": "runnable-recipe",
"description": "Runnable serialized in a JSON based recipe file",
"type": "object",
"properties": {
"kind": {
"description": "The kind of runnable, which should be matched to a capable runner",
"type": "string"
},
"uri": {
"description": "The main reference to what needs to be run. This is free form, but commonly set to the path to a file containing the test or being the test, or an actual URI with multiple parts",
"type": "string"
},
"args": {
"description": "Sequence of arguments to be interpreted by the runner. For instance, exec-test turns these into positional command line arguments",
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": false
},
"kwargs": {
"description": "Keyword based arguments, that is, a sequence of key and values. The exec-test, for instance, will turn these into environment variables",
"type": "object"
},
"config": {
"description": "Avocado settings that should be applied to this runnable. At least the ones declared as CONFIGURATION_USED in the runner specific for this kind should be present",
"type": "object"
}
},
"additionalProperties": false,
"required": [ "kind" ]
}
2 changes: 1 addition & 1 deletion selftests/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"job-api-7": 1,
"nrunner-interface": 70,
"nrunner-requirement": 16,
"unit": 667,
"unit": 668,
"jobs": 11,
"functional-parallel": 301,
"functional-serial": 4,
Expand Down
35 changes: 35 additions & 0 deletions selftests/unit/nrunner_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import glob
import json
import os

from avocado import Test, skipUnless
from selftests.utils import BASEDIR

try:
import jsonschema

JSONSCHEMA_AVAILABLE = True
except ImportError:
JSONSCHEMA_AVAILABLE = False


BASE_SCHEMA_DIR = os.path.join(BASEDIR, "contrib", "schemas")
BASE_RECIPE_DIR = os.path.join(BASEDIR, "examples", "nrunner", "recipes")


@skipUnless(JSONSCHEMA_AVAILABLE, "jsonschema module not available")
class Schema(Test):
def _test(self, schema_filename, recipe_path):
schema_path = os.path.join(BASE_SCHEMA_DIR, schema_filename)
with open(schema_path, "r", encoding="utf-8") as schema:
with open(recipe_path, "r", encoding="utf-8") as recipe:
try:
jsonschema.validate(json.load(recipe), json.load(schema))
except jsonschema.exceptions.ValidationError as details:
self.fail(details)

def test_runnable_recipes(self):
for recipe_path in glob.glob(
os.path.join(BASE_RECIPE_DIR, "runnables", "*.json")
):
self._test("runnable-recipe.schema.json", recipe_path)

0 comments on commit 76199b2

Please sign in to comment.