Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/allure_commons/mapping.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 from itertools import chain, islice | |
2 import attr | |
3 import re | |
4 from allure_commons.types import Severity, LabelType, LinkType | |
5 from allure_commons.types import ALLURE_UNIQUE_LABELS | |
6 from allure_commons.model2 import Label, Link | |
7 | |
8 | |
9 TAG_PREFIX = "allure" | |
10 | |
11 semi_sep = re.compile(r"allure[\.\w]+:") | |
12 eq_sep = re.compile(r"allure[\.\w]+=") | |
13 | |
14 | |
15 def allure_tag_sep(tag): | |
16 if semi_sep.search(tag): | |
17 return ":" | |
18 if eq_sep.search(tag): | |
19 return "=" | |
20 | |
21 | |
22 def __is(kind, t): | |
23 return kind in [v for k, v in t.__dict__.items() if not k.startswith('__')] | |
24 | |
25 | |
26 def parse_tag(tag, issue_pattern=None, link_pattern=None): | |
27 """ | |
28 >>> parse_tag("blocker") | |
29 Label(name='severity', value='blocker') | |
30 | |
31 >>> parse_tag("allure.issue:http://example.com/BUG-42") | |
32 Link(type='issue', url='http://example.com/BUG-42', name='http://example.com/BUG-42') | |
33 | |
34 >>> parse_tag("allure.link.home:http://qameta.io") | |
35 Link(type='link', url='http://qameta.io', name='home') | |
36 | |
37 >>> parse_tag("allure.suite:mapping") | |
38 Label(name='suite', value='mapping') | |
39 | |
40 >>> parse_tag("allure.suite:mapping") | |
41 Label(name='suite', value='mapping') | |
42 | |
43 >>> parse_tag("allure.label.owner:me") | |
44 Label(name='owner', value='me') | |
45 | |
46 >>> parse_tag("foo.label:1") | |
47 Label(name='tag', value='foo.label:1') | |
48 | |
49 >>> parse_tag("allure.foo:1") | |
50 Label(name='tag', value='allure.foo:1') | |
51 """ | |
52 sep = allure_tag_sep(tag) | |
53 schema, value = islice(chain(tag.split(sep, 1), [None]), 2) | |
54 prefix, kind, name = islice(chain(schema.split('.'), [None], [None]), 3) | |
55 | |
56 if tag in [severity for severity in Severity]: | |
57 return Label(name=LabelType.SEVERITY, value=tag) | |
58 | |
59 if prefix == TAG_PREFIX and value is not None: | |
60 | |
61 if __is(kind, LinkType): | |
62 if issue_pattern and kind == "issue" and not value.startswith("http"): | |
63 value = issue_pattern.format(value) | |
64 if link_pattern and kind == "link" and not value.startswith("http"): | |
65 value = link_pattern.format(value) | |
66 return Link(type=kind, name=name or value, url=value) | |
67 | |
68 if __is(kind, LabelType): | |
69 return Label(name=kind, value=value) | |
70 | |
71 if kind == "id": | |
72 return Label(name=LabelType.ID, value=value) | |
73 | |
74 if kind == "label" and name is not None: | |
75 return Label(name=name, value=value) | |
76 | |
77 return Label(name=LabelType.TAG, value=tag) | |
78 | |
79 | |
80 def labels_set(labels): | |
81 """ | |
82 >>> labels_set([Label(name=LabelType.SEVERITY, value=Severity.NORMAL), | |
83 ... Label(name=LabelType.SEVERITY, value=Severity.BLOCKER) | |
84 ... ]) | |
85 [Label(name='severity', value=<Severity.BLOCKER: 'blocker'>)] | |
86 | |
87 >>> labels_set([Label(name=LabelType.SEVERITY, value=Severity.NORMAL), | |
88 ... Label(name='severity', value='minor') | |
89 ... ]) | |
90 [Label(name='severity', value='minor')] | |
91 | |
92 >>> labels_set([Label(name=LabelType.EPIC, value="Epic"), | |
93 ... Label(name=LabelType.EPIC, value="Epic") | |
94 ... ]) | |
95 [Label(name='epic', value='Epic')] | |
96 | |
97 >>> labels_set([Label(name=LabelType.EPIC, value="Epic1"), | |
98 ... Label(name=LabelType.EPIC, value="Epic2") | |
99 ... ]) | |
100 [Label(name='epic', value='Epic1'), Label(name='epic', value='Epic2')] | |
101 """ | |
102 class Wl(object): | |
103 def __init__(self, label): | |
104 self.label = label | |
105 | |
106 def __repr__(self): | |
107 return "{name}{value}".format(**attr.asdict(self.label)) | |
108 | |
109 def __eq__(self, other): | |
110 if self.label.name in ALLURE_UNIQUE_LABELS: | |
111 return self.label.name == other.label.name | |
112 return repr(self) == repr(other) | |
113 | |
114 def __hash__(self): | |
115 if self.label.name in ALLURE_UNIQUE_LABELS: | |
116 return hash(self.label.name) | |
117 return hash(repr(self)) | |
118 | |
119 return sorted([wl.label for wl in set([Wl(label) for label in reversed(labels)])]) |