How to use nested_match method in refurb

Best Python code snippet using refurb_python

base.py

Source:base.py Github

copy

Full Screen

1# Copyright 2011-2013 Colin Scott2# Copyright 2011-2013 Andreas Wundsam3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at:7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15import abc16class Fingerprint(object):17 __metaclass__ = abc.ABCMeta18 # This should really be a protected constructor19 def __init__(self, field2value):20 # Make sure to convert arrays to tuples, since we need __hash__()21 for field, value in field2value.iteritems():22 if type(value) == list:23 field2value[field] = tuple(value)24 self._field2value = field2value25 def to_dict(self):26 flattened = {}27 for field, value in self._field2value.iteritems():28 if 'to_dict' in dir(value):29 flattened[field] = value.to_dict()30 else:31 flattened[field] = value32 return flattened33 def check_match(self, match):34 ''' Return whether this fingerprint matches the pattern in match.35 match must be of the form (key, value, nested_match), where key and value36 are members of self._field2value to match on, and nested_match is either37 None or a tuple (nest_key, match pattern) to match on recursively.38 This method differs from __eq__ in that it will return True if a39 subset (specified in match) of fields are equal, whereas __eq__ requires40 every field to match.41 # TODO(cs): an arguably cleaner way to implement this would be to support42 # wildcarded fields in __eq__.43 '''44 (key, value, nested_match) = match45 if key not in self._field2value:46 return False47 if value != self._field2value[key]:48 return False49 if nested_match is None:50 return True51 (nested_key, match) = nested_match52 nested_fingerprint = self._field2value[nested_key]53 if nested_fingerprint == ():54 return True55 return nested_fingerprint.check_match(match)56 @abc.abstractmethod57 def __hash__(self):58 pass59 @abc.abstractmethod60 def __eq__(self, other):61 pass62 def __getitem__(self, key):63 return self._field2value[key]64 def __ne__(self, other):65 # NOTE: __ne__ in python does *NOT* by default delegate to eq66 return not self.__eq__(other)67 def __str__(self):68 return str(self._field2value)69 def __repr__(self):...

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 refurb 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