teddecor.UnitTest.TestSuite

Test Suite

A collection of tests that are to be run. Can be either test classes or individual test cases.

 1"""Test Suite
 2
 3A collection of tests that are to be run.
 4Can be either test classes or individual test cases.
 5"""
 6from __future__ import annotations
 7from inspect import isclass
 8from typing import Callable, Pattern, Union
 9
10from .Results import SuiteResult
11from .Testing import Test, test, run
12
13__all__ = ["TestSuite"]
14
15
16class TestSuite:
17    """Run the given test classes or filter with regex."""
18
19    def __init__(
20        self,
21        name: str,
22        tests: list[Union[Test, test]] = [],
23    ):
24        """Start with a list of Test classes or test functions. The function name patter can also be specified.
25            Lastly you can specify whether a Test class outputs the result
26
27        Args:
28            tests (list[Union[Test, test]], optional): _description_. Defaults to None.
29            regex (Pattern, optional): _description_. Defaults to None.
30            output (bool, optional): _description_. Defaults to True.
31        """
32        self._name = name
33        self._tests = tests
34
35    @property
36    def name(self) -> str:
37        return self._name
38
39    @property
40    def tests(self) -> Union[list, None]:
41        return self._tests
42
43    @tests.setter
44    def tests(self, tests: list[Test]):
45        self._tests = tests
46
47    @property
48    def regex(self) -> Union[str, None]:
49        return self._regex
50
51    @regex.setter
52    def regex(self, regex: str):
53        self._regex = regex
54
55    def append(self, obj: Union[Test, Callable]):
56        if self._tests is None:
57            self._tests = []
58
59        self._tests.append(obj)
60
61    def run(
62        self,
63        display: bool = True,
64        regex: Pattern = None,
65    ) -> SuiteResult:
66        """Run all the provided test classes and cases.q
67
68        Args:
69            display (bool, optional): Whether to display anything. Defaults to True
70            regex (Pattern, optional): Pattern of which tests should be run
71
72        Returns:
73            SuiteResult: Results object that can save and print the results
74        """
75        from re import match
76
77        _results = SuiteResult(self.name)
78
79        for test in self.tests:
80            if isclass(test):
81                _results.append(test().run(regex=regex, display=False))
82            else:
83                result = run(test, display=False)
84                if regex is not None and match(regex, result.name):
85                    _results.append(result)
86                elif regex is None:
87                    _results.append(result)
88
89        if display:
90            _results.write()
91
92        return _results
class TestSuite:
17class TestSuite:
18    """Run the given test classes or filter with regex."""
19
20    def __init__(
21        self,
22        name: str,
23        tests: list[Union[Test, test]] = [],
24    ):
25        """Start with a list of Test classes or test functions. The function name patter can also be specified.
26            Lastly you can specify whether a Test class outputs the result
27
28        Args:
29            tests (list[Union[Test, test]], optional): _description_. Defaults to None.
30            regex (Pattern, optional): _description_. Defaults to None.
31            output (bool, optional): _description_. Defaults to True.
32        """
33        self._name = name
34        self._tests = tests
35
36    @property
37    def name(self) -> str:
38        return self._name
39
40    @property
41    def tests(self) -> Union[list, None]:
42        return self._tests
43
44    @tests.setter
45    def tests(self, tests: list[Test]):
46        self._tests = tests
47
48    @property
49    def regex(self) -> Union[str, None]:
50        return self._regex
51
52    @regex.setter
53    def regex(self, regex: str):
54        self._regex = regex
55
56    def append(self, obj: Union[Test, Callable]):
57        if self._tests is None:
58            self._tests = []
59
60        self._tests.append(obj)
61
62    def run(
63        self,
64        display: bool = True,
65        regex: Pattern = None,
66    ) -> SuiteResult:
67        """Run all the provided test classes and cases.q
68
69        Args:
70            display (bool, optional): Whether to display anything. Defaults to True
71            regex (Pattern, optional): Pattern of which tests should be run
72
73        Returns:
74            SuiteResult: Results object that can save and print the results
75        """
76        from re import match
77
78        _results = SuiteResult(self.name)
79
80        for test in self.tests:
81            if isclass(test):
82                _results.append(test().run(regex=regex, display=False))
83            else:
84                result = run(test, display=False)
85                if regex is not None and match(regex, result.name):
86                    _results.append(result)
87                elif regex is None:
88                    _results.append(result)
89
90        if display:
91            _results.write()
92
93        return _results

Run the given test classes or filter with regex.

TestSuite( name: str, tests: list[typing.Union[teddecor.UnitTest.Testing.Test, test]] = [])
20    def __init__(
21        self,
22        name: str,
23        tests: list[Union[Test, test]] = [],
24    ):
25        """Start with a list of Test classes or test functions. The function name patter can also be specified.
26            Lastly you can specify whether a Test class outputs the result
27
28        Args:
29            tests (list[Union[Test, test]], optional): _description_. Defaults to None.
30            regex (Pattern, optional): _description_. Defaults to None.
31            output (bool, optional): _description_. Defaults to True.
32        """
33        self._name = name
34        self._tests = tests

Start with a list of Test classes or test functions. The function name patter can also be specified. Lastly you can specify whether a Test class outputs the result

Args: tests (list[Union[Test, test]], optional): _description_. Defaults to None. regex (Pattern, optional): _description_. Defaults to None. output (bool, optional): _description_. Defaults to True.

name: str
tests: Optional[list]
regex: Optional[str]
def append(self, obj: Union[teddecor.UnitTest.Testing.Test, Callable])
56    def append(self, obj: Union[Test, Callable]):
57        if self._tests is None:
58            self._tests = []
59
60        self._tests.append(obj)
def run( self, display: bool = True, regex: Pattern = None) -> teddecor.UnitTest.Results.SuiteResult:
62    def run(
63        self,
64        display: bool = True,
65        regex: Pattern = None,
66    ) -> SuiteResult:
67        """Run all the provided test classes and cases.q
68
69        Args:
70            display (bool, optional): Whether to display anything. Defaults to True
71            regex (Pattern, optional): Pattern of which tests should be run
72
73        Returns:
74            SuiteResult: Results object that can save and print the results
75        """
76        from re import match
77
78        _results = SuiteResult(self.name)
79
80        for test in self.tests:
81            if isclass(test):
82                _results.append(test().run(regex=regex, display=False))
83            else:
84                result = run(test, display=False)
85                if regex is not None and match(regex, result.name):
86                    _results.append(result)
87                elif regex is None:
88                    _results.append(result)
89
90        if display:
91            _results.write()
92
93        return _results

Run all the provided test classes and cases.q

Args: display (bool, optional): Whether to display anything. Defaults to True regex (Pattern, optional): Pattern of which tests should be run

Returns: SuiteResult: Results object that can save and print the results