GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — allure-python/allure-python-commons-test/src/report.py at master · OmarFlow/allure-python Expand file tree/ Copy pathreport.pyMore file actions 159 lines (126 loc) · 4.3 KB / Copy pathreport.pyFile metadata and controls159 lines (126 loc) · 4.3 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 """ >>> from hamcrest import assert_that >>> class Report: ... 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, starts_with from hamcrest import only_contains from hamcrest.core.base_matcher import BaseMatcher class AllureReport: def __init__(self, result): self.result_dir = 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), encoding="utf-8") 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', starts_with(name)) ), *matchers ) ) ) class HasOnlyTetcases(BaseMatcher): def __init__(self, *matchers): self.matchers = matchers def _matches(self, item): return has_property('test_cases', only_contains(any_of(*self.matchers)) ).matches(item) def describe_to(self, description): pass def has_only_testcases(*matchers): return HasOnlyTetcases(*matchers) class ContainsExactly(BaseMatcher): def __init__(self, num, matcher): self.matcher = matcher self.count = 0 self.num = num def _matches(self, item): self.count = 0 for subitem in item: if self.matcher.matches(subitem): self.count += 1 if self.count == self.num: return True else: return False def describe_to(self, description): description.append_text(f'exactly {self.num} item(s) matching ').append_text(self.matcher) def has_only_n_test_cases(name, num, *matchers): return has_property('test_cases', ContainsExactly(num, all_of( any_of( has_entry('fullName', ends_with(name)), has_entry('name', ends_with(name)) ), *matchers ) ) ) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |