Changeset 132db16 in sasview for test/sasdataloader
- Timestamp:
- Sep 15, 2016 8:33:57 AM (8 years ago)
- Branches:
- 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
- Children:
- ef51b63
- Parents:
- fac2619
- git-author:
- Jeff Krzywon <krzywon@…> (08/04/16 13:37:51)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (09/15/16 08:33:57)
- Location:
- test/sasdataloader/test
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/sasdataloader/test/utest_cansas.py
rb699768 r132db16 2 2 Unit tests for the new recursive cansas reader 3 3 """ 4 import logging5 import warnings6 warnings.simplefilter("ignore")7 8 4 import sas.sascalc.dataloader.readers.cansas_reader as cansas 9 5 from sas.sascalc.dataloader.loader import Loader 10 from sas.sascalc.dataloader.data_info import Data1D 6 from sas.sascalc.dataloader.data_info import Data1D, Data2D 11 7 from sas.sascalc.dataloader.readers.xml_reader import XMLreader 12 8 from sas.sascalc.dataloader.readers.cansas_reader import Reader … … 20 16 import unittest 21 17 import numpy 18 import logging 19 import warnings 22 20 23 21 from lxml import etree 24 22 from xml.dom import minidom 25 23 24 warnings.simplefilter("ignore") 25 26 26 CANSAS_FORMAT = CansasConstants.CANSAS_FORMAT 27 27 CANSAS_NS = CansasConstants.CANSAS_NS 28 29 class cansas_reader (unittest.TestCase):30 28 29 class cansas_reader_xml(unittest.TestCase): 30 31 31 def setUp(self): 32 32 self.loader = Loader() … … 43 43 self.schema_1_0 = "cansas1d_v1_0.xsd" 44 44 self.schema_1_1 = "cansas1d_v1_1.xsd" 45 46 45 46 47 47 def get_number_of_entries(self, dictionary, name, i): 48 48 if dictionary.get(name) is not None: … … 52 52 name = self.get_number_of_entries(dictionary, name, i) 53 53 return name 54 55 54 55 56 56 def test_invalid_xml(self): 57 57 """ … … 60 60 invalid = StringIO.StringIO('<a><c></b></a>') 61 61 reader = XMLreader(invalid) 62 62 63 63 64 64 def test_xml_validate(self): … … 78 78 self.assertTrue(xmlschema.validate(valid)) 79 79 self.assertFalse(xmlschema.validate(invalid)) 80 81 80 81 82 82 def test_real_xml(self): 83 83 reader = XMLreader(self.xml_valid, self.schema_1_0) … … 87 87 else: 88 88 self.assertFalse(valid) 89 90 89 90 91 91 def _check_data(self, data): 92 92 self.assertTrue(data.title == "TK49 c10_SANS") … … 101 101 self.assertTrue(data.process[0].name == "Mantid generated CanSAS1D XML") 102 102 self.assertTrue(data.meta_data["xmlpreprocess"] != None) 103 104 103 104 105 105 def _check_data_1_1(self, data): 106 106 spectrum = data.trans_spectrum[0] 107 107 self.assertTrue(len(spectrum.wavelength) == 138) 108 109 108 109 110 110 def test_cansas_xml(self): 111 111 filename = "isis_1_1_write_test.xml" … … 132 132 written_data = return_data[0] 133 133 self._check_data(written_data) 134 135 134 135 136 136 def test_double_trans_spectra(self): 137 137 xmlreader = XMLreader(self.isis_1_1_doubletrans, self.schema_1_1) … … 141 141 for item in data: 142 142 self._check_data(item) 143 144 143 144 145 145 def test_entry_name_recurse(self): 146 146 test_values = [1,2,3,4,5,6] … … 151 151 d[new_key] = value 152 152 self.assertTrue(len(d) == 6) 153 154 153 154 155 155 def test_load_cansas_file(self): 156 156 valid = [] … … 169 169 reader7 = XMLreader(self.isis_1_1, self.schema_1_0) 170 170 self.assertFalse(reader7.validate_xml()) 171 172 171 172 173 173 def test_old_cansas_files(self): 174 174 reader1 = XMLreader(self.cansas1d, self.schema_1_0) … … 182 182 reader4 = XMLreader(self.cansas1d_slit, self.schema_1_0) 183 183 self.assertTrue(reader4.validate_xml()) 184 185 184 185 186 186 def test_save_cansas_v1_0(self): 187 187 filename = "isis_1_0_write_test.xml" … … 204 204 self.assertTrue(valid) 205 205 self._check_data(written_data) 206 207 206 207 208 208 def test_processing_instructions(self): 209 209 reader = XMLreader(self.isis_1_1, self.schema_1_1) … … 214 214 self.assertTrue(dic == {'xml-stylesheet': \ 215 215 'type="text/xsl" href="cansas1d.xsl" '}) 216 216 217 217 xml = "<test><a><b><c></c></b></a></test>" 218 218 xmldoc = minidom.parseString(xml) 219 219 220 220 ## take the processing instructions and put them back in 221 221 xmldoc = self.set_processing_instructions(xmldoc, dic) 222 222 xml_output = xmldoc.toprettyxml() 223 224 223 224 225 225 def set_processing_instructions(self, minidom_object, dic): 226 226 xmlroot = minidom_object.firstChild … … 229 229 minidom_object.insertBefore(pi, xmlroot) 230 230 return minidom_object 231 232 231 232 233 233 def get_processing_instructions(self, xml_reader_object): 234 234 dict = {} … … 247 247 pi = pi.getprevious() 248 248 return dict 249 249 250 251 class cansas_reader_hdf5(unittest.TestCase): 252 253 def setUp(self): 254 self.loader = Loader() 255 self.datafile_basic = "simpleexamplefile.h5" 256 self.datafile_multiplesasentry = "cansas_1Dand2D_samedatafile.h5" 257 self.datafile_multiplesasdata = "cansas_1Dand2D_samesasentry.h5" 258 self.datafile_multiplesasdata_multiplesasentry = "cansas_1Dand2D_multiplesasentry_multiplesasdata.h5" 259 260 def test_real_data(self): 261 self.data = self.loader.load(self.datafile_basic) 262 self._check_example_data(self.data[0]) 263 264 def test_multiple_sasentries(self): 265 self.data = self.loader.load(self.datafile_multiplesasentry) 266 self.assertTrue(len(self.data) == 2) 267 self._check_multiple_data(self.data[0]) 268 self._check_multiple_data(self.data[1]) 269 self._check_1d_data(self.data[0]) 270 271 def _check_multiple_data(self, data): 272 self.assertTrue(data.title == "MH4_5deg_16T_SLOW") 273 self.assertTrue(data.run[0] == '33837') 274 self.assertTrue(len(data.run) == 1) 275 self.assertTrue(data.instrument == "SANS2D") 276 self.assertTrue(data.source.radiation == "Spallation Neutron Source") 277 self.assertTrue(len(data.detector) == 1) 278 self.assertTrue(data.detector[0].name == "rear-detector") 279 self.assertTrue(data.detector[0].distance == 4.385281) 280 self.assertTrue(data.detector[0].distance_unit == 'm') 281 self.assertTrue(len(data.trans_spectrum) == 1) 282 283 def _check_1d_data(self, data): 284 self.assertTrue(isinstance(data, Data1D)) 285 self.assertTrue(len(data.x) == 66) 286 self.assertTrue(len(data.x) == len(data.y)) 287 self.assertTrue(data.dy[10] == 0.20721350111248701) 288 self.assertTrue(data.y[10] == 24.193889608153476) 289 self.assertTrue(data.x[10] == 0.008981127988654792) 290 291 def _check_2d_data(self, data): 292 self.assertTrue(isinstance(data, Data2D)) 293 self.assertTrue(len(data.x) == 66) 294 self.assertTrue(len(data.x) == len(data.y)) 295 self.assertTrue(data.dy[10] == 0.20721350111248701) 296 self.assertTrue(data.y[10] == 24.193889608153476) 297 self.assertTrue(data.x[10] == 0.008981127988654792) 298 299 def _check_example_data(self, data): 300 self.assertTrue(data.title == "") 301 self.assertTrue(data.x.size == 100) 302 self.assertTrue(data._xunit == "A^{-1}") 303 self.assertTrue(data._yunit == "cm^{-1}") 304 self.assertTrue(data.y.size == 100) 305 self.assertAlmostEqual(data.y[9], 0.952749011516985) 306 self.assertAlmostEqual(data.x[9], 0.3834415188257777) 307 self.assertAlmostEqual(len(data.meta_data), 0) 308 250 309 251 310 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.