How to use _matching_keys method in PyHamcrest

Best Python code snippet using PyHamcrest_python

isdict_containing.py

Source:isdict_containing.py Github

copy

Full Screen

...23 description.append_text("a dictionary containing [").append_description_of(24 self.key_matcher25 ).append_text(": ").append_description_of(self.value_matcher).append_text("]")26 def describe_mismatch(self, item: Mapping[K, V], mismatch_description: Description) -> None:27 key_matches = self._matching_keys(item)28 if len(key_matches) == 1:29 key, value = key_matches.popitem()30 mismatch_description.append_text("value for ").append_description_of(key).append_text(31 " "32 )33 self.value_matcher.describe_mismatch(value, mismatch_description)34 else:35 super().describe_mismatch(item, mismatch_description)36 def describe_match(self, item: Mapping[K, V], match_description: Description) -> None:37 key_matches = self._matching_keys(item)38 if len(key_matches) == 1:39 key, value = key_matches.popitem()40 match_description.append_text("value for ").append_description_of(key).append_text(" ")41 self.value_matcher.describe_mismatch(value, match_description)42 else:43 super().describe_match(item, match_description)44 def _matching_keys(self, item):45 key_matches: MutableMapping[K, V] = {}46 if hasmethod(item, "items"):47 for key, value in item.items():48 if self.key_matcher.matches(key):49 key_matches[key] = value50 return key_matches51def has_entry(52 key_match: Union[K, Matcher[K]], value_match: Union[V, Matcher[V]]53) -> Matcher[Mapping[K, V]]:54 """Matches if dictionary contains key-value entry satisfying a given pair55 of matchers.56 :param key_match: The matcher to satisfy for the key, or an expected value57 for :py:func:`~hamcrest.core.core.isequal.equal_to` matching.58 :param value_match: The matcher to satisfy for the value, or an expected...

Full Screen

Full Screen

synonym.py

Source:synonym.py Github

copy

Full Screen

...18 and self._output not in data.keys()19 )20 def _apply(self, data):21 try:22 key = next(self._matching_keys(data))23 except StopIteration:24 pass25 else:26 data[self._output] = data[key]27 data.pop(key)28 finally:29 return data30 def _matching_keys(self, data):31 inputs = [inp.casefold() for inp in self._inputs]32 for input_pattern in inputs:33 for k in data.keys():34 if fnmatch(k, input_pattern):35 yield k36 @classmethod37 def create(cls, data):38 output = data["output"]39 inputs = data["inputs"]40 return SynonymAction(output, inputs)41 @classmethod42 def register(cls):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run PyHamcrest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful