|
1 | 1 | import re |
2 | 2 |
|
3 | | -from .case_info import CaseInfo |
| 3 | +from .case_funcs import get_case_id, get_case_tags |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class CaseFilter(object): |
@@ -41,36 +41,78 @@ def __invert__(self): |
41 | 41 | ) |
42 | 42 |
|
43 | 43 |
|
44 | | -def has_tag(tag_name): |
45 | | - """Select cases that have the tag `tag_name`. See `@case(tags=...)` to add tags to a case.""" |
46 | | - return CaseFilter(lambda case: tag_name in CaseInfo.get_from(case).tags) |
| 44 | +def has_tags(*tag_names # type: str |
| 45 | + ): |
| 46 | + """ |
| 47 | + Selects cases that have all tags in `tag_names`. See `@case(tags=...)` to add tags to a case. |
| 48 | +
|
| 49 | + :param tag_names: |
| 50 | + :return: |
| 51 | + """ |
| 52 | + |
| 53 | + def _filter(case): |
| 54 | + return len( |
| 55 | + set(tag_names) - set(get_case_tags(case)) |
| 56 | + ) == 0 |
| 57 | + |
| 58 | + return CaseFilter(_filter) |
| 59 | + |
| 60 | + |
| 61 | +def has_tag(tag_name # type: str |
| 62 | + ): |
| 63 | + """ |
| 64 | + Selects cases that have the tag `tag_name`. See `@case(tags=...)` to add tags to a case. |
| 65 | +
|
| 66 | + :param tag_name: |
| 67 | + :return: |
| 68 | + """ |
| 69 | + |
| 70 | + def _filter(case): |
| 71 | + return tag_name in get_case_tags(case) |
| 72 | + |
| 73 | + return CaseFilter(_filter) |
47 | 74 |
|
48 | 75 |
|
49 | | -def id_has_prefix(prefix): |
| 76 | +def id_has_prefix(prefix # type: str |
| 77 | + ): |
50 | 78 | """ |
51 | | - Select cases that have a case id prefix `prefix`. |
| 79 | + Selects cases that have a case id prefix `prefix`. |
52 | 80 |
|
53 | 81 | Note that this is not the prefix of the whole case function name, but the case id, |
54 | 82 | possibly overridden with `@case(id=)` |
55 | 83 | """ |
56 | | - return CaseFilter(lambda case: CaseInfo.get_from(case).id.startswith(prefix)) |
| 84 | + |
| 85 | + def _filter(case): |
| 86 | + return get_case_id(case).startswith(prefix) |
| 87 | + |
| 88 | + return CaseFilter(_filter) |
57 | 89 |
|
58 | 90 |
|
59 | | -def id_has_suffix(suffix): |
| 91 | +def id_has_suffix(suffix # type: str |
| 92 | + ): |
60 | 93 | """ |
61 | | - Select cases that have a case id suffix `suffix`. |
| 94 | + Selects cases that have a case id suffix `suffix`. |
62 | 95 |
|
63 | 96 | Note that this is not the suffix of the whole case function name, but the case id, |
64 | 97 | possibly overridden with `@case(id=)` |
65 | 98 | """ |
66 | | - return CaseFilter(lambda case: CaseInfo.get_from(case).id.endswith(suffix)) |
67 | 99 |
|
| 100 | + def _filter(case): |
| 101 | + return get_case_id(case).endswith(suffix) |
68 | 102 |
|
69 | | -def id_match_regex(regex): |
| 103 | + return CaseFilter(_filter) |
| 104 | + |
| 105 | + |
| 106 | +def id_match_regex(regex # type: str |
| 107 | + ): |
70 | 108 | """ |
71 | 109 | Select cases that have a case id matching `regex`. |
72 | 110 |
|
73 | 111 | Note that this is not a match of the whole case function name, but the case id, |
74 | 112 | possibly overridden with `@case(id=)` |
75 | 113 | """ |
76 | | - return CaseFilter(lambda case: re.match(regex, CaseInfo.get_from(case).id)) |
| 114 | + |
| 115 | + def _filter(case): |
| 116 | + return re.match(regex, get_case_id(case)) |
| 117 | + |
| 118 | + return CaseFilter(_filter) |
0 commit comments