Changeset 5022 for anuga_core/source/anuga/utilities/test_xml_tools.py
- Timestamp:
- Feb 12, 2008, 2:37:03 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/test_xml_tools.py
r5015 r5022 132 132 133 133 134 135 136 def test_xml2object_empty_fields(self): 137 """Test that XML_document can be generated from file 138 This on tests that empty fields are treated as '' 139 """ 140 141 tmp_fd , tmp_name = mkstemp(suffix='.xml', dir='.') 142 fid = os.fdopen(tmp_fd, 'w') 143 144 xml_string = """<?xml version="1.0" encoding="iso-8859-1"?> 145 <ga_license_file> 146 <metadata> 147 <author>Ole Nielsen</author> 148 <svn_keywords> 149 <author>$Author$</author> 150 <date>$Date$</date> 151 <revision>$Revision$</revision> 152 <url>$URL:$</url> 153 <id>$Id$</id> 154 </svn_keywords> 155 </metadata> 156 <datafile> 157 <filename>bathymetry.asc</filename> 158 <checksum>%s</checksum> 159 <publishable></publishable> 160 <accountable>Jane Sexton</accountable> 161 <source>Unknown</source> 162 <IP_owner>Geoscience Australia</IP_owner> 163 <IP_info>This is a test</IP_info> 164 </datafile> 165 </ga_license_file> 166 """ %('1234') 167 168 fid.write(xml_string) 169 fid.close() 170 171 fid = open(tmp_name) 172 reference = fid.read() 173 reflines = reference.split('\n') 174 175 xmlobject = xml2object(fid, verbose=True) 176 177 178 #print xmlobject.pretty_print() 179 180 xmllines = str(xmlobject).split('\n') 181 182 #for line in reflines: 183 # print line 184 #print 185 #for line in xmllines: 186 # print line 187 188 189 ##assert len(reflines) == len(xmllines) 190 x = xmlobject['ga_license_file']['datafile']['publishable'] 191 msg = 'Got %s, should have been an empty string' %x 192 assert x == '', msg 193 194 195 for i, refline in enumerate(reflines): 196 msg = '%s != %s' %(refline.strip(), xmllines[i].strip()) 197 assert refline.strip() == xmllines[i].strip(), msg 198 199 # Check dictionary behaviour 200 for tag in xmlobject['ga_license_file'].keys(): 201 xmlobject['ga_license_file'][tag] 202 203 assert xmlobject['ga_license_file']['datafile']['accountable'] == 'Jane Sexton' 204 205 206 207 208 #print 209 #print xmlobject['ga_license_file']['datafile'] 210 #print xmlobject['ga_license_file']['metadata'] 211 #print xmlobject['ga_license_file']['datafile'] 212 #print xmlobject['ga_license_file']['datafile']['accountable'] 213 #print xmlobject['ga_license_file']['datafile'].keys() 214 215 #for tag in xmlobject['ga_license_file'].keys(): 216 # print xmlobject['ga_license_file'][tag] 217 218 # Clean up 219 fid.close() 220 os.remove(tmp_name) 221 222 134 223 135 224
Note: See TracChangeset
for help on using the changeset viewer.