File: test.py

package info (click to toggle)
blender 4.3.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 309,564 kB
  • sloc: cpp: 2,385,210; python: 330,236; ansic: 280,972; xml: 2,446; sh: 972; javascript: 317; makefile: 170
file content (84 lines) | stat: -rw-r--r-- 2,325 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# SPDX-FileCopyrightText: 2021-2022 Blender Authors
#
# SPDX-License-Identifier: Apache-2.0

import abc
import fnmatch
from typing import Dict, List


class Test:
    @abc.abstractmethod
    def name(self) -> str:
        """
        Name of the test.
        """

    @abc.abstractmethod
    def category(self) -> str:
        """
        Category of the test.
        """

    def use_device(self) -> bool:
        """
        Test uses a specific CPU or GPU device.
        """
        return False

    def use_background(self) -> bool:
        """
        Test runs in background mode and requires no display.
        """
        return True

    @abc.abstractmethod
    def run(self, env, device_id: str) -> Dict:
        """
        Execute the test and report results.
        """


class TestCollection:
    def __init__(self, env, names_filter: List = ['*'], categories_filter: List = ['*'], background: bool = False):
        import importlib
        import pkgutil
        import tests

        self.tests = []

        # Find and import all Python files in the tests folder, and generate
        # the list of tests for each.
        for _, modname, _ in pkgutil.iter_modules(tests.__path__, 'tests.'):
            module = importlib.import_module(modname)
            tests = module.generate(env)

            for test in tests:
                if background and not test.use_background():
                    continue

                test_category = test.category()
                found = False
                for category_filter in categories_filter:
                    if fnmatch.fnmatch(test_category, category_filter):
                        found = True
                if not found:
                    continue

                test_name = test.name()
                found = False
                for name_filter in names_filter:
                    if fnmatch.fnmatch(test_name, name_filter):
                        found = True
                if not found:
                    continue

                self.tests.append(test)

    def find(self, test_name: str, test_category: str):
        # Find a test based on name and category.
        for test in self.tests:
            if test.name() == test_name and test.category() == test_category:
                return test

        return None