How to use _dict_include method in assertpy

Best Python code snippet using assertpy_python

assertions.py

Source:assertions.py Github

copy

Full Screen

...1085 raise TypeError('%s <%s> does not have [] accessor' % (name, type(l).__name__))1086 def _dict_not_equal(self, val, other, ignore=None, include=None):1087 if ignore or include:1088 ignores = self._dict_ignore(ignore)1089 includes = self._dict_include(include)1090 # guarantee include keys are in val1091 if include:1092 missing = []1093 for i in includes:1094 if i not in val:1095 missing.append(i)1096 if missing:1097 self._err('Expected <%s> to include key%s %s, but did not include key%s %s.' % (1098 val,1099 '' if len(includes) == 1 else 's',1100 self._fmt_items(['.'.join([str(s) for s in i]) if type(i) is tuple else i for i in includes]),1101 '' if len(missing) == 1 else 's',1102 self._fmt_items(missing)))1103 if ignore and include:1104 k1 = set([k for k in val if k not in ignores and k in includes])1105 elif ignore:1106 k1 = set([k for k in val if k not in ignores])1107 else: # include1108 k1 = set([k for k in val if k in includes])1109 if ignore and include:1110 k2 = set([k for k in other if k not in ignores and k in includes])1111 elif ignore:1112 k2 = set([k for k in other if k not in ignores])1113 else: # include1114 k2 = set([k for k in other if k in includes])1115 if k1 != k2:1116 return True1117 else:1118 for k in k1:1119 if self._check_dict_like(val[k], check_values=False, return_as_bool=True) and self._check_dict_like(1120 other[k], check_values=False, return_as_bool=True):1121 return self._dict_not_equal(val[k], other[k],1122 ignore=[i[1:] for i in ignores if1123 type(i) is tuple and i[0] == k] if ignore else None,1124 include=[i[1:] for i in self._dict_ignore(include) if1125 type(i) is tuple and i[0] == k] if include else None)1126 elif val[k] != other[k]:1127 return True1128 return False1129 else:1130 return val != other1131 def _dict_ignore(self, ignore):1132 return [i[0] if type(i) is tuple and len(i) == 1 else i \1133 for i in (ignore if type(ignore) is list else [ignore])]1134 def _dict_include(self, include):1135 return [i[0] if type(i) is tuple else i \1136 for i in (include if type(include) is list else [include])]1137 def _dict_err(self, val, other, ignore=None, include=None):1138 def _dict_repr(d, other):1139 out = ''1140 ellip = False1141 for k, v in d.items():1142 if k not in other:1143 out += '%s%s: %s' % (', ' if len(out) > 0 else '', repr(k), repr(v))1144 elif v != other[k]:1145 out += '%s%s: %s' % (', ' if len(out) > 0 else '', repr(k),1146 _dict_repr(v, other[k]) if self._check_dict_like(v, check_values=False,1147 return_as_bool=True) and self._check_dict_like(1148 other[k], check_values=False, return_as_bool=True) else repr(v)...

Full Screen

Full Screen

helpers.py

Source:helpers.py Github

copy

Full Screen

...134 def _dict_not_equal(self, val, other, ignore=None, include=None):135 """Helper to compare dicts."""136 if ignore or include:137 ignores = self._dict_ignore(ignore)138 includes = self._dict_include(include)139 # guarantee include keys are in val140 if include:141 missing = []142 for i in includes:143 if i not in val:144 missing.append(i)145 if missing:146 return self.error('Expected <%s> to include key%s %s, but did not include key%s %s.' % (147 val,148 '' if len(includes) == 1 else 's',149 self._fmt_items(['.'.join([str(s) for s in i]) if type(i) is tuple else i for i in includes]),150 '' if len(missing) == 1 else 's',151 self._fmt_items(missing)))152 # calc val keys given ignores and includes153 if ignore and include:154 k1 = set([k for k in val if k not in ignores and k in includes])155 elif ignore:156 k1 = set([k for k in val if k not in ignores])157 else: # include158 k1 = set([k for k in val if k in includes])159 # calc other keys given ignores and includes160 if ignore and include:161 k2 = set([k for k in other if k not in ignores and k in includes])162 elif ignore:163 k2 = set([k for k in other if k not in ignores])164 else: # include165 k2 = set([k for k in other if k in includes])166 if k1 != k2:167 # different set of keys, so not equal168 return True169 else:170 for k in k1:171 if self._check_dict_like(val[k], check_values=False, return_as_bool=True) and \172 self._check_dict_like(other[k], check_values=False, return_as_bool=True):173 subdicts_not_equal = self._dict_not_equal(174 val[k],175 other[k],176 ignore=[i[1:] for i in ignores if type(i) is tuple and i[0] == k] if ignore else None,177 include=[i[1:] for i in self._dict_ignore(include) if type(i) is tuple and i[0] == k] if include else None)178 if subdicts_not_equal:179 # fast fail inside the loop since sub-dicts are not equal180 return True181 elif val[k] != other[k]:182 # fast fail inside the loop since values are not equal183 return True184 return False185 else:186 return val != other187 def _dict_ignore(self, ignore):188 """Helper to make list for given ignore kwarg values."""189 return [i[0] if type(i) is tuple and len(i) == 1 else i for i in (ignore if type(ignore) is list else [ignore])]190 def _dict_include(self, include):191 """Helper to make a list from given include kwarg values."""192 return [i[0] if type(i) is tuple else i for i in (include if type(include) is list else [include])]193 def _dict_err(self, val, other, ignore=None, include=None):194 """Helper to construct error message for dict comparison."""195 def _dict_repr(d, other):196 out = ''197 ellip = False198 for k, v in sorted(d.items()):199 if k not in other:200 out += '%s%s: %s' % (', ' if len(out) > 0 else '', repr(k), repr(v))201 elif v != other[k]:202 out += '%s%s: %s' % (203 ', ' if len(out) > 0 else '',204 repr(k),...

Full Screen

Full Screen

call.py

Source:call.py Github

copy

Full Screen

...114 for a1, a2 in zip(self, other):115 if not (a1 is a2 or a1 == a2):116 return False117 return True118def _dict_include(self, other):119 other_keys = set(other)120 if other_keys != other_keys & self.keys():121 return False122 for k in other_keys:123 a1, a2 = self[k], other[k]124 if not (a1 is a2 or a1 == a2):125 return False126 return True127class dispatch_by_args:128 def __init__(self, func=None, /):129 if func is not None:130 self.default = func131 self.alternates = []132 @staticmethod133 def default(*args, **kwds):134 raise NotImplementedError135 def register(self, fn=None, /, *args, **kwds):136 if fn is None:137 return lambda func, /: self.register(func, *args, **kwds)138 elif not callable(fn):139 return lambda func, /: self.register(func, fn, *args, **kwds)140 self.alternates.append(141 ((args, tuple(kwds.items())), fn))142 return fn143 def __call__(self, *args, **kwds):144 for (pargs, pkwds), fn in self.alternates:145 if _tuple_prefix(args, pargs) and _dict_include(kwds, pkwds):146 return fn(*args, **kwds)147 return self.default(*args, **kwds)148class expand_by_args(dispatch_by_args):149 def __call__(self, *args, **kwds):150 for (pargs, pkwds), fn in self.alternates:151 if _tuple_prefix(args, pargs) and _dict_include(kwds, pkwds):152 return fn(153 *args[len(pargs):],154 **{k: v for k, v in kwds.items() if k not in pkwds},155 )...

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