forked from allure-framework/allure-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlookup.py
More file actions
26 lines (20 loc) · 736 Bytes
/
lookup.py
File metadata and controls
26 lines (20 loc) · 736 Bytes
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
from hamcrest.core.base_matcher import BaseMatcher
from hamcrest import all_of
class MapsTo(BaseMatcher):
def __init__(self, mapping, *value_matchers):
self.__mapping = mapping
self.__value_matcher = all_of(*value_matchers)
def _matches(self, item):
if item not in self.__mapping:
return False
return self.__value_matcher.matches(
self.__mapping[item]
)
def describe_to(self, description):
keys = list(self.__mapping)
description.append_text(
f"one of keys {keys!r} mapping to "
)
self.__value_matcher.describe_to(description)
def maps_to(mapping, *value_matchers):
return MapsTo(mapping, *value_matchers)