|
1 | | -from typing import List, Union |
2 | | - |
3 | | -from robot.api import SuiteVisitor |
4 | | -from robot.running import TestCase, TestSuite |
5 | | - |
6 | | - |
7 | | -class ByLongName(SuiteVisitor): # type: ignore |
8 | | - def __init__(self, *included: str) -> None: |
9 | | - super().__init__() |
10 | | - self.included = included |
11 | | - |
12 | | - def start_suite(self, suite: TestSuite) -> None: |
13 | | - suite.tests = [t for t in suite.tests if self._is_included(t)] |
14 | | - |
15 | | - def _is_included(self, test: Union[TestCase, TestSuite]) -> bool: |
16 | | - names = [] |
17 | | - names.append(test.longname) |
18 | | - current = test.parent |
19 | | - while current: |
20 | | - names.append(current.longname) |
21 | | - current = current.parent |
22 | | - |
23 | | - return any((s in names) for s in self.included) |
24 | | - |
25 | | - def end_suite(self, suite: TestSuite) -> None: |
26 | | - suite.suites = [s for s in suite.suites if s.test_count > 0] |
27 | | - |
28 | | - |
29 | | -class ExcludedByLongName(SuiteVisitor): # type: ignore |
30 | | - def __init__(self, *included: str) -> None: |
31 | | - super().__init__() |
32 | | - self.included = included |
33 | | - |
34 | | - def start_suite(self, suite: TestSuite) -> None: |
35 | | - suite.tests = [t for t in suite.tests if not self._is_included(t)] |
36 | | - |
37 | | - def _is_included(self, test: Union[TestCase, TestSuite]) -> bool: |
38 | | - names = [] |
39 | | - names.append(test.longname) |
40 | | - current = test.parent |
41 | | - while current: |
42 | | - names.append(current.longname) |
43 | | - current = current.parent |
44 | | - |
45 | | - return any((s in names) for s in self.included) |
46 | | - |
47 | | - def end_suite(self, suite: TestSuite) -> None: |
48 | | - suite.suites = [s for s in suite.suites if s.test_count > 0] |
| 1 | +from .longname_modifiers import ByLongName, ExcludedByLongName |
0 commit comments