forked from allure-framework/allure-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.py
More file actions
171 lines (142 loc) · 5.19 KB
/
container.py
File metadata and controls
171 lines (142 loc) · 5.19 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from hamcrest.core.base_matcher import BaseMatcher
from hamcrest import all_of
from hamcrest import has_entry, has_item, has_property, equal_to
class HasContainer(BaseMatcher):
def __init__(self, report, *matchers):
self.report = report
self.matchers = matchers
def _matches(self, item):
return has_property(
'test_containers',
has_item(
all_of(
has_entry('children', has_item(item['uuid'])),
*self.matchers
)
)).matches(self.report)
def describe_to(self, description):
description.append_text('describe me later').append_list('[', ', ', ']', self.matchers)
def describe_mismatch(self, item, mismatch_description):
self.matches(item, mismatch_description)
def has_container(report, *matchers):
"""
>>> from hamcrest import assert_that
>>> from allure_commons_test.report import has_test_case
>>> class Report:
... test_cases = [
... {
... 'fullName': 'test_case',
... 'uuid': 'test_case_uuid'
... },
... {
... 'fullName': 'test_case_without_container',
... 'uuid': 'test_case_without_container_uuid'
... }
... ]
... test_containers = [
... {
... 'children' : ['test_case_uuid'],
... 'befores': [ {'name': 'before_fixture'} ]
... }
... ]
>>> assert_that(Report,
... has_test_case('test_case',
... has_container(Report,
... has_before('before_fixture')
... )
... )
... )
>>> assert_that(Report,
... has_test_case('test_case_without_container',
... has_container(Report,
... has_before('before_fixture')
... )
... )
... ) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError: ...
Expected: ...
but: ...
<BLANKLINE>
"""
return HasContainer(report, *matchers)
class HasSameContainer(BaseMatcher):
def __init__(self, *args):
self.test_case_names = [test_case_name for test_case_name in args if isinstance(test_case_name, str)]
self.matchers = args[len(self.test_case_names):]
@staticmethod
def _test_case_id_by_name(report, test_case_name):
for test_case in report.test_cases:
if test_case['fullName'].endswith(test_case_name):
return test_case['uuid']
def _matches(self, report):
return has_property('test_containers',
has_item(
all_of(
has_entry('children',
all_of(
*[has_item(self._test_case_id_by_name(report, name))
for name in self.test_case_names]
)),
*self.matchers
)
)
).matches(report)
# TODO better describe
def describe_to(self, description):
description.append_text('test_case has group')
def has_same_container(*args):
"""
>>> from hamcrest import assert_that
>>> class Report:
... test_cases = [
... {
... 'fullName': 'first_test_case',
... 'uuid': 'first_test_case_uuid'
... },
... {
... 'fullName': 'second_test_case',
... 'uuid': 'second_test_case_uuid'
... },
... {
... 'fullName': 'third_test_case',
... 'uuid': 'third_test_case_uuid'
... }
... ]
... test_containers = [
... {
... 'children' : ['first_test_case_uuid', 'second_test_case_uuid'],
... },
... {
... 'children' : ['first_test_case_uuid', 'third_test_case_uuid'],
... }
... ]
>>> assert_that(Report,
... has_same_container('first_test_case', 'second_test_case')
... )
>>> assert_that(Report,
... has_same_container('second_test_case', 'third_test_case')
... ) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError: ...
Expected: ...
but: ...
<BLANKLINE>
"""
return HasSameContainer(*args)
def has_fixture(section, name, *matchers):
return has_entry(
section,
has_item(
all_of(
has_entry('name', equal_to(name)),
*matchers
)
)
)
def has_before(name, *matchers):
return has_fixture('befores', name, *matchers)
def has_after(name, *matchers):
return has_fixture('afters', name, *matchers)