Best Python code snippet using yandex-tank
test_xml_node_list.py
Source:test_xml_node_list.py
...84 # Then85 assert not result86def test_get_item(sample_xml_text):87 # Given88 xml_doc = parse_xml(sample_xml_text)89 # When90 result = xml_doc.Header.To.Credential[1]91 # Then92 assert result.Identity.text() == 'admin@acme.com'93def test_get_item_out_of_bounds(sample_xml_text):94 # Given95 xml_doc = parse_xml(sample_xml_text)96 # When97 with pytest.raises(IndexError) as exc_info:98 _ = xml_doc.Header.From.Credential[99]99 # Then100 assert exc_info.value.args[0] == "list index out of range"101def test_len(sample_xml_text):102 # Given103 xml_doc = parse_xml(sample_xml_text)104 # When105 result = len(xml_doc.Header.To.Credential)106 # Then107 assert result == 2108def test_for_loop(sample_xml_text):109 # Given110 xml_doc = parse_xml(sample_xml_text)111 # When112 result = []113 for credential in xml_doc.Header.To.Credential:114 result.append(credential.Identity.text())115 # Then116 assert result == ['bigadmin@marketplace.org', 'admin@acme.com']117def test_list_comprehensions(sample_xml_text):118 # Given119 xml_doc = parse_xml(sample_xml_text)120 # When121 result = [x.Identity.text() for x in xml_doc.Header.Sender.Credential if x['domain'] == 'DUNS']122 # Then123 assert len(result) == 1124 assert result[0] == '942888711'125def test_filter(sample_xml_text):126 # Given127 credentials = parse_xml(sample_xml_text).Header.To.Credential128 # When129 result = credentials.filter(lambda n: n['domain'] == 'AribaNetworkUserId').first().Identity.text()130 # Then131 assert result == 'bigadmin@marketplace.org'132def test_filter_prop_none_found(sample_xml_text):133 # Given134 xml_doc = parse_xml(sample_xml_text)135 # When136 result = xml_doc.Header.To.Credential.filter_prop("domain", "not-there")137 # Then138 assert len(result) == 0139def test_filter_prop_some_found(sample_xml_text):140 # Given141 xml_doc = parse_xml(sample_xml_text)142 # When143 result = xml_doc.Header.To.Credential.filter_prop("domain", "AribaNetworkUserId")144 # Then145 assert len(result) == 2146def test_filter_text_none_found(sample_xml_text):147 # Given148 xml_doc = parse_xml(sample_xml_text)149 # When150 result = xml_doc.Request.ConfirmationRequest.ConfirmationHeader.Contact.PostalAddress.Street.filter_text('Suite 3')151 # Then152 assert len(result) == 0153def test_filter_text_some_found(sample_xml_text):154 # Given155 xml_doc = parse_xml(sample_xml_text)156 # When157 result = xml_doc.Request.ConfirmationRequest.ConfirmationHeader.Contact.PostalAddress.Street.filter_text('Suite 2')158 # Then159 assert len(result) == 1160def test_first_empty(sample_xml_text):161 # Given162 address = parse_xml(sample_xml_text).Request.ConfirmationRequest.ConfirmationHeader.Contact.PostalAddress163 # When164 result = address.Street.filter(lambda n: n.text() == 'Suite 3').first()165 # Then166 assert result is None167def test_first_many(sample_xml_text):168 # Given169 address = parse_xml(sample_xml_text).Request.ConfirmationRequest.ConfirmationHeader.Contact.PostalAddress170 # When171 result = address.Street.filter(lambda n: n.text() == 'Suite 2').first()172 # Then173 assert result is not None174def test_last_empty(sample_xml_text):175 # Given176 address = parse_xml(sample_xml_text).Request.ConfirmationRequest.ConfirmationHeader.Contact.PostalAddress177 # When178 result = address.Street.filter(lambda n: n.text() == 'Suite 3').last()179 # Then180 assert result is None181def test_last_many(sample_xml_text):182 # Given183 address = parse_xml(sample_xml_text).Request.ConfirmationRequest.ConfirmationHeader.Contact.PostalAddress184 # When185 result = address.Street.filter(lambda n: n.text() == 'Suite 2').last()186 # Then187 assert result is not None188def test_join_text(sample_xml_text):189 # Given190 address = parse_xml(sample_xml_text).Request.ConfirmationRequest.ConfirmationHeader.Contact.PostalAddress191 # When192 result = address.Street.join_text()193 # Then194 assert result == '432 Lake Drive, Suite 2'195def test_join_prop(sample_xml_text):196 # Given197 credentials = parse_xml(sample_xml_text).Header.To.Credential198 # When199 result = credentials.join_prop('domain')200 # Then201 assert result == 'AribaNetworkUserId, AribaNetworkUserId'202def test_repr_filled(sample_xml_text):203 # Given204 credentials = parse_xml(sample_xml_text).Header.To.Credential205 # When206 result = str(credentials)207 # Then208 assert result == 'XmlNodeList: [Credential]'209def test_repr_empty(sample_xml_text):210 # Given211 credentials = parse_xml(sample_xml_text).Header.To.Credential.filter_prop("domain", "not-here")212 # When213 result = str(credentials)214 # Then215 assert result == 'XmlNodeList: []'216def test_map_attr(sample_xml_text):217 # Given218 from_header = parse_xml(sample_xml_text).Header.To219 # When220 result = [i.text() for i in from_header.Credential.map_attr('Identity')]221 # Then222 assert result == [223 from_header.Credential[0].Identity.text(),224 from_header.Credential[1].Identity.text()225 ]226def test_map_prop(sample_xml_text):227 # Given228 from_header = parse_xml(sample_xml_text).Header.To229 # When230 result = from_header.Credential.map_prop('domain')231 # Then232 assert result == ['AribaNetworkUserId', 'AribaNetworkUserId']233def test_map_text(sample_xml_text):234 # Given235 credentials = parse_xml(sample_xml_text).Header.To.Credential236 cred_identities = XmlNodeList(credentials.map_attr('Identity'))237 # When238 result = cred_identities.map_text()239 # Then...
test_xml_node.py
Source:test_xml_node.py
...5def test_initialization(sample_xml_text):6 # Given7 raw_text = sample_xml_text8 # When9 result = parse_xml(raw_text)10 # Then11 assert result.raw_text is raw_text12 assert result.tag() == 'cXML'13def test_get_item_as_dict(sample_xml_text):14 # Given15 xml_doc = parse_xml(sample_xml_text)16 # When17 result = xml_doc['payloadID']18 # Then19 assert result == '1233444-2001@premier.workchairs.com'20def test_get_item_as_dict_case_insensitive(sample_xml_text):21 # Given22 xml_doc = parse_xml(sample_xml_text)23 # When24 result = xml_doc['PaYlOaDiD']25 # Then26 assert result == '1233444-2001@premier.workchairs.com'27def test_get_item_as_dict_unavailable(sample_xml_text):28 # Given29 xml_doc = parse_xml(sample_xml_text)30 # When31 with pytest.raises(KeyError) as exc_info:32 _ = xml_doc['not-there']33 # Then34 assert exc_info.value.args[0] == 'not-there'35def test_get_item_as_dict_function(sample_xml_text):36 # Given37 xml_doc = parse_xml(sample_xml_text)38 # When39 result = xml_doc.get('timestamp')40 # Then41 assert result == '2000-10-12T18:41:29-08:00'42def test_get_item_as_dict_function_with_default(sample_xml_text):43 # Give44 xml_doc = parse_xml(sample_xml_text)45 # When46 result = xml_doc.get('x-version', 'stuff')47 # Then48 assert result == 'stuff'49def test_contains_as_dict_found(sample_xml_text):50 # Give51 xml_doc = parse_xml(sample_xml_text)52 # When53 result = 'timestamp' in xml_doc54 # Then55 assert result56def test_contains_as_dict_found_case_insensitive(sample_xml_text):57 # Give58 xml_doc = parse_xml(sample_xml_text)59 # When60 result = 'tImEsTaMp' in xml_doc61 # Then62 assert result63def test_contains_as_dict_not_found(sample_xml_text):64 # Give65 xml_doc = parse_xml(sample_xml_text)66 # When67 result = 'version' in xml_doc68 # Then69 assert not result70def test_attribute(sample_xml_text):71 # Given72 xml_doc = parse_xml(sample_xml_text)73 # When74 result = xml_doc.Header.To75 # Then76 assert result.tag() == 'To'77def test_attribute_case_insensitive(sample_xml_text):78 # Given79 xml_doc = parse_xml(sample_xml_text)80 # When81 result = xml_doc.header.to82 # Then83 assert result.tag() == 'To'84def test_attribute_unavailable(sample_xml_text):85 # Given86 xml_doc = parse_xml(sample_xml_text)87 # When88 with pytest.raises(AttributeError) as exc_info:89 _ = xml_doc.not_there90 # Then91 assert exc_info.value.args[0] == "'cXML' object has no attribute 'not_there'"92def test_hasattr_with_available_attribute(sample_xml_text):93 # Given94 xml_doc = parse_xml(sample_xml_text)95 # When96 result = hasattr(xml_doc.Header, 'From')97 # Then98 assert result99def test_hasattr_with_unavailable_attribute(sample_xml_text):100 # Given101 xml_doc = parse_xml(sample_xml_text)102 # When103 result = hasattr(xml_doc.Header, 'Xfrom')104 # Then105 assert not result106def test_get_item_as_list(sample_xml_text):107 # Given108 xml_doc = parse_xml(sample_xml_text)109 # When110 result = xml_doc.Header.Sender.UserAgent[0]111 # Then112 assert result.tag() == 'UserAgent'113def test_get_item_as_list_out_of_bounds_root(sample_xml_text):114 # Given115 xml_doc = parse_xml(sample_xml_text)116 # When117 with pytest.raises(IndexError) as exc_info:118 _ = xml_doc.Header.Sender.UserAgent[1]119 # Then120 assert exc_info.value.args[0] == "list index out of range"121def test_len(sample_xml_text):122 # Given123 xml_doc = parse_xml(sample_xml_text)124 # When125 result = len(xml_doc)126 # Then127 assert result == 1128def test_repr(sample_xml_text):129 # Given130 xml_doc = parse_xml(sample_xml_text)131 # When132 result = str(xml_doc.Header.From.Credential[0])133 # Then134 assert result == 'XmlNode: Credential'135def test_repr_non_xml_node_entries(sample_xml_text):136 # Given137 sut = XmlNodeList([1, 2, 3])138 # When139 result = str(sut)140 # Then141 assert result == '[1, 2, 3]'142def test_dir_shows_attributes(sample_xml_text):143 # Given144 xml_doc = parse_xml(sample_xml_text)145 # When146 result = dir(xml_doc.Header)147 # Then148 assert set(result) == {'From', 'To', 'Sender'}149def test_map(sample_xml_text):150 # Given151 credentials = parse_xml(sample_xml_text).Header.To.Credential152 # When153 result = credentials.map(lambda n: n.Identity.text())154 # Then155 assert result == ['bigadmin@marketplace.org', 'admin@acme.com']156def test_returns_blank_if_empty_element(sample_xml_text):157 # Given158 conf_header = parse_xml(sample_xml_text).Request.ConfirmationRequest.ConfirmationHeader159 # When160 result = conf_header.Notes.text()161 # Then...
generate_description.py
Source:generate_description.py
...8 table.style = "TableGrid"9 cells = table.add_row().cells10 cells[0].paragraphs[0].add_run("Type de document\n").bold = True11 cells[1].text = "Project Log Document"12 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))13 cells[1]._tc.get_or_add_tcPr().append(parse_xml(odd))14 cells = table.add_row().cells15 cells[0].paragraphs[0].add_run("Date\n").bold = True16 cells[1].text = date17 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))18 cells[1]._tc.get_or_add_tcPr().append(parse_xml(even))19 cells = table.add_row().cells20 cells[0].paragraphs[0].add_run("Responsable du groupe\n").bold = True21 cells[1].text = "Hugo Frugier"22 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))23 cells[1]._tc.get_or_add_tcPr().append(parse_xml(odd))24 cells = table.add_row().cells25 cells[0].paragraphs[0].add_run("Auteur\n").bold = True26 cells[1].text = author27 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))28 cells[1]._tc.get_or_add_tcPr().append(parse_xml(even))29 cells = table.add_row().cells30 cells[0].paragraphs[0].add_run("Groupe\n").bold = True31 cells[1].text = "Hugo Frugier, Alexandre Tahery, Clément Chanal, Thomas Bouvier, Paul Gaston, Alexis Auriac, Alexandre Lefèvre"32 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))33 cells[1]._tc.get_or_add_tcPr().append(parse_xml(odd))34 cells = table.add_row().cells35 cells[0].paragraphs[0].add_run("Responsable de la relecture\n").bold = True36 cells[1].text = "Thomas Bouvier"37 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))38 cells[1]._tc.get_or_add_tcPr().append(parse_xml(even))39 cells = table.add_row().cells40 cells[0].paragraphs[0].add_run("Mèl\n").bold = True41 cells[1].text = "mediwatch_2022@labeip.epitech.eu"42 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))43 cells[1]._tc.get_or_add_tcPr().append(parse_xml(odd))44 cells = table.add_row().cells45 cells[0].paragraphs[0].add_run("Sujet\n").bold = True46 cells[1].text = "Project Log Document du projet Mediwatch"47 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))48 cells[1]._tc.get_or_add_tcPr().append(parse_xml(even))...
generate_advancements.py
Source:generate_advancements.py
...16 table = document.add_table(0, 5)17 table.style = "TableGrid"18 cells = table.add_row().cells19 cells[0].paragraphs[0].add_run("Date").bold = True20 cells[0]._tc.get_or_add_tcPr().append(parse_xml(title))21 cells[1].paragraphs[0].add_run("Version").bold = True22 cells[1]._tc.get_or_add_tcPr().append(parse_xml(title))23 cells[2].paragraphs[0].add_run("Auteur").bold = True24 cells[2]._tc.get_or_add_tcPr().append(parse_xml(title))25 cells[3].paragraphs[0].add_run("Section").bold = True26 cells[3]._tc.get_or_add_tcPr().append(parse_xml(title))27 cells[4].paragraphs[0].add_run("Commentaire").bold = True28 cells[4]._tc.get_or_add_tcPr().append(parse_xml(title))29 for i in range(len(advancements)):30 cells = table.add_row().cells31 cells[0].paragraphs[0].text = advancements[i]["date"]32 cells[0]._tc.get_or_add_tcPr().append(parse_xml(odd if i % 2 == 0 else even))33 cells[1].paragraphs[0].text = advancements[i]["version"]34 cells[1]._tc.get_or_add_tcPr().append(parse_xml(odd if i % 2 == 0 else even))35 cells[2].paragraphs[0].text = advancements[i]["auteur"]36 cells[2]._tc.get_or_add_tcPr().append(parse_xml(odd if i % 2 == 0 else even))37 cells[3].paragraphs[0].text = advancements[i]["section"]38 cells[3]._tc.get_or_add_tcPr().append(parse_xml(odd if i % 2 == 0 else even))39 cells[4].paragraphs[0].text = advancements[i]["commentaire"]40 cells[4]._tc.get_or_add_tcPr().append(parse_xml(odd if i % 2 == 0 else even))41 document.add_page_break()...
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!!