Best Python code snippet using localstack_python
equality.py
Source:equality.py
...14 return (round(mantissa1, places) == round(mantissa2, places) and15 exp1 == exp2)16# Extracts the xmlns from an lxml element tag17xmlns_re = re.compile(r'\{(.*)\}(.*)')18def strip_xmlns(tag_name):19 return xmlns_re.match(tag_name).group(2)20def xml_equal(xml1, xml2, indent='', annotations=False):21 if xml1.tag != xml2.tag:22 logger.error("{}Tag '{}' doesn't equal '{}'"23 .format(indent, xml1.tag, xml2.tag))24 return False25 if xml1.attrib != xml2.attrib:26 logger.error("{}Attributes '{}' doesn't equal '{}'"27 .format(indent, xml1.attrib, xml2.attrib))28 return False29 text1 = xml1.text if xml1.text is not None else ''30 text2 = xml2.text if xml2.text is not None else ''31 if text1.strip() != text2.strip():32 logger.error("{}Body '{}' doesn't equal '{}'"33 .format(indent, text1, text2))34 return False35 tail1 = xml1.tail if xml1.tail is not None else ''36 tail2 = xml2.tail if xml2.tail is not None else ''37 if tail1.strip() != tail2.strip():38 if text1.strip() != text2.strip():39 logger.error("{}Body '{}' doesn't equal '{}'"40 .format(indent, tail1, tail2))41 return False42 children1 = [c for c in xml1.getchildren()43 if not c.tag.endswith('Annotations') or annotations]44 children2 = [c for c in xml2.getchildren()45 if not c.tag.endswith('Annotations') or annotations]46 if len(children1) != len(children2):47 logger.error("{}Number of children {} doesn't equal {}:\n{}\n{}"48 .format(indent, len(children1), len(children2),49 ', '.join(50 '{}:{}'.format(strip_xmlns(c.tag),51 c.attrib.get('name', None))52 for c in children1),53 ', '.join(54 '{}:{}'.format(strip_xmlns(c.tag),55 c.attrib.get('name', None))56 for c in children2)))57 return False58 return all(xml_equal(c1, c2, indent=indent + ' ')...
xml.py
Source:xml.py
...7 return "".join([obj_to_xml(o) for o in obj])8 if isinstance(obj, dict):9 return "".join(["<{k}>{v}</{k}>".format(k=k, v=obj_to_xml(v)) for (k, v) in obj.items()])10 return str(obj)11def strip_xmlns(obj: Any) -> Any:12 """Strip xmlns attributes from a dict returned by xmltodict.parse."""13 if isinstance(obj, list):14 return [strip_xmlns(item) for item in obj]15 if isinstance(obj, dict):16 # Remove xmlns attribute.17 obj.pop("@xmlns", None)18 if len(obj) == 1 and "#text" in obj:19 # If the only remaining key is the #text key, elide the dict20 # entirely, to match the structure that xmltodict.parse would have21 # returned if the xmlns namespace hadn't been present.22 return obj["#text"]23 return {k: strip_xmlns(v) for k, v in obj.items()}...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!