How to use safe_format_repr method in Sure

Best Python code snippet using sure_python

core.py

Source:core.py Github

copy

Full Screen

...179 X = list(Y)180 c = self.get_context()181 if self.is_complex(X) and type(X) is type(Y):182 return self.compare_complex_stuff(X, Y)183 def safe_format_repr(string):184 "Escape '{' and '}' in string for use with str.format()"185 if not isinstance(string, (string_types, binary_type)):186 return string187 orig_str_type = type(string)188 if isinstance(string, binary_type):189 safe_repr = string.replace(b'{', b'{{').replace(b'}', b'}}')190 else:191 safe_repr = string.replace('{', '{{').replace('}', '}}')192 # NOTE: str.replace() automatically converted the 'string' to 'unicode' in Python 2193 return orig_str_type(safe_repr)194 # get safe representation for X and Y195 safe_X, safe_Y = safe_format_repr(X), safe_format_repr(Y)196 # maintaining backwards compatibility between error messages197 kwargs = {}198 if self.is_simple(X) and self.is_simple(Y):199 kwargs['msg_format'] = 'X{{0}} is {0!r} whereas Y{{1}} is {1!r}'.format(safe_X, safe_Y)200 elif type(X) is not type(Y):201 kwargs['msg_format'] = 'X{{0}} is a {0} and Y{{1}} is a {1} instead'.format(202 type(X).__name__, type(Y).__name__)203 exp = self.compare_generic(X, Y, **kwargs)204 if isinstance(exp, DeepExplanation):205 original_X, original_Y = c.parent.operands206 raise exp.as_assertion(original_X, original_Y)207 return exp208 def explanation(self):209 return self._explanation...

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