#! /usr/bin/python3 # SPDX-License-Identifier: GPL-2.0-or-later # # Copyright Red Hat # Author: David Gibson """ Manage the manifest of classless tests in a module """ import sys MANIFEST = "__avocado_classless__" DEFAULT_TIMEOUT = 60.0 def manifest(mod): """Return avocado-classless manifest for a Python module""" if not hasattr(mod, MANIFEST): setattr(mod, MANIFEST, {}) return getattr(mod, MANIFEST) class ManifestTestInfo: # pylint: disable=R0903 """Metadata about a classless test""" def __init__(self, func, timeout=DEFAULT_TIMEOUT): self.func = func self.__timeout = float(timeout) def run_test(self): self.func() def timeout(self): return self.__timeout def manifest_add(mod, name, func, **kwargs): """Register a function as a classless test""" if isinstance(mod, str): mod = sys.modules[mod] mfest = manifest(mod) if name in mfest: raise ValueError(f"Duplicate classless test name {name}") mfest[name] = ManifestTestInfo(func, **kwargs)