@@ -102,41 +102,38 @@ def testInsertBefore(self):
102
102
elem = root .childNodes [0 ]
103
103
nelem = dom .createElement ("element" )
104
104
root .insertBefore (nelem , elem )
105
- self .confirm (len (root .childNodes ) == 2
106
- and root .childNodes .length == 2
107
- and root .childNodes [0 ] is nelem
108
- and root .childNodes .item (0 ) is nelem
109
- and root .childNodes [1 ] is elem
110
- and root .childNodes .item (1 ) is elem
111
- and root .firstChild is nelem
112
- and root .lastChild is elem
113
- and root .toxml () == "<doc><element/><foo/></doc>"
114
- , "testInsertBefore -- node properly placed in tree" )
105
+ self .assertEqual (len (root .childNodes ), 2 )
106
+ self .assertEqual (root .childNodes .length , 2 )
107
+ self .assertIs (root .childNodes [0 ], nelem )
108
+ self .assertIs (root .childNodes .item (0 ), nelem )
109
+ self .assertIs (root .childNodes [1 ], elem )
110
+ self .assertIs (root .childNodes .item (1 ), elem )
111
+ self .assertIs (root .firstChild , nelem )
112
+ self .assertIs (root .lastChild , elem )
113
+ self .assertEqual (root .toxml (), "<doc><element/><foo/></doc>" )
115
114
nelem = dom .createElement ("element" )
116
115
root .insertBefore (nelem , None )
117
- self .confirm (len (root .childNodes ) == 3
118
- and root .childNodes .length == 3
119
- and root .childNodes [1 ] is elem
120
- and root .childNodes .item (1 ) is elem
121
- and root .childNodes [2 ] is nelem
122
- and root .childNodes .item (2 ) is nelem
123
- and root .lastChild is nelem
124
- and nelem .previousSibling is elem
125
- and root .toxml () == "<doc><element/><foo/><element/></doc>"
126
- , "testInsertBefore -- node properly placed in tree" )
116
+ self .assertEqual (len (root .childNodes ), 3 )
117
+ self .assertEqual (root .childNodes .length , 3 )
118
+ self .assertIs (root .childNodes [1 ], elem )
119
+ self .assertIs (root .childNodes .item (1 ), elem )
120
+ self .assertIs (root .childNodes [2 ], nelem )
121
+ self .assertIs (root .childNodes .item (2 ), nelem )
122
+ self .assertIs (root .lastChild , nelem )
123
+ self .assertIs (nelem .previousSibling , elem )
124
+ self .assertEqual (root .toxml (), "<doc><element/><foo/><element/></doc>" )
127
125
nelem2 = dom .createElement ("bar" )
128
126
root .insertBefore (nelem2 , nelem )
129
- self .confirm (len (root .childNodes ) == 4
130
- and root .childNodes .length == 4
131
- and root .childNodes [2 ] is nelem2
132
- and root .childNodes .item (2 ) is nelem2
133
- and root .childNodes [3 ] is nelem
134
- and root .childNodes .item (3 ) is nelem
135
- and nelem2 .nextSibling is nelem
136
- and nelem .previousSibling is nelem2
137
- and root .toxml () ==
138
- "<doc><element/><foo/><bar/><element/></doc>"
139
- , "testInsertBefore -- node properly placed in tree" )
127
+ self .assertEqual (len (root .childNodes ), 4 )
128
+ self .assertEqual (root .childNodes .length , 4 )
129
+ self .assertIs (root .childNodes [2 ], nelem2 )
130
+ self .assertIs (root .childNodes .item (2 ), nelem2 )
131
+ self .assertIs (root .childNodes [3 ], nelem )
132
+ self .assertIs (root .childNodes .item (3 ), nelem )
133
+ self .assertIs (nelem2 .nextSibling , nelem )
134
+ self .assertIs (nelem .previousSibling , nelem2 )
135
+ self .assertEqual (root .toxml (),
136
+ "<doc><element/><foo/><bar/><element/></doc>" )
140
137
dom .unlink ()
141
138
142
139
def _create_fragment_test_nodes (self ):
@@ -342,8 +339,8 @@ def testRemoveAttributeNode(self):
342
339
self .assertRaises (xml .dom .NotFoundErr , child .removeAttributeNode ,
343
340
None )
344
341
self .assertIs (node , child .removeAttributeNode (node ))
345
- self .confirm (len (child .attributes ) == 0
346
- and child .getAttributeNode ("spam" ) is None )
342
+ self .assertEqual (len (child .attributes ), 0 )
343
+ self . assertIsNone ( child .getAttributeNode ("spam" ))
347
344
dom2 = Document ()
348
345
child2 = dom2 .appendChild (dom2 .createElement ("foo" ))
349
346
node2 = child2 .getAttributeNode ("spam" )
@@ -366,33 +363,34 @@ def testChangeAttr(self):
366
363
# Set this attribute to be an ID and make sure that doesn't change
367
364
# when changing the value:
368
365
el .setIdAttribute ("spam" )
369
- self .confirm (len (el .attributes ) == 1
370
- and el .attributes ["spam" ].value == "bam"
371
- and el .attributes ["spam" ].nodeValue == "bam"
372
- and el .getAttribute ("spam" ) == "bam"
373
- and el .getAttributeNode ("spam" ).isId )
366
+ self .assertEqual (len (el .attributes ), 1 )
367
+ self . assertEqual ( el .attributes ["spam" ].value , "bam" )
368
+ self . assertEqual ( el .attributes ["spam" ].nodeValue , "bam" )
369
+ self . assertEqual ( el .getAttribute ("spam" ), "bam" )
370
+ self . assertTrue ( el .getAttributeNode ("spam" ).isId )
374
371
el .attributes ["spam" ] = "ham"
375
- self .confirm (len (el .attributes ) == 1
376
- and el .attributes ["spam" ].value == "ham"
377
- and el .attributes ["spam" ].nodeValue == "ham"
378
- and el .getAttribute ("spam" ) == "ham"
379
- and el .attributes ["spam" ].isId )
372
+ self .assertEqual (len (el .attributes ), 1 )
373
+ self . assertEqual ( el .attributes ["spam" ].value , "ham" )
374
+ self . assertEqual ( el .attributes ["spam" ].nodeValue , "ham" )
375
+ self . assertEqual ( el .getAttribute ("spam" ), "ham" )
376
+ self . assertTrue ( el .attributes ["spam" ].isId )
380
377
el .setAttribute ("spam2" , "bam" )
381
- self .confirm (len (el .attributes ) == 2
382
- and el .attributes ["spam" ].value == "ham"
383
- and el .attributes ["spam" ].nodeValue == "ham"
384
- and el .getAttribute ("spam" ) == "ham"
385
- and el .attributes ["spam2" ].value == "bam"
386
- and el .attributes ["spam2" ].nodeValue == "bam"
387
- and el .getAttribute ("spam2" ) == "bam" )
378
+ self .assertEqual (len (el .attributes ), 2 )
379
+ self . assertEqual ( el .attributes ["spam" ].value , "ham" )
380
+ self . assertEqual ( el .attributes ["spam" ].nodeValue , "ham" )
381
+ self . assertEqual ( el .getAttribute ("spam" ), "ham" )
382
+ self . assertEqual ( el .attributes ["spam2" ].value , "bam" )
383
+ self . assertEqual ( el .attributes ["spam2" ].nodeValue , "bam" )
384
+ self . assertEqual ( el .getAttribute ("spam2" ), "bam" )
388
385
el .attributes ["spam2" ] = "bam2"
389
- self .confirm (len (el .attributes ) == 2
390
- and el .attributes ["spam" ].value == "ham"
391
- and el .attributes ["spam" ].nodeValue == "ham"
392
- and el .getAttribute ("spam" ) == "ham"
393
- and el .attributes ["spam2" ].value == "bam2"
394
- and el .attributes ["spam2" ].nodeValue == "bam2"
395
- and el .getAttribute ("spam2" ) == "bam2" )
386
+
387
+ self .assertEqual (len (el .attributes ), 2 )
388
+ self .assertEqual (el .attributes ["spam" ].value , "ham" )
389
+ self .assertEqual (el .attributes ["spam" ].nodeValue , "ham" )
390
+ self .assertEqual (el .getAttribute ("spam" ), "ham" )
391
+ self .assertEqual (el .attributes ["spam2" ].value , "bam2" )
392
+ self .assertEqual (el .attributes ["spam2" ].nodeValue , "bam2" )
393
+ self .assertEqual (el .getAttribute ("spam2" ), "bam2" )
396
394
dom .unlink ()
397
395
398
396
def testGetAttrList (self ):
@@ -448,12 +446,12 @@ def testGetElementsByTagNameNS(self):
448
446
dom = parseString (d )
449
447
elems = dom .getElementsByTagNameNS ("http://pyxml.sf.net/minidom" ,
450
448
"myelem" )
451
- self .confirm (len (elems ) == 1
452
- and elems [0 ].namespaceURI == "http://pyxml.sf.net/minidom"
453
- and elems [0 ].localName == "myelem"
454
- and elems [0 ].prefix == "minidom"
455
- and elems [0 ].tagName == "minidom:myelem"
456
- and elems [0 ].nodeName == "minidom:myelem" )
449
+ self .assertEqual (len (elems ), 1 )
450
+ self . assertEqual ( elems [0 ].namespaceURI , "http://pyxml.sf.net/minidom" )
451
+ self . assertEqual ( elems [0 ].localName , "myelem" )
452
+ self . assertEqual ( elems [0 ].prefix , "minidom" )
453
+ self . assertEqual ( elems [0 ].tagName , "minidom:myelem" )
454
+ self . assertEqual ( elems [0 ].nodeName , "minidom:myelem" )
457
455
dom .unlink ()
458
456
459
457
def get_empty_nodelist_from_elements_by_tagName_ns_helper (self , doc , nsuri ,
@@ -602,17 +600,17 @@ def test_toprettyxml_preserves_content_of_text_node(self):
602
600
def testProcessingInstruction (self ):
603
601
dom = parseString ('<e><?mypi \t \n data \t \n ?></e>' )
604
602
pi = dom .documentElement .firstChild
605
- self .confirm (pi .target == "mypi"
606
- and pi .data == "data \t \n "
607
- and pi .nodeName == "mypi"
608
- and pi .nodeType == Node .PROCESSING_INSTRUCTION_NODE
609
- and pi .attributes is None
610
- and not pi .hasChildNodes ()
611
- and len (pi .childNodes ) == 0
612
- and pi .firstChild is None
613
- and pi .lastChild is None
614
- and pi .localName is None
615
- and pi .namespaceURI == xml .dom .EMPTY_NAMESPACE )
603
+ self .assertEqual (pi .target , "mypi" )
604
+ self . assertEqual ( pi .data , "data \t \n " )
605
+ self . assertEqual ( pi .nodeName , "mypi" )
606
+ self . assertEqual ( pi .nodeType , Node .PROCESSING_INSTRUCTION_NODE )
607
+ self . assertIsNone ( pi .attributes )
608
+ self . assertFalse ( pi .hasChildNodes () )
609
+ self . assertEqual ( len (pi .childNodes ), 0 )
610
+ self . assertIsNone ( pi .firstChild )
611
+ self . assertIsNone ( pi .lastChild )
612
+ self . assertIsNone ( pi .localName )
613
+ self . assertEqual ( pi .namespaceURI , xml .dom .EMPTY_NAMESPACE )
616
614
617
615
def testProcessingInstructionRepr (self ):
618
616
dom = parseString ('<e><?mypi \t \n data \t \n ?></e>' )
@@ -718,19 +716,16 @@ def _testCloneElementCopiesAttributes(self, e1, e2, test):
718
716
keys2 = list (attrs2 .keys ())
719
717
keys1 .sort ()
720
718
keys2 .sort ()
721
- self .assertEqual (keys1 , keys2 ,
722
- "clone of element has same attribute keys" )
719
+ self .assertEqual (keys1 , keys2 )
723
720
for i in range (len (keys1 )):
724
721
a1 = attrs1 .item (i )
725
722
a2 = attrs2 .item (i )
726
- self .confirm (a1 is not a2
727
- and a1 .value == a2 .value
728
- and a1 .nodeValue == a2 .nodeValue
729
- and a1 .namespaceURI == a2 .namespaceURI
730
- and a1 .localName == a2 .localName
731
- , "clone of attribute node has proper attribute values" )
732
- self .assertIs (a2 .ownerElement , e2 ,
733
- "clone of attribute node correctly owned" )
723
+ self .assertIsNot (a1 , a2 )
724
+ self .assertEqual (a1 .value , a2 .value )
725
+ self .assertEqual (a1 .nodeValue , a2 .nodeValue )
726
+ self .assertEqual (a1 .namespaceURI ,a2 .namespaceURI )
727
+ self .assertEqual (a1 .localName , a2 .localName )
728
+ self .assertIs (a2 .ownerElement , e2 )
734
729
735
730
def _setupCloneElement (self , deep ):
736
731
dom = parseString ("<doc attr='value'><foo/></doc>" )
@@ -746,20 +741,19 @@ def _setupCloneElement(self, deep):
746
741
747
742
def testCloneElementShallow (self ):
748
743
dom , clone = self ._setupCloneElement (0 )
749
- self .confirm (len (clone .childNodes ) == 0
750
- and clone .childNodes .length == 0
751
- and clone .parentNode is None
752
- and clone .toxml () == '<doc attr="value"/>'
753
- , "testCloneElementShallow" )
744
+ self .assertEqual (len (clone .childNodes ), 0 )
745
+ self . assertEqual ( clone .childNodes .length , 0 )
746
+ self . assertIsNone ( clone .parentNode )
747
+ self . assertEqual ( clone .toxml (), '<doc attr="value"/>' )
748
+
754
749
dom .unlink ()
755
750
756
751
def testCloneElementDeep (self ):
757
752
dom , clone = self ._setupCloneElement (1 )
758
- self .confirm (len (clone .childNodes ) == 1
759
- and clone .childNodes .length == 1
760
- and clone .parentNode is None
761
- and clone .toxml () == '<doc attr="value"><foo/></doc>'
762
- , "testCloneElementDeep" )
753
+ self .assertEqual (len (clone .childNodes ), 1 )
754
+ self .assertEqual (clone .childNodes .length , 1 )
755
+ self .assertIsNone (clone .parentNode )
756
+ self .assertTrue (clone .toxml (), '<doc attr="value"><foo/></doc>' )
763
757
dom .unlink ()
764
758
765
759
def testCloneDocumentShallow (self ):
0 commit comments