- Timestamp:
- May 5, 2014 3:41:43 PM (11 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- c81aa18
- Parents:
- 0089be3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/sansdataloader/test/utest_cansas.py
r2e3b055 rac5b69d 5 5 warnings.simplefilter("ignore") 6 6 7 import unittest8 import numpy9 7 import sans.dataloader.readers.cansas_reader as cansas 10 8 from sans.dataloader.loader import Loader … … 12 10 from sans.dataloader.readers.xml_reader import XMLreader 13 11 from sans.dataloader.readers.cansas_reader import Reader 14 from sans.dataloader.readers.cansas_constants import cansasConstants12 from sans.dataloader.readers.cansas_constants import CansasConstants 15 13 16 14 import os … … 18 16 import urllib2 19 17 import StringIO 18 import pylint as pylint 19 import unittest 20 import numpy 20 21 21 22 from lxml import etree 22 23 from xml.dom import minidom 23 24 24 CANSAS_FORMAT = cansasConstants.CANSAS_FORMAT25 CANSAS_NS = cansasConstants.CANSAS_NS25 CANSAS_FORMAT = CansasConstants.CANSAS_FORMAT 26 CANSAS_NS = CansasConstants.CANSAS_NS 26 27 27 28 class cansas_reader(unittest.TestCase): … … 72 73 def test_real_xml(self): 73 74 reader = XMLreader(self.xml_valid, self.schema_1_0) 74 valid = reader.validate XML()75 valid = reader.validate_xml() 75 76 if valid: 76 77 self.assertTrue(valid) … … 101 102 filename = "isis_1_1_write_test.xml" 102 103 xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) 103 valid = xmlreader.validate XML()104 xmlreader.set ProcessingInstructions()104 valid = xmlreader.validate_xml() 105 xmlreader.set_processing_instructions() 105 106 self.assertTrue(valid) 106 107 fo = open(self.isis_1_1) … … 126 127 def test_double_trans_spectra(self): 127 128 xmlreader = XMLreader(self.isis_1_1_doubletrans, self.schema_1_1) 128 self.assertTrue(xmlreader.validate XML())129 self.assertTrue(xmlreader.validate_xml()) 129 130 reader = Loader() 130 131 data = reader.load(self.isis_1_1_doubletrans) … … 146 147 valid = [] 147 148 reader1 = XMLreader(self.xml_valid, self.schema_1_0) 148 self.assertTrue(reader1.validate XML())149 self.assertTrue(reader1.validate_xml()) 149 150 reader2 = XMLreader(self.xml_invalid, self.schema_1_0) 150 self.assertFalse(reader2.validate XML())151 self.assertFalse(reader2.validate_xml()) 151 152 reader3 = XMLreader(self.xml_valid, self.schema_1_1) 152 self.assertFalse(reader3.validate XML())153 self.assertFalse(reader3.validate_xml()) 153 154 reader4 = XMLreader(self.xml_invalid, self.schema_1_1) 154 self.assertFalse(reader4.validate XML())155 self.assertFalse(reader4.validate_xml()) 155 156 reader5 = XMLreader(self.isis_1_0, self.schema_1_0) 156 self.assertTrue(reader5.validate XML())157 self.assertTrue(reader5.validate_xml()) 157 158 reader6 = XMLreader(self.isis_1_1, self.schema_1_1) 158 self.assertTrue(reader6.validate XML())159 self.assertTrue(reader6.validate_xml()) 159 160 reader7 = XMLreader(self.isis_1_1, self.schema_1_0) 160 self.assertFalse(reader7.validate XML())161 self.assertFalse(reader7.validate_xml()) 161 162 162 163 163 164 def test_old_cansas_files(self): 164 165 reader1 = XMLreader(self.cansas1d, self.schema_1_0) 165 self.assertTrue(reader1.validate XML())166 self.assertTrue(reader1.validate_xml()) 166 167 file_loader = Loader() 167 168 file1 = file_loader.load(self.cansas1d) 168 169 reader2 = XMLreader(self.cansas1d_units, self.schema_1_0) 169 self.assertTrue(reader2.validate XML())170 self.assertTrue(reader2.validate_xml()) 170 171 reader3 = XMLreader(self.cansas1d_badunits, self.schema_1_0) 171 self.assertTrue(reader3.validate XML())172 self.assertTrue(reader3.validate_xml()) 172 173 reader4 = XMLreader(self.cansas1d_slit, self.schema_1_0) 173 self.assertTrue(reader4.validate XML())174 self.assertTrue(reader4.validate_xml()) 174 175 175 176 … … 177 178 filename = "isis_1_0_write_test.xml" 178 179 xmlreader = XMLreader(self.isis_1_0, self.schema_1_0) 179 valid = xmlreader.validate XML()180 valid = xmlreader.validate_xml() 180 181 self.assertTrue(valid) 181 182 reader_generic = Loader() … … 191 192 written_data = return_data[0] 192 193 xmlwrite = XMLreader(filename, self.schema_1_0) 193 valid = xmlreader.validate XML()194 valid = xmlreader.validate_xml() 194 195 self.assertTrue(valid) 195 196 self._check_data(written_data) … … 198 199 def test_processing_instructions(self): 199 200 reader = XMLreader(self.isis_1_1, self.schema_1_1) 200 valid = reader.validate XML()201 valid = reader.validate_xml() 201 202 if valid: 202 203 ## find the processing instructions and make into a dictionary 203 dic = self.get ProcessingInstructions(reader)204 dic = self.get_processing_instructions(reader) 204 205 self.assertTrue(dic == {'xml-stylesheet': 'type="text/xsl" href="cansas1d.xsl" '}) 205 206 … … 208 209 209 210 ## take the processing instructions and put them back in 210 xmldoc = self.set ProcessingInstructions(xmldoc, dic)211 xmldoc = self.set_processing_instructions(xmldoc, dic) 211 212 xml_output = xmldoc.toprettyxml() 212 213 213 214 214 def set ProcessingInstructions(self, minidomObject, dic):215 xmlroot = minidom Object.firstChild215 def set_processing_instructions(self, minidom_object, dic): 216 xmlroot = minidom_object.firstChild 216 217 for item in dic: 217 pi = minidom Object.createProcessingInstruction(item, dic[item])218 minidom Object.insertBefore(pi, xmlroot)219 return minidom Object220 221 222 def get ProcessingInstructions(self, XMLreaderObject):218 pi = minidom_object.createProcessingInstruction(item, dic[item]) 219 minidom_object.insertBefore(pi, xmlroot) 220 return minidom_object 221 222 223 def get_processing_instructions(self, xml_reader_object): 223 224 dict = {} 224 pi = XMLreaderObject.xmlroot.getprevious()225 pi = xml_reader_object.xmlroot.getprevious() 225 226 i = 0 226 227 while pi is not None:
Note: See TracChangeset
for help on using the changeset viewer.