Skip to content

Commit

Permalink
[WIP] Expand example to include schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
  • Loading branch information
LecrisUT committed May 24, 2024
1 parent f47814b commit 64f66db
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import dataclasses

import tmt
import tmt.steps
import tmt.steps.discover
import tmt.utils

# See the online documentation for more details about writing plugins
# https://tmt.readthedocs.io/en/stable/plugins.html


@dataclasses.dataclass
class DiscoverExampleData(tmt.steps.discover.DiscoverStepData):
path: str = tmt.utils.field(
default=".",
option=('-p', '--path'),
metavar='ROOT',
help='Path to the metadata tree root.')


@tmt.steps.provides_method('example')
class DiscoverExample(tmt.steps.discover.DiscoverPlugin):
"""
Expand All @@ -16,6 +28,8 @@ class DiscoverExample(tmt.steps.discover.DiscoverPlugin):
of configuration examples as well.
"""

_data_class = DiscoverExampleData

def show(self):
""" Show plugin details for given or all available keys """
super().show([])
Expand Down Expand Up @@ -48,7 +62,8 @@ def go(self):
print("Code should prepare environment for tests.")

# Discover available tests
self._tests = tmt.Tree(logger=self._logger, path=".").tests()
self._tests = tmt.Tree(logger=self._logger,
path=self.data.path).tests()

def tests(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def default(self, option, default=None):
defaults = {
'what': 'default value',
'switch': False,
}
}
return defaults.get(option, default)

def show(self):
Expand Down
23 changes: 23 additions & 0 deletions examples/plugins/example/schemas/discover/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$id: /schemas/discover/example
$schema: https://json-schema.org/draft-07/schema

type: object
additionalProperties: false

properties:

how:
type: string
enum:
- example
path:
$ref: "/schemas/common#/definitions/fmf_id/properties/path"

# Other basic discover properties
name:
type: string
order:
$ref: "/schemas/core#/definitions/order"

required:
- how
12 changes: 7 additions & 5 deletions examples/plugins/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ dependencies = [
]

[tool.setuptools]
py-modules = [
"discover",
"provision",
packages = [
"example",
]

[project.entry-points."tmt.plugin"]
ProvisionExample = "provision:ProvisionExample"
DiscoverExample = "discover:DiscoverExample"
ProvisionExample = "example.provision:ProvisionExample"
DiscoverExample = "example.discover:DiscoverExample"

[project.entry-points."tmt.resources"]
ResourcesExample = "examaple"

0 comments on commit 64f66db

Please sign in to comment.