Best Python code snippet using tempest_python
tex.py
Source:tex.py
...5import glob6from xml.dom import minidom789def create_tag(name: str = None, text: str = None, attributes: dict = None, *, cdata: bool = False):10 #ФÑнкÑÐ¸Ñ ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ ÑÑга XML11 doc = minidom.Document()1213 if name is None:14 return doc1516 tag = doc.createElement(name)1718 if text is not None:19 if cdata is True:20 tag.appendChild(doc.createCDATASection(text))21 else:22 tag.appendChild(doc.createTextNode(text))2324 if attributes is not None:25 for k, v in attributes.items():26 tag.setAttribute(k, str(v))2728 return tag29303132#ÐоиÑк Ñайла msm_jrnn*.tex Ð´Ð»Ñ Ð¾Ð¿ÑÐµÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð½Ð¾Ð¼ÐµÑа жÑÑнала33filenames = glob.glob("*")34filenames_to_string = ' '.join(filenames)35number_journal = re.findall(r'msm_jrn_n([^.tex]*)', filenames_to_string, re.DOTALL)36with open('msm_jrn_n' + number_journal[0] + '.tex') as jrn: tex = jrn.read()37with open('msm_jrn_n' + number_journal[0] + '.aux') as jrn: aux = jrn.read()383940dell_comments = re.sub(r'[^\\]?%.*\n', '', tex)41dell_comments = dell_comments.replace('~', ' ')42dell_comments = dell_comments.replace('<<', '"')43dell_comments = dell_comments.replace('>>', '"')44dell_comments = dell_comments.replace('<', '\\lt')45dell_comments = dell_comments.replace('>', '\\gt')46dell_comments = dell_comments.replace('---', '-')47dell_comments = dell_comments.replace('\\_', '_')4849doc = create_tag()50515253# JOURNAL #54root = create_tag('journal')55doc.appendChild(root)56# JOURNAL #575859# OPERCARD #60opercard = create_tag('operCard')6162operator = create_tag('operator', 'Articulus_1911')63pid = create_tag('pid', '0')64date = create_tag('date', '0')6566filenames_authors = re.findall(r'\\Input{([^}]*)}', dell_comments, re.DOTALL)67filenames_authors.remove('authors')68filenames_authors.remove('title2')69cntArticle = create_tag('cntArticle', str(len(filenames_authors)))7071cntNode = create_tag('cntNode', '0')72cs = create_tag('cs', '0')73opercard.appendChild(operator.cloneNode(True))74opercard.appendChild(pid.cloneNode(True))75opercard.appendChild(date.cloneNode(True))76opercard.appendChild(cntArticle.cloneNode(True))77opercard.appendChild(cntNode.cloneNode(True))78opercard.appendChild(cs.cloneNode(True))7980root.appendChild(opercard)81# OPERCARD #828384# JOURNAL #85titleid = create_tag('titleid', '32419')86issn = create_tag('issn', '2222-8772')87eissn = create_tag('eissn', '2222-8799')8889root.appendChild(titleid)90root.appendChild(issn)91root.appendChild(eissn)92# JOURNAL #939495# JOURNALINFO #96atr = {'lang': 'RUS'}97journalInfo = create_tag('journalInfo', None, atr)98journalInfo.setAttribute('lang', 'RUS')99title = create_tag('title', 'ÐаÑемаÑиÑеÑкие ÑÑÑÑкÑÑÑÑ Ð¸ моделиÑование')100journalInfo.appendChild(title.cloneNode(True))101root.appendChild(journalInfo)102# JOURNALINFO #103104num = re.findall(r'\\num{([^}]*)}', dell_comments, re.DOTALL)105dateUn = re.findall(r'\\yearpub{([^}]*)}', dell_comments, re.DOTALL)106altNum = re.findall(r'\\volume{([^}]*)}', dell_comments, re.DOTALL)107pagess = re.findall(r'\\newlabel{endofsborn}{{[^}]*}{([^}]*)}}', aux, re.DOTALL)108109# ISSUE #110issue = create_tag('issue')111112volume = create_tag('volume', '')113number = create_tag('number', num[0])114altNumber = create_tag('altNumber', altNum[0])115part = create_tag('part', '')116dateUni = create_tag('dateUni', dateUn[0])117issTitle = create_tag('issTitle', '')118pages = create_tag('pages', ('1-'+pagess[0]))119120121# ISSUE/ARTICLES #122articles = create_tag('articles')123124125def create_article(filename):126 with open(filename) as f: data = f.read()127 dellcomment = re.sub(r'[^\\]?%.*\n', '', data, re.DOTALL)128 dellcomment = dellcomment.replace('~', ' ')129 dellcomment = dellcomment.replace('<<', '"')130 dellcomment = dellcomment.replace('>>', '"')131 dellcomment = dellcomment.replace('<', '\\lt')132 dellcomment = dellcomment.replace('>', '\\gt')133 dellcomment = dellcomment.replace('---', '-')134 dellcomment = dellcomment.replace('--', '-')135 dellcomment = dellcomment.replace('\\_', '_')136137138 # ISSUE/ARTILES/SECTION #139 langRU = {'lang': 'RUS'}140 langEN = {'lang': 'ENG'}141 secTitle_list = re.findall(r'\\(?:addcontentsline{toc}{sect}){([^{}]*)}\s*$', dell_comments, re.MULTILINE)142 secTitle_listEN = re.findall(r'\\addcontentsline{toc}{sectEng}{([^}]*)}', dell_comments, re.DOTALL)143 secTitle_listRUEN_auth = re.findall(r'\\(?:addcontentsline{toc}{sect}|addcontentsline{toc}{sectEng}|Input){([^{}]*)}\s*$', dell_comments, re.MULTILINE)144 k = 0145 while k < len(secTitle_list):146147 start_secTitle = dell_comments.find(secTitle_list[k])148 if k + 1 == len(secTitle_list):149 end_secTitle = dell_comments.find(secTitle_listRUEN_auth[-1])150 else:151 end_secTitle = dell_comments.find(secTitle_list[k + 1])152153 section_authors = re.findall(r'\\(?:addcontentsline{toc}{sect}|Input){([^{}]*)}\s*$', dell_comments[start_secTitle:end_secTitle], re.MULTILINE)154 if section_authors.count(filename[:-4]) > 0:155 section = create_tag('section')156 secTitleRU = create_tag('secTitle', secTitle_list[k], langRU)157 section.appendChild(secTitleRU)158 secTitleEN = create_tag('secTitle', secTitle_listEN[k], langEN)159 section.appendChild(secTitleEN)160 articles.appendChild(section.cloneNode(True))161 k = k + 1162 # ISSUE/ARTICLES/SECTION #163164 # ISSUE/ARTICLES/ARTICLE #165 article = create_tag('article')166167168 # ISSUE/ARTICLES/ARTICLE/PAGES #169170 begNameAuthor = r"\\@writefile{filepages}{\\contentsline {" + filename + "}{startpage}{([^}]*)}}"171 pagesArtStart = re.findall(begNameAuthor, aux, re.DOTALL)172 endNameAuthor = r"\\@writefile{filepages}{\\contentsline {" + filename + "}{endpage}{([^}]*)}}"173 pagesArtEnd = re.findall(endNameAuthor, aux, re.DOTALL)174 pages_article = create_tag('pages', pagesArtStart[0] + '-' + pagesArtEnd[0])175176 # ISSUE/ARTICLES/ARTICLE/PAGES #177178 artType = create_tag('artType', 'RAR')179180 # ISSUE/ARTICLES/ARTICLE/AUTHORS #181 authors = create_tag('authors')182183 # ISSUE/ARTICLE/ARTICLE/AUTHORS/AUTHOR #184 authors_full = re.findall(r'\\author{([^}]*)}{[^}]*}{([^}]*)}', dellcomment, re.DOTALL)185 authors_full_en = re.findall(r'\\authorEng\[[^\]]*\]{[^}]*}{[^}]*}{[^}]*}', dellcomment, re.DOTALL)186 authors_name_and_surname_ru = re.findall(r'\\author{([^}]*)}{[^}]*}{[^}]*}', dellcomment, re.DOTALL)187 authors_email = re.findall(r'\\author{[^}]*}{[^}]*}{([^}]*)}', dellcomment, re.DOTALL)188 authors_email_en = re.findall(r'\\authorEng\[[^\]]*\]{[^}]*}{[^}]*}{([^},]*)', dellcomment)189 author_email_en = re.findall(r'\\authorEng{[^}]*}{[^}]*}{([^}]*)\b[^}]*}', dellcomment)190 affil_RU = re.findall(r'\\affil{([^}]*)}', dellcomment, re.DOTALL)191 affil_EN = re.findall(r'\\affilEng\[[^\]]*\]{([^}]*)}', dellcomment, re.DOTALL)192 affil_RU_some = re.findall(r'\\affil\[[^\]]*\]{([^}]*)}', dellcomment, re.DOTALL)193 affil_EN_one = re.findall(r'\\affilEng{([^}]*)}', dellcomment, re.DOTALL)194 affil_RU_one = re.findall(r'\\affil{([^}]*)}', dellcomment, re.DOTALL)195 authors_Initial_EN = re.findall(r'\\authorEng\[[^\]]*\]{([^}]*)\b\w+}{[^}]*}{[^}]*}', dellcomment)196 authors_Initial_RU = re.findall(r'\\author\[[^\]]*\]{([^}]*)\b\w+}{[^}]*}{[^}]*}', dellcomment)197 author_Initial_EN = re.findall(r'\\authorEng{([^}]+?)[\w\']*}', dellcomment)198 author_Initial_RU = re.findall(r'\\author{([^}]*)\b\w+[^}]*}{[^}]*}{[^}]*}', dellcomment)199 authors_Surname_en = re.findall(r'\\authorEng\[[^\]]*\]{[^}]*\b(\w+)}{[^}]*}{[^}]*}', dellcomment)200 authors_Surname_ru = re.findall(r'\\author\[[^\]]*\]{[^}]*\b(\w+)}{[^}]*}{[^}]*}', dellcomment)201 author_Surname_en = re.findall(r'\\authorEng{[^}]*?([\w\']+)}{[^}]*}{[^}]*}', dellcomment)202 author_Surname_ru = re.findall(r'\\author{[^}]*\b(\w+)[^}]*}{[^}]*}{[^}]*}', dellcomment)203 authors_Index_en = re.findall(r'\\authorEng\[([^\]]*)\]{[^}]*}{[^}]*}{[^}]*}', dellcomment, re.DOTALL)204 language_Article_en = dellcomment.count('\\selectlanguage{english}')205206 langRU = {'lang': 'RUS'}207 langEN = {'lang': 'ENG'}208 i = 0209 j = 0210 if language_Article_en == 0:211 while i < len(authors_full):212 atr_author = {'id': '0', 'num': i + 1}213 author = create_tag('author', None, atr_author)214 individInfoRU = create_tag('individInfo', None, langRU)215 individInfoEN = create_tag('individInfo', None, langEN)216 while j <= i:217 surnameRU = create_tag('surname', authors_name_and_surname_ru[j][5:])218 initialsRU = create_tag('initials', authors_name_and_surname_ru[j][0:4])219 surnameEN = create_tag('surname', author_Surname_en[j])220 initialsEN = create_tag('initials', author_Initial_EN[j][0:4])221 emailRU = create_tag('email', authors_email[j])222 emailEN = create_tag('email', authors_email[j])223 orgNameRU = create_tag('orgName', affil_RU[0])224 orgNameEN = create_tag('orgName', affil_EN_one[0])225 individInfoEN.appendChild(surnameEN)226 individInfoEN.appendChild(initialsEN)227 individInfoRU.appendChild(surnameRU)228 individInfoRU.appendChild(initialsRU)229 individInfoEN.appendChild(emailEN)230 individInfoRU.appendChild(emailRU)231 individInfoRU.appendChild(orgNameRU)232 individInfoEN.appendChild(orgNameEN)233 author.appendChild(individInfoRU)234 author.appendChild(individInfoEN)235 j = j + 1236 authors.appendChild(author)237 i = i + 1238 else:239 if not authors_full_en:240 countAuth = len(authors_full)241 else:242 countAuth = len(authors_full_en)243 while i < countAuth:244 atr_author = {'id': '0', 'num': i + 1}245 author = create_tag('author', None, atr_author)246 individInfoEN = create_tag('individInfo', None, langEN)247 individInfoRU = create_tag('individInfo', None, langRU)248 while j <= i:249 if not authors_Surname_en:250 surnameEN = create_tag('surname', author_Surname_en[j])251 surnameRU = create_tag('surname', author_Surname_ru[j])252 else:253 surnameEN = create_tag('surname', authors_Surname_en[j])254 surnameRU = create_tag('surname', authors_Surname_ru[j])255 individInfoEN.appendChild(surnameEN)256 individInfoRU.appendChild(surnameRU)257 if not authors_Initial_EN:258 initialsEN = create_tag('initials', author_Initial_EN[j])259 initialsRU = create_tag('initials', author_Initial_RU[j])260 else:261 initialsEN = create_tag('initials', authors_Initial_EN[j])262 initialsRU = create_tag('initials', authors_Initial_RU[j])263 individInfoEN.appendChild(initialsEN)264 individInfoRU.appendChild(initialsRU)265 if not authors_email_en:266 emailEN = create_tag('email', author_email_en[j])267 emailRU = create_tag('email', author_email_en[j])268 else:269 emailEN = create_tag('email', authors_email_en[j])270 emailRU = create_tag('email', authors_email_en[j])271 individInfoEN.appendChild(emailEN)272 individInfoRU.appendChild(emailRU)273274 if not affil_EN:275 orgNameEN = create_tag('orgName', affil_EN_one[0])276 orgNameRU = create_tag('orgName', affil_RU_one[0])277 else:278 ind = authors_Index_en[j][0:1]279 ind = int(ind) - 1280 orgNameEN = create_tag('orgName', affil_EN[int(ind)])281 orgNameRU = create_tag('orgName', affil_RU_some[int(ind)])282 individInfoEN.appendChild(orgNameEN)283 individInfoRU.appendChild(orgNameRU)284 author.appendChild(individInfoEN)285 author.appendChild(individInfoRU)286 j = j + 1287 authors.appendChild(author)288 i = i + 1289290 # ISSUE/ARTICLES/ARTICLE/ARTTITLE291 artTitles = create_tag('artTitles')292 titleRU = re.findall(r'\\title{((?:[^{}]|{[^}]*})*)}', dellcomment, re.DOTALL)293 titleEN = re.findall(r'\\titleEng{((?:[^{}]|{[^}]*})*)}', dellcomment, re.DOTALL)294 artTitleRU = create_tag('artTitle', titleRU[0], langRU)295 artTitleEN = create_tag('artTitle', titleEN[0], langEN)296 artTitles.appendChild(artTitleRU.cloneNode(True))297 artTitles.appendChild(artTitleEN.cloneNode(True))298299 # ISSUE/ARTICLES/ARTICLE/ABSTRACTS300 abstracts = create_tag('abstracts')301 abstrRU = re.findall(r'\\abstract{((?:[^{}]|{[^}]*})*)}', dellcomment, re.DOTALL)302 abstrEN= re.findall(r'\\abstractEng{((?:[^{}]|{[^}]*})*)}', dellcomment, re.DOTALL)303 abstractRU = create_tag('abstract', abstrRU[0], langRU)304 abstractEN = create_tag('abstract', abstrEN[0], langEN)305 abstracts.appendChild(abstractRU.cloneNode(True))306 abstracts.appendChild(abstractEN.cloneNode(True))307 # ISSUE/ARTICLES/ARTICLE/ABSTRACT308309 # ISSUE/ARTICLES/ARTICLE/TEXT310 atrText = {'lang': 'RUS'}311 beg = dellcomment.find('\\maketitle') + 10312 end = dellcomment.find('\\begin{thebibliography}') - 1313 text_art = create_tag('text', dellcomment[beg:end].strip(), atrText)314 # ISSUE/ARTICLES/ARTICLE/TEXT315316317 # ISSUE/ARTICLES/ARTICLE/CODES318 codes = create_tag('codes')319 udc = re.findall(r'\\udc{([^}]*)}', dellcomment, re.DOTALL)320 udk = create_tag('udk', udc[0])321 codes.appendChild(udk.cloneNode(True))322 # ISSUE/ARTICLES/ARTICLE/CODES323324325 # ISSUE/ARTICLES/ARTICLE/KEYWORDS326 kwdAtrRUS = {'lang': 'RUS'}327 kwdAtrENG = {'lang': 'ENG'}328 keywords = create_tag('keywords')329 kwdGroupRUS = create_tag('kwdGroup', None, kwdAtrRUS)330331332 keywords_all = re.findall(r'\\keywords{([^}]*)}', dellcomment, re.DOTALL)333 keywords_grouped = keywords_all[0].split(',')334 i = 0335 while i < len(keywords_grouped):336 keyword = str(keywords_grouped[i])337 keyword = keyword.strip('\n')338 keyword = keyword.strip()339 keyword = create_tag('keyword', keyword)340 kwdGroupRUS.appendChild(keyword.cloneNode(True))341 i = i + 1342343344 kwdGroupENG = create_tag('kwdGroup', None, kwdAtrENG)345 keywords_all = re.findall(r'\\keywordsEng{([^}]*)}', dellcomment, re.DOTALL)346 keywords_grouped = keywords_all[0].split(', ')347 i = 0348 while i < len(keywords_grouped):349 keyword = str(keywords_grouped[i])350 keyword = keyword.strip('\n')351 keyword = keyword.strip()352 keyword = create_tag('keyword', keyword)353 kwdGroupENG.appendChild(keyword.cloneNode(True))354 i = i + 1355356 keywords.appendChild(kwdGroupRUS.cloneNode(True))357 keywords.appendChild(kwdGroupENG.cloneNode(True))358# ISSUE/ARTICLES/ARTICLE/KEUWORDS359360361 # ISSUE/ARTICLES/ARTICLE/REFERENCES362 bBeg = dellcomment.find('begin{thebibliography}')363 bEnd = dellcomment.find('\\end{thebibliography}') - 2364 bibitems_all = re.split(r'\\bibitem{.*}', dellcomment[bBeg:bEnd])365 references = create_tag('references')366 i = 1367 while i < len(bibitems_all):368 bibitem = str(bibitems_all[i])369 bibitem = bibitem.strip('\n')370 bibitem = bibitem.strip()371 bibitem = bibitem.replace('\\url{', '')372 bibitem = bibitem.replace('{', '')373 bibitem = bibitem.replace('}', '')374 reference = create_tag('reference', bibitem)375 references.appendChild(reference.cloneNode(True))376 i = i + 1377378379 # ISSUE/ARTICLES/ARTICLE/REFERENCES380381382 # ISSUE/ARTICLES/ARTICLE/FILES383 nameURL = 'http://msm.omsu.ru/jrns/jrn' + altNum[0] + '/' + filename.replace('.tex', '.pdf')384 files = create_tag('files')385 furl = create_tag('furl', nameURL)386 file = create_tag('file', filename.replace('.tex', '.pdf'))387 files.appendChild(furl.cloneNode(True))388 files.appendChild(file.cloneNode(True))389 # ISSUE/ARTICLES/ARTICLE/FILES390391392393 # ISSUE/ARTICLES/ARTICLE/ARTTITLE394395 #authors.appendChild(author.cloneNode(True))396 article.appendChild(pages_article.cloneNode(True))397 article.appendChild(artType.cloneNode(True))398 article.appendChild(authors.cloneNode(True))399 article.appendChild(artTitles.cloneNode(True))400 article.appendChild(abstracts.cloneNode(True))
...
test_create_tag.py
Source:test_create_tag.py
...19from gvm.protocols.gmpv208 import EntityType20class GmpCreateTagTestMixin:21 def test_create_tag_missing_name(self):22 with self.assertRaises(RequiredArgument):23 self.gmp.create_tag(24 name=None, resource_ids=["foo"], resource_type=EntityType.TASK25 )26 with self.assertRaises(RequiredArgument):27 self.gmp.create_tag(28 name="", resource_ids=["foo"], resource_type=EntityType.TASK29 )30 def test_create_tag_missing_resource_filter_and_ids(self):31 self.gmp.create_tag(32 name="foo",33 resource_filter=None,34 resource_ids=None,35 resource_type=EntityType.TASK,36 )37 self.connection.send.has_been_called_with(38 "<create_tag>"39 "<name>foo</name>"40 "<resources>"41 "<type>task</type>"42 "</resources>"43 "</create_tag>"44 )45 self.gmp.create_tag(46 name="foo",47 resource_filter=None,48 resource_ids=[],49 resource_type=EntityType.TASK,50 )51 self.connection.send.has_been_called_with(52 "<create_tag>"53 "<name>foo</name>"54 "<resources>"55 "<type>task</type>"56 "</resources>"57 "</create_tag>"58 )59 self.gmp.create_tag(name="foo", resource_type=EntityType.TASK)60 self.connection.send.has_been_called_with(61 "<create_tag>"62 "<name>foo</name>"63 "<resources>"64 "<type>task</type>"65 "</resources>"66 "</create_tag>"67 )68 def test_create_tag_both_resource_filter_and_ids(self):69 with self.assertRaises(InvalidArgument):70 self.gmp.create_tag(71 name="foo",72 resource_filter="name=foo",73 resource_ids=["foo"],74 resource_type=EntityType.TASK,75 )76 def test_create_tag_invalid_resource_type(self):77 with self.assertRaises(InvalidArgumentType):78 self.gmp.create_tag(79 name="foo",80 resource_type="Foo",81 resource_filter=None,82 resource_ids=["foo"],83 )84 def test_create_tag_missing_resource_type(self):85 with self.assertRaises(RequiredArgument):86 self.gmp.create_tag(87 name="foo",88 resource_type=None,89 resource_filter=None,90 resource_ids=["foo"],91 )92 with self.assertRaises(RequiredArgument):93 self.gmp.create_tag(94 name="foo",95 resource_type=None,96 resource_filter="name=foo",97 resource_ids=None,98 )99 with self.assertRaises(RequiredArgument):100 self.gmp.create_tag(101 name="foo", resource_type="", resource_ids=["foo"]102 )103 def test_create_tag_with_resource_filter(self):104 self.gmp.create_tag(105 name="foo",106 resource_filter="name=foo",107 resource_type=EntityType.TASK,108 )109 self.connection.send.has_been_called_with(110 "<create_tag>"111 "<name>foo</name>"112 '<resources filter="name=foo">'113 "<type>task</type>"114 "</resources>"115 "</create_tag>"116 )117 def test_create_tag_with_resource_filter_audit(self):118 self.gmp.create_tag(119 name="foo",120 resource_filter="name=foo",121 resource_type=EntityType.AUDIT,122 )123 self.connection.send.has_been_called_with(124 "<create_tag>"125 "<name>foo</name>"126 '<resources filter="name=foo">'127 "<type>task</type>"128 "</resources>"129 "</create_tag>"130 )131 def test_create_tag_with_resource_filter_policy(self):132 self.gmp.create_tag(133 name="foo",134 resource_filter="name=foo",135 resource_type=EntityType.POLICY,136 )137 self.connection.send.has_been_called_with(138 "<create_tag>"139 "<name>foo</name>"140 '<resources filter="name=foo">'141 "<type>config</type>"142 "</resources>"143 "</create_tag>"144 )145 def test_create_tag_with_resource_ids(self):146 self.gmp.create_tag(147 name="foo", resource_ids=["foo"], resource_type=EntityType.TASK148 )149 self.connection.send.has_been_called_with(150 "<create_tag>"151 "<name>foo</name>"152 "<resources>"153 '<resource id="foo"/>'154 "<type>task</type>"155 "</resources>"156 "</create_tag>"157 )158 self.gmp.create_tag(159 name="foo",160 resource_ids=["foo", "bar"],161 resource_type=EntityType.TASK,162 )163 self.connection.send.has_been_called_with(164 "<create_tag>"165 "<name>foo</name>"166 "<resources>"167 '<resource id="foo"/>'168 '<resource id="bar"/>'169 "<type>task</type>"170 "</resources>"171 "</create_tag>"172 )173 def test_create_tag_with_comment(self):174 self.gmp.create_tag(175 name="foo",176 resource_ids=["foo"],177 resource_type=EntityType.TASK,178 comment="bar",179 )180 self.connection.send.has_been_called_with(181 "<create_tag>"182 "<name>foo</name>"183 "<resources>"184 '<resource id="foo"/>'185 "<type>task</type>"186 "</resources>"187 "<comment>bar</comment>"188 "</create_tag>"189 )190 def test_create_tag_with_value(self):191 self.gmp.create_tag(192 name="foo",193 resource_ids=["foo"],194 resource_type=EntityType.TASK,195 value="bar",196 )197 self.connection.send.has_been_called_with(198 "<create_tag>"199 "<name>foo</name>"200 "<resources>"201 '<resource id="foo"/>'202 "<type>task</type>"203 "</resources>"204 "<value>bar</value>"205 "</create_tag>"206 )207 def test_create_tag_with_active(self):208 self.gmp.create_tag(209 name="foo",210 resource_ids=["foo"],211 resource_type=EntityType.TASK,212 active=True,213 )214 self.connection.send.has_been_called_with(215 "<create_tag>"216 "<name>foo</name>"217 "<resources>"218 '<resource id="foo"/>'219 "<type>task</type>"220 "</resources>"221 "<active>1</active>"222 "</create_tag>"223 )224 self.gmp.create_tag(225 name="foo",226 resource_ids=["foo"],227 resource_type=EntityType.TASK,228 active=False,229 )230 self.connection.send.has_been_called_with(231 "<create_tag>"232 "<name>foo</name>"233 "<resources>"234 '<resource id="foo"/>'235 "<type>task</type>"236 "</resources>"237 "<active>0</active>"238 "</create_tag>"...
test_engines_differences.py
Source:test_engines_differences.py
...5from draftjs_exporter.engines.lxml import DOM_LXML6from draftjs_exporter.engines.string import DOMString7class TestDOMEnginesDifferences(unittest.TestCase):8 def test_html5lib_self_closing_tags(self):9 self.assertEqual(DOM_HTML5LIB.render_debug(DOM_HTML5LIB.create_tag('hr')), '<hr/>')10 def test_lxml_self_closing_tags(self):11 self.assertEqual(DOM_LXML.render_debug(DOM_LXML.create_tag('hr')), '<hr>')12 def test_string_self_closing_tags(self):13 self.assertEqual(DOMString.render_debug(DOMString.create_tag('hr')), '<hr/>')14 def test_html5lib_invalid_attributes(self):15 self.assertEqual(DOM_HTML5LIB.render_debug(DOM_HTML5LIB.create_tag('div', {'*ngFor': 'test'})), '<div *ngFor="test"></div>')16 def test_lxml_invalid_attributes(self):17 with self.assertRaises(ValueError):18 DOM_LXML.render_debug(DOM_LXML.create_tag('div', {'*ngFor': 'test'}))19 def test_string_invalid_attributes(self):20 self.assertEqual(DOMString.render_debug(DOMString.create_tag('div', {'*ngFor': 'test'})), '<div *ngFor="test"></div>')21 def test_html5lib_namespaced_attributes(self):22 bs_elt = DOM_HTML5LIB.create_tag('svg')23 DOM_HTML5LIB.append_child(bs_elt, DOM_HTML5LIB.create_tag('use', {'xlink:href': 'test'}))24 self.assertEqual(DOM_HTML5LIB.render_debug(bs_elt), '<svg><use xlink:href="test"></use></svg>')25 def test_lxml_namespaced_attributes(self):26 lxml_elt = DOM_LXML.create_tag('svg')27 DOM_LXML.append_child(lxml_elt, DOM_LXML.create_tag('use', {'xlink:href': 'test'}))28 self.assertEqual(DOM_LXML.render_debug(lxml_elt), '<svg><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="test"></use></svg>')29 def test_string_namespaced_attributes(self):30 bs_elt = DOMString.create_tag('svg')31 DOMString.append_child(bs_elt, DOMString.create_tag('use', {'xlink:href': 'test'}))32 self.assertEqual(DOMString.render_debug(bs_elt), '<svg><use xlink:href="test"></use></svg>')33 def test_html5lib_html_escaping(self):34 self.assertEqual(DOM_HTML5LIB.render_debug(DOM_HTML5LIB.create_tag('img', {35 'alt': '< " \' < > &',36 })), '<img alt="< " \' < > &"/>')37 def test_lxml_html_escaping(self):38 self.assertEqual(DOM_LXML.render_debug(DOM_LXML.create_tag('img', {39 'alt': '< " \' < > &',40 })), '<img alt="< " \' < > &">')41 def test_string_html_escaping(self):42 self.assertEqual(DOMString.render_debug(DOMString.create_tag('img', {43 'alt': '< " \' < > &',44 })), '<img alt="< " ' < > &"/>')45 def test_html5lib_html_parsing(self):46 self.assertEqual(DOM_HTML5LIB.render_debug(DOM_HTML5LIB.parse_html('<p>Invalid > " &</p>')), '<p>Invalid > " &</p>')47 def test_lxml_html_parsing(self):48 self.assertEqual(DOM_LXML.render_debug(DOM_LXML.parse_html('<p>Invalid > " &</p>')), '<p>Invalid > " &</p>')49 def test_string_html_parsing(self):...
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!!