You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/AdvancedHTMLParserTests/test_Style.py
+72Lines changed: 72 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -334,5 +334,77 @@ def test_styleCopy(self):
334
334
assert'float: left'notinstr(tag1) , 'Expected update to oldStyle to not change html representation of tag with different style. str(tag1) = '+str(tag1)
335
335
336
336
337
+
deftest_htmlAttrPresent(self):
338
+
'''
339
+
test_htmlAttrPresent - Test that html attribute is present when set, and not when not.
340
+
'''
341
+
tag=AdvancedHTMLParser.AdvancedTag('div')
342
+
343
+
assert"style="notinstr(tag) , 'Expected style to not be in tag html. Got: '+str(tag)
344
+
345
+
assert'style'notintag.attributes , "Expected style to not be in tag attributes."
346
+
347
+
tagCopy=tag.cloneNode()
348
+
349
+
tag.style='display: block; float: left'
350
+
351
+
tagHTML=str(tag)
352
+
353
+
assert'style="'intagHTMLand'display: block'intagHTMLand'float: left'intagHTML , "Expected style to be set properly on tag, but was not. Got: "+tagHTML
354
+
355
+
tag.style=''
356
+
tagHTML=str(tag)
357
+
358
+
assert"style"notintagHTML , "Expected after clearing style via tag.style='' that the attribute was gone. Got: "+tagHTML
359
+
360
+
assertstr(tag.getAttribute("style")) =="" , "Expected after clearing style via tag.style='' that attribute was gone."
361
+
362
+
tag=tagCopy
363
+
364
+
tagCopy=tag.cloneNode()
365
+
366
+
assertstr(tag.style) =='' , 'Expected cloned node to not have linked style to its parent'
assert'style="'intagHTMLand'display: block'intagHTMLand'float: right'intagHTML , "Expected style to be set properly on tag with setAttribute('style', ...) , but was not. Got: "+tagHTML
373
+
374
+
tag.setAttribute('style', 'display: block')
375
+
tagHTML=str(tag)
376
+
assert'style="'intagHTMLand'display: block'intagHTMLand'float: right'notintagHTML , "Expected style to be set properly on tag after modification by setAttribute('style', ...) , but was not. Got: "+tagHTML
377
+
378
+
tagCopy=tag.cloneNode()
379
+
380
+
tag.setAttribute('style', '')
381
+
382
+
tagHTML=str(tag)
383
+
384
+
assert"style"notintagHTML , "Expected setAttribute('style', '') to clear style from html, but did not. Got: "+tagHTML
385
+
386
+
tag=tagCopy
387
+
tagCopy=tag.cloneNode()
388
+
tagHTML=str(tag)
389
+
390
+
assert"style"intagHTML , "Expected cloneNode to retain style, did not."
391
+
392
+
tag.removeAttribute('style')
393
+
tagHTML=str(tag)
394
+
395
+
assert"style"notintagHTML , "Expected removeAttribute('style') to clear style from html, but did not. Got: "+tagHTML
396
+
397
+
398
+
tag=tagCopy
399
+
400
+
401
+
tag.attributes['style'] =''
402
+
tagHTML=str(tag)
403
+
404
+
assert"style"notintagHTML , "Expected tag.attributes['style'] = '' to clear stlye from html, but did not. Got: "+tagHTML
405
+
406
+
assertstr(tag.style) =='' , 'Expected tag.attributes["style"] = '' to clear style attribute, but tag.style returned: '+str(tag.style)
0 commit comments