1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| | #! /usr/bin/python3
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright Red Hat
# Author: David Gibson <david@gibson.dropbear.id.au>
"""
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)
|