Best Python code snippet using lemoncheesecake
_capitains_cts.py
Source:_capitains_cts.py
...721 child = self.child.export(output=output)722 label = ""723 if self.name is not None:724 label = self.name725 return make_xml_node(726 get_graph(), RDF_NAMESPACES.CTS.citation, attributes={727 "xpath": re.sub(Citation.escape, "'", self.xpath),728 "scope": re.sub(Citation.escape, "'", self.scope),729 "label": label730 }, innerXML=child, complete=True731 )732 elif output == Mimetypes.XML.TEI:733 if self.refsDecl is None:734 return ""735 label = ""736 if self.name is not None:737 label = self.name738 return \739 "<tei:cRefPattern n=\"{label}\" matchPattern=\"{regexp}\" replacementPattern=\"#xpath({refsDecl})\">" \...
inventory.py
Source:inventory.py
...118 strings = []119 for pred in self.CTS_PROPERTIES:120 for obj in self.metadata.get(pred):121 strings.append(122 make_xml_node(123 self.graph, pred, attributes={"xml:lang": obj.language}, text=str(obj), complete=True124 )125 )126 if output == Mimetypes.XML.CapiTainS.CTS:127 strings.append(make_xml_node(self.graph, RDF_NAMESPACES.CAPITAINS.term("structured-metadata")))128 strings.append(129 self.metadata.export(130 Mimetypes.XML.CapiTainS.CTS,131 exclude=[RDF_NAMESPACES.CTS, RDF_NAMESPACES.DTS, RDF])132 )133 strings.append(make_xml_node(self.graph, RDF_NAMESPACES.CAPITAINS.term("structured-metadata"), close=True))134 if members is None:135 members = self.members136 for obj in members:137 strings.append(obj.export(output, namespaces=False))138 strings.append(make_xml_node(self.graph, TYPE_URI, close=True))139 if namespaces is True:140 attrs.update(self.__namespaces_header__(cpt=(output == Mimetypes.XML.CapiTainS.CTS)))141 strings = [make_xml_node(self.graph, TYPE_URI, close=False, attributes=attrs)] + strings142 return lines.join(strings)143 def __export__(self, output=None, domain=""):144 if output == Mimetypes.PYTHON.ETREE:145 return xmlparser(self.export(output=Mimetypes.XML.CTS))146class CtsTextMetadata(ResourceCollection, PrototypeCtsCollection):147 """ Represents a CTS CtsTextMetadata148 :param urn: Identifier of the CtsTextMetadata149 :type urn: str150 :param parent: Item parents of the current collection151 :type parent: [PrototypeCtsCollection]152 :ivar urn: URN Identifier153 :type urn: URN154 """155 DC_TITLE_KEY = RDF_NAMESPACES.CTS.term("label")156 TYPE_URI = RDF_NAMESPACES.CTS.term("text")157 MODEL_URI = URIRef(RDF_NAMESPACES.DTS.resource)158 EXPORT_TO = [Mimetypes.XML.CTS, Mimetypes.XML.CapiTainS.CTS]159 CTS_PROPERTIES = [RDF_NAMESPACES.CTS.label, RDF_NAMESPACES.CTS.description]160 CTS_LINKS = [RDF_NAMESPACES.CTS.about]161 SUBTYPE = "unknown"162 def __init__(self, urn="", parent=None, lang=None):163 self.__subtype__ = self.SUBTYPE164 super(CtsTextMetadata, self).__init__(identifier=str(urn))165 self.resource = None166 self.citation = None167 self.__urn__ = URN(urn)168 self.docname = None169 self.validate = None170 if lang is not None:171 self.lang = lang172 if parent is not None:173 self.parent = parent174 if lang is None:175 self.lang = self.parent.lang176 @property177 def subtype(self):178 """ Subtype of the object179 :return: string representation of subtype180 """181 return self.__subtype__182 @property183 def readable(self):184 return True185 @property186 def members(self):187 """ Children of the collection's item188 .. warning:: CapitainsCtsText has no children189 :rtype: list190 """191 return []192 @property193 def descendants(self):194 """ Descendants of the collection's item195 .. warning:: CapitainsCtsText has no Descendants196 :rtype: list197 """198 return []199 def translations(self, key=None):200 """ Get translations in given language201 :param key: Language ISO Code to filter on202 :return:203 """204 return self.parent.get_translation_in(key)205 def editions(self):206 """ Get all editions of the texts207 :return: List of editions208 :rtype: [CtsTextMetadata]209 """210 return [211 item212 for urn, item in self.parent.children.items()213 if isinstance(item, CtsEditionMetadata)214 ]215 def __export__(self, output=None, domain="", namespaces=True, lines="\n"):216 """ Create a {output} version of the CapitainsCtsText217 :param output: Format to be chosen218 :type output: basestring219 :param domain: Domain to prefix IDs when necessary220 :type domain: str221 :returns: Desired output formatted resource222 """223 if output == Mimetypes.XML.CTS or output == Mimetypes.XML.CapiTainS.CTS:224 attrs = {"urn": self.id, "xml:lang": self.lang}225 if self.parent is not None and self.parent.id:226 attrs["workUrn"] = self.parent.id227 if namespaces is True:228 attrs.update(self.__namespaces_header__(cpt=(output==Mimetypes.XML.CapiTainS.CTS)))229 strings = [make_xml_node(self.graph, self.TYPE_URI, close=False, attributes=attrs)]230 # additional = [make_xml_node(self.graph, RDF_NAMESPACES.CTS.extra)]231 for pred in self.CTS_PROPERTIES:232 for obj in self.metadata.get(pred):233 strings.append(234 make_xml_node(235 self.graph, pred, attributes={"xml:lang": obj.language}, text=str(obj), complete=True236 )237 )238 for pred in self.CTS_LINKS:239 # For each predicate in CTS_LINKS240 for obj in self.metadata.get(pred):241 # For each item in the graph connected to the current item metadata as object through the predicate "pred"242 strings.append(243 make_xml_node(244 self.graph, pred, attributes={"urn": str(obj)}, complete=True245 )246 # <pref urn="obj.language"/>247 )248 # Citation !249 if self.citation is not None:250 strings.append(251 # Online252 make_xml_node(253 self.graph, RDF_NAMESPACES.CTS.term("online"), complete=True,254 # XmlCtsCitation Mapping255 innerXML=make_xml_node(256 self.graph, RDF_NAMESPACES.CTS.term("citationMapping"), complete=True,257 innerXML=self.citation.export(Mimetypes.XML.CTS)258 )259 )260 )261 if output == Mimetypes.XML.CapiTainS.CTS:262 strings.append(make_xml_node(self.graph, RDF_NAMESPACES.CAPITAINS.term("structured-metadata")))263 strings.append(264 self.metadata.export(265 Mimetypes.XML.CapiTainS.CTS,266 exclude=[RDF_NAMESPACES.CTS, RDF_NAMESPACES.DTS, RDF])267 )268 strings.append(269 make_xml_node(self.graph, RDF_NAMESPACES.CAPITAINS.term("structured-metadata"), close=True)270 )271 strings.append(make_xml_node(self.graph, self.TYPE_URI, close=True))272 return lines.join(strings)273 def get_creator(self, lang=None):274 """ Get the DC Creator literal value275 :param lang: Language to retrieve276 :return: Creator string representation277 :rtype: Literal278 """279 return self.parent.parent.metadata.get_label(lang=lang)280 def get_title(self, lang=None):281 """ Get the DC Title of the object282 :param lang: Lang to retrieve283 :return: Title string representation284 :rtype: Literal285 """...
xml.py
Source:xml.py
...32 elem.tail = i33 else:34 if level and (not elem.tail or not elem.tail.strip()):35 elem.tail = i36def make_xml_node(name, *args):37 node = E(name)38 i = 039 while i < len(args):40 attr_name, attr_value = args[i], args[i+1]41 node.attrib[attr_name] = attr_value42 i += 243 return node44def make_xml_child(parent, name, *args):45 child = make_xml_node(name, *args)46 parent.append(child)47 return child48def _serialize_time(value):49 return format_time_as_iso8601(value)50def _serialize_bool(value):51 return "true" if value else "false"52def _serialize_steps(steps, xml_result):53 for step in steps:54 xml_step = make_xml_child(55 xml_result, "step",56 "description", step.description,57 "start-time", _serialize_time(step.start_time)58 )59 if step.end_time is not None:60 xml_step.attrib["end-time"] = _serialize_time(step.end_time)61 for log in step.get_logs():62 if isinstance(log, Log):63 xml_log = make_xml_child(64 xml_step, "log",65 "level", log.level,66 "time", _serialize_time(log.time)67 )68 xml_log.text = log.message69 elif isinstance(log, Attachment):70 xml_attachment = make_xml_child(71 xml_step, "attachment",72 "description", log.description,73 "as-image", _serialize_bool(log.as_image),74 "time", _serialize_time(log.time)75 )76 xml_attachment.text = log.filename77 elif isinstance(log, Url):78 xml_url = make_xml_child(79 xml_step, "url",80 "description", log.description,81 "time", _serialize_time(log.time)82 )83 xml_url.text = log.url84 else: # TestCheck85 xml_check = make_xml_child(86 xml_step, "check",87 "description", log.description,88 "is-successful", _serialize_bool(log.is_successful),89 "time", _serialize_time(log.time)90 )91 xml_check.text = log.details92def _serialize_result(result, xml_result):93 if result.status:94 xml_result.attrib["status"] = result.status95 if result.status_details:96 xml_result.attrib["status-details"] = result.status_details97 xml_result.attrib["start-time"] = _serialize_time(result.start_time)98 if result.end_time is not None:99 xml_result.attrib["end-time"] = _serialize_time(result.end_time)100 _serialize_steps(result.get_steps(), xml_result)101def _serialize_node_metadata(obj, xml_node):102 xml_node.attrib["name"] = obj.name103 xml_node.attrib["description"] = obj.description104 for tag in obj.tags:105 xml_tag = make_xml_child(xml_node, "tag")106 xml_tag.text = tag107 for name, value in obj.properties.items():108 xml_property = make_xml_child(xml_node, "property", "name", name)109 xml_property.text = value110 for link in obj.links:111 xml_link = make_xml_child(xml_node, "link")112 if link[1]:113 xml_link.attrib["name"] = link[1]114 xml_link.text = link[0]115def _serialize_test_result(test):116 xml_test = make_xml_node("test")117 _serialize_node_metadata(test, xml_test)118 _serialize_result(test, xml_test)119 return xml_test120def _serialize_suite_result(suite):121 xml_suite = make_xml_node("suite")122 _serialize_node_metadata(suite, xml_suite)123 xml_suite.attrib["start-time"] = _serialize_time(suite.start_time)124 if suite.end_time is not None:125 xml_suite.attrib["end-time"] = _serialize_time(suite.end_time)126 # before suite127 if suite.suite_setup:128 _serialize_result(suite.suite_setup, make_xml_child(xml_suite, "suite-setup"))129 # tests130 xml_suite.extend(map(_serialize_test_result, suite.get_tests()))131 # sub suites132 xml_suite.extend(map(_serialize_suite_result, suite.get_suites()))133 # after suite134 if suite.suite_teardown:135 _serialize_result(suite.suite_teardown, make_xml_child(xml_suite, "suite-teardown"))...
metadata.py
Source:metadata.py
...185 if hasattr(obj, "language") and obj.language is not None:186 kwargs["xml:lang"] = obj.language187 if hasattr(obj, "datatype") and obj.datatype is not None:188 kwargs["rdf:type"] = obj.datatype189 strings.append(make_xml_node(graph, pred, text=obj, attributes=kwargs, complete=True))190 del graph191 return "\n".join(strings)192 @staticmethod193 def getOr(subject, predicate, *args, **kwargs):194 """ Retrieve a metadata node or generate a new one195 :param subject: Subject to which the metadata node should be connected196 :param predicate: Predicate by which the metadata node should be connected197 :return: Metadata for given node198 :rtype: Metadata199 """200 if (subject, predicate, None) in get_graph():201 return Metadata(node=get_graph().objects(subject, predicate).__next__())...
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!!