22import xml .dom .minidom
33
44from xcp .xmlunwrap import (getElementsByTagName , getText , getMapAttribute ,
5- getStrAttribute , XmlUnwrapError )
5+ getStrAttribute , getIntAttribute , XmlUnwrapError )
66
77class TestXmlUnwrap (unittest .TestCase ):
88 def setUp (self ):
9- a_text = """<installation mode='test'>
9+ a_text = """<installation mode='test' integer='1' >
1010 <fred>text1</fred>
1111 <fred>text2</fred>
1212 </installation>"""
@@ -20,17 +20,25 @@ def test(self):
2020 for el in getElementsByTagName (self .top_el , ["fred" ])],
2121 ["text1" , "text2" ])
2222
23+ # Test xcp.xmlunwrap.getIntAttribute()
24+ self .assertEqual (getIntAttribute (self .top_el , ["integer" ], 5 ), 1 )
25+ self .assertEqual (getIntAttribute (self .top_el , ["noexist" ], 5 ), 5 )
26+ with self .assertRaises (XmlUnwrapError ):
27+ getIntAttribute (self .top_el , ["nonexisting-attribute" ])
28+
29+ # Test xcp.xmlunwrap.getMapAttribute()
2330 x = getMapAttribute (self .top_el , ["mode" ], [('test' , 42 ), ('stuff' , 77 )])
2431 self .assertEqual (x , 42 )
2532 x = getMapAttribute (self .top_el , ["made" ], [('test' , 42 ), ('stuff' , 77 )],
2633 default = 'stuff' )
2734 self .assertEqual (x , 77 )
2835
36+ # Test xcp.xmlunwrap.getIntAttribute()
2937 x = getStrAttribute (self .top_el , ["mode" ])
3038 self .assertEqual (x , "test" )
3139 x = getStrAttribute (self .top_el , ["made" ])
3240 self .assertEqual (x , "" )
33- x = getStrAttribute (self .top_el , ["made" ], None )
41+ x = getStrAttribute (self .top_el , ["made" ], None ) # pyright: ignore
3442 self .assertEqual (x , None )
3543
3644 with self .assertRaises (XmlUnwrapError ):
0 commit comments