forked from allure-framework/allure-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
104 lines (84 loc) · 2.71 KB
/
report.py
File metadata and controls
104 lines (84 loc) · 2.71 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
"""
>>> from hamcrest import assert_that
>>> class Report(object):
... def __init__(self):
... self.test_cases = [
... {
... 'fullName': 'package.module.test',
... 'id': '1'
... },
... {
... 'fullName': 'package.module.test[param]',
... 'id': '2'
... },
... {
... 'fullName': 'package.module.Class#test[param]',
... 'id': '3'
... }
... ]
>>> assert_that(Report(),
... has_test_case('test')
... )
>>> assert_that(Report(),
... has_test_case('test[param]')
... )
>>> assert_that(Report(),
... has_test_case('Class#test[param]')
... )
>>> assert_that(Report(),
... has_test_case('wrong_test_case_name')
... ) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError: ...
Expected: ...
but: property 'test_cases' was <[{...}]>
<BLANKLINE>
>>> assert_that(Report(),
... has_test_case('test',
... has_entry('id', '1')
... )
... )
>>> assert_that(Report(),
... has_test_case('Class#test[param]',
... has_entry('id', '2')
... )
... ) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError: ...
Expected: ...
but: property 'test_cases' was <[{...}]>
<BLANKLINE>
"""
import os
import json
import fnmatch
from hamcrest import all_of, any_of
from hamcrest import has_property
from hamcrest import has_item
from hamcrest import has_entry
from hamcrest import ends_with
class AllureReport(object):
def __init__(self, result):
self.test_cases = [json.load(item) for item in self._report_items(result, '*result.json')]
self.test_containers = [json.load(item) for item in self._report_items(result, '*container.json')]
self.attachments = [item.read() for item in self._report_items(result, '*attachment.*')]
@staticmethod
def _report_items(report_dir, glob):
for _file in os.listdir(report_dir):
if fnmatch.fnmatch(_file, glob):
with open(os.path.join(report_dir, _file)) as report_file:
yield report_file
def has_test_case(name, *matchers):
return has_property('test_cases',
has_item(
all_of(
any_of(
has_entry('fullName', ends_with(name)),
has_entry('name', ends_with(name))
),
*matchers
)
)
)