- Timestamp:
- Aug 31, 2018 7:13:23 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- c1cfa80
- Parents:
- aa1db44
- Location:
- test
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
test/corfunc/test/utest_corfunc.py
r86ba9d6 r3a473ef 4 4 from __future__ import division, print_function 5 5 6 import os.path 6 7 import unittest 7 8 import time … … 11 12 from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator 12 13 from sas.sascalc.dataloader.data_info import Data1D 14 15 16 def find(filename): 17 return os.path.join(os.path.dirname(__file__), filename) 13 18 14 19 … … 31 36 self.extrapolation = None 32 37 self.transformation = None 33 self.results = [np.loadtxt(fi lename+"_out.txt").T[2]38 self.results = [np.loadtxt(find(filename+"_out.txt")).T[2] 34 39 for filename in ("gamma1", "gamma3", "idf")] 35 40 … … 69 74 while True: 70 75 time.sleep(0.001) 71 if not self.calculator.transform_isrunning(): 76 if (not self.calculator.transform_isrunning() and 77 self.transformation is not None): 72 78 break 73 79 74 def transform_callback(self, transforms): 75 transform1, transform3, idf = transforms 80 transform1, transform3, idf = self.transformation 76 81 self.assertIsNotNone(transform1) 77 82 self.assertAlmostEqual(transform1.y[0], 1) 78 83 self.assertAlmostEqual(transform1.y[-1], 0, 5) 84 85 def transform_callback(self, transforms): 79 86 self.transformation = transforms 80 87 … … 110 117 111 118 def load_data(filename="98929.txt"): 112 data = np.loadtxt(fi lename, dtype=np.float64)119 data = np.loadtxt(find(filename), dtype=np.float64) 113 120 q = data[:,0] 114 121 iq = data[:,1] -
test/fileconverter/test/utest_nxcansas_writer.py
r5a8cdbb r3a473ef 3 3 4 4 import os 5 import pylint5 import os.path 6 6 import unittest 7 7 import warnings 8 8 9 9 warnings.simplefilter("ignore") 10 11 12 def find(filename): 13 return os.path.join(os.path.dirname(__file__), filename) 14 10 15 11 16 class nxcansas_writer(unittest.TestCase): … … 14 19 self.loader = Loader() 15 20 self.writer = NXcanSASWriter() 16 self.read_file_1d = "cansas1d.xml"17 self.write_file_1d = "export1d.h5"18 self.read_file_2d = "exp18_14_igor_2dqxqy.dat"19 self.write_file_2d = "export2d.h5"21 self.read_file_1d = find("cansas1d.xml") 22 self.write_file_1d = find("export1d.h5") 23 self.read_file_2d = find("exp18_14_igor_2dqxqy.dat") 24 self.write_file_2d = find("export2d.h5") 20 25 21 26 self.data_1d = self.loader.load(self.read_file_1d)[0] -
test/pr_inversion/test/utest_explorer.py
r959eb01 r3a473ef 3 3 """ 4 4 5 import os.path 5 6 import unittest, math, numpy 6 7 from utest_invertor import load 7 8 from sas.sascalc.pr.invertor import Invertor 8 9 from sas.sascalc.pr.distance_explorer import DistExplorer 9 10 11 12 def find(filename): 13 return os.path.join(os.path.dirname(__file__), filename) 14 15 10 16 class TestExplorer(unittest.TestCase): 11 17 12 18 def setUp(self): 13 19 self.invertor = Invertor() 14 x, y, err = load( 'sphere_80.txt')20 x, y, err = load(find('sphere_80.txt')) 15 21 16 22 # Choose the right d_max... -
test/pr_inversion/test/utest_invertor.py
rcb62bd5 r3a473ef 10 10 11 11 import os 12 import os.path 12 13 import unittest 13 14 import math 14 15 import numpy 15 16 from sas.sascalc.pr.invertor import Invertor 17 18 19 def find(filename): 20 return os.path.join(os.path.dirname(__file__), filename) 16 21 17 22 … … 28 33 self.x_in[i] = 1.0*(i+1) 29 34 30 x, y, err = load( "sphere_80.txt")35 x, y, err = load(find("sphere_80.txt")) 31 36 32 37 # Choose the right d_max... … … 192 197 Test an inversion for which we know the answer 193 198 """ 194 x, y, err = load( "sphere_80.txt")199 x, y, err = load(find("sphere_80.txt")) 195 200 196 201 # Choose the right d_max... … … 247 252 Test an inversion for which we know the answer 248 253 """ 249 x, y, err = load( "sphere_80.txt")254 x, y, err = load(find("sphere_80.txt")) 250 255 251 256 # Choose the right d_max... … … 312 317 Test error condition where a point has q=0 313 318 """ 314 x, y, err = load( "sphere_80.txt")319 x, y, err = load(find("sphere_80.txt")) 315 320 x[0] = 0.0 316 321 … … 329 334 Test error condition where a point has q<0 330 335 """ 331 x, y, err = load( "sphere_80.txt")336 x, y, err = load(find("sphere_80.txt")) 332 337 x[0] = -0.2 333 338 … … 353 358 Test error condition where a point has q<0 354 359 """ 355 x, y, err = load( "sphere_80.txt")360 x, y, err = load(find("sphere_80.txt")) 356 361 y[0] = 0.0 357 362 … … 374 379 375 380 def no_test_time(self): 376 x, y, err = load( "sphere_80.txt")381 x, y, err = load(find("sphere_80.txt")) 377 382 378 383 # Choose the right d_max... … … 406 411 407 412 def test_save(self): 408 x, y, err = load( "sphere_80.txt")413 x, y, err = load(find("sphere_80.txt")) 409 414 410 415 # Choose the right d_max... … … 464 469 Test an inversion for which we know the answer 465 470 """ 466 x, y, err = load( "data_error_1.txt")471 x, y, err = load(find("data_error_1.txt")) 467 472 468 473 # Choose the right d_max... … … 482 487 Have zero as an error should raise an exception 483 488 """ 484 x, y, err = load( "data_error_2.txt")489 x, y, err = load(find("data_error_2.txt")) 485 490 486 491 # Set data … … 495 500 Test an inversion for which we know the answer 496 501 """ 497 x, y, err = load( "data_error_1.txt")502 x, y, err = load(find("data_error_1.txt")) 498 503 499 504 # Set data … … 511 516 An exception should be raised. 512 517 """ 513 x, y, err = load( "data_error_3.txt")518 x, y, err = load(find("data_error_3.txt")) 514 519 515 520 # Set data … … 521 526 Should not complain or crash. 522 527 """ 523 x, y, err = load( "data_error_4.txt")528 x, y, err = load(find("data_error_4.txt")) 524 529 525 530 # Set data … … 535 540 Makes not sense, but should not complain or crash. 536 541 """ 537 x, y, err = load( "data_error_5.txt")542 x, y, err = load(find("data_error_5.txt")) 538 543 539 544 # Set data … … 549 554 Makes not sense, but should not complain or crash. 550 555 """ 551 x, y, err = load( "data_error_6.txt")556 x, y, err = load(find("data_error_6.txt")) 552 557 553 558 # Set data -
test/sascalculator/test/utest_sas_gen.py
r1d014cb r3a473ef 2 2 Unit tests for the sas_gen 3 3 """ 4 5 import os.path 4 6 import warnings 5 7 warnings.simplefilter("ignore") 6 8 7 9 import unittest 10 import numpy as np 11 8 12 from sas.sascalc.calculator import sas_gen 13 14 15 def find(filename): 16 return os.path.join(os.path.dirname(__file__), filename) 9 17 10 18 … … 20 28 Test .sld file loaded 21 29 """ 22 f = self.sldloader.read( "sld_file.sld")30 f = self.sldloader.read(find("sld_file.sld")) 23 31 self.assertEqual(f.pos_x[0], -40.5) 24 32 self.assertEqual(f.pos_y[0], -13.5) … … 29 37 Test .pdb file loaded 30 38 """ 31 f = self.pdbloader.read( "c60.pdb")39 f = self.pdbloader.read(find("c60.pdb")) 32 40 self.assertEqual(f.pos_x[0], -0.733) 33 41 self.assertEqual(f.pos_y[0], -1.008) … … 38 46 Test .omf file loaded 39 47 """ 40 f = self.omfloader.read( "A_Raw_Example-1.omf")48 f = self.omfloader.read(find("A_Raw_Example-1.omf")) 41 49 output = sas_gen.OMF2SLD() 42 50 output.set_data(f) … … 48 56 self.assertEqual(output.pos_z[0], 0.0) 49 57 58 def test_calculator(self): 59 """ 60 Test that the calculator calculates. 61 """ 62 f = self.omfloader.read(find("A_Raw_Example-1.omf")) 63 omf2sld = sas_gen.OMF2SLD() 64 omf2sld.set_data(f) 65 model = sas_gen.GenSAS() 66 model.set_sld_data(omf2sld.output) 67 x = np.linspace(0, 0.1, 11)[1:] 68 model.runXY([x, x]) 69 50 70 51 71 if __name__ == '__main__': -
test/sascalculator/test/utest_slit_length_calculator.py
rb09095a r3a473ef 3 3 """ 4 4 5 import os.path 5 6 import unittest 6 7 from sas.sascalc.dataloader.readers.ascii_reader import Reader 7 8 from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator \ 8 9 as calculator 10 11 12 def find(filename): 13 return os.path.join(os.path.dirname(__file__), filename) 9 14 10 15 … … 19 24 Test slit_length_calculator" 20 25 """ 21 list = self.reader.read( "beam profile.DAT")26 list = self.reader.read(find("beam profile.DAT")) 22 27 self.assertTrue(len(list) == 1) 23 28 f = list[0] -
test/sasdataloader/test/utest_abs_reader.py
r574adc7 r3a473ef 16 16 17 17 18 def find(filename): 19 return os.path.join(os.path.dirname(__file__), filename) 20 21 18 22 class abs_reader(unittest.TestCase): 19 23 20 24 def setUp(self): 21 25 reader = AbsReader() 22 data = reader.read("jan08002.ABS")23 self.data = data[0]26 self.data_list = reader.read(find("jan08002.ABS")) 27 self.data = self.data_list[0] 24 28 25 29 def test_abs_checkdata(self): … … 31 35 tests won't pass 32 36 """ 33 self.assertEqual( self.data.filename, "jan08002.ABS")37 self.assertEqual(os.path.basename(self.data.filename), "jan08002.ABS") 34 38 self.assertEqual(self.data.meta_data['loader'], "IGOR 1D") 35 39 … … 49 53 50 54 self.assertEqual(self.data.y_unit, 'cm^{-1}') 51 self.assertEqual(self.data.x[0], 0.00 2618)52 self.assertEqual(self.data.x[1], 0.0 07854)53 self.assertEqual(self.data.x[2], 0.0 1309)55 self.assertEqual(self.data.x[0], 0.008082) 56 self.assertEqual(self.data.x[1], 0.0275) 57 self.assertEqual(self.data.x[2], 0.02762) 54 58 self.assertEqual(self.data.x[126], 0.5828) 55 59 … … 69 73 def test_generic_loader(self): 70 74 # the generic loader should work as well 71 data = Loader().load( "jan08002.ABS")75 data = Loader().load(find("jan08002.ABS")) 72 76 self.assertEqual(data[0].meta_data['loader'], "IGOR 1D") 77 78 def test_usans_negative_dxl(self): 79 data_abs = Loader().load(find("sam14_cor.ABS")) 80 data_cor = Loader().load(find("sam14_cor.cor")) 81 for i in range(0, len(data_abs) - 1): 82 self.assertEquals(data_abs.x[i], data_cor.x[i]) 83 self.assertEquals(data_abs.y[i], data_cor.y[i]) 84 self.assertEquals(data_abs.dxl[i], data_cor.dxl[i]) 85 self.assertEquals(data_abs.dxw[i], data_cor.dxw[i]) 86 self.assertTrue(data_abs.dxl > 0) 87 73 88 74 89 class DanseReaderTests(unittest.TestCase): … … 76 91 def setUp(self): 77 92 reader = DANSEReader() 78 data = reader.read("MP_New.sans")79 self.data = data[0]93 self.data_list = reader.read(find("MP_New.sans")) 94 self.data = self.data_list[0] 80 95 81 96 def test_checkdata(self): … … 87 102 tests won't pass 88 103 """ 89 self.assertEqual(self.data.filename, "MP_New.sans") 104 self.assertEqual(len(self.data_list), 1) 105 self.assertEqual(os.path.basename(self.data.filename), "MP_New.sans") 90 106 self.assertEqual(self.data.meta_data['loader'], "DANSE") 91 107 … … 113 129 def test_generic_loader(self): 114 130 # the generic loader should work as well 115 data = Loader().load("MP_New.sans") 131 data = Loader().load(find("MP_New.sans")) 132 self.assertEqual(len(data), 1) 116 133 self.assertEqual(data[0].meta_data['loader'], "DANSE") 117 134 … … 121 138 def setUp(self): 122 139 reader = CANSASReader() 123 data = reader.read("cansas1d.xml")124 self.data = data[0]140 self.data_list = reader.read(find("cansas1d.xml")) 141 self.data = self.data_list[0] 125 142 126 143 def test_generic_loader(self): 127 144 # the generic loader should work as well 128 data = Loader().load("cansas1d.xml") 145 data = Loader().load(find("cansas1d.xml")) 146 self.assertEqual(len(data), 1) 129 147 self.assertEqual(data[0].meta_data['loader'], "CanSAS XML 1D") 130 148 131 149 def test_cansas_checkdata(self): 132 self.assertEqual( self.data.filename, "cansas1d.xml")150 self.assertEqual(os.path.basename(self.data.filename), "cansas1d.xml") 133 151 self._checkdata() 134 152 … … 141 159 tests won't pass 142 160 """ 161 self.assertEqual(len(self.data_list), 1) 143 162 self.assertEqual(self.data.run[0], "1234") 144 163 self.assertEqual(self.data.meta_data['loader'], "CanSAS XML 1D") … … 278 297 279 298 filename = "write_test.xml" 280 r.write(fi lename, self.data)281 data = Loader().load(fi lename)299 r.write(find(filename), self.data) 300 data = Loader().load(find(filename)) 282 301 self.data = data[0] 302 self.assertEqual(len(data), 1) 283 303 self.assertEqual(self.data.filename, filename) 284 304 self._checkdata() … … 292 312 """ 293 313 filename = "cansas1d_units.xml" 294 data = CANSASReader().read(fi lename)314 data = CANSASReader().read(find(filename)) 295 315 self.data = data[0] 316 self.assertEqual(len(data), 1) 296 317 self.assertEqual(self.data.filename, filename) 297 318 self._checkdata() … … 303 324 """ 304 325 filename = "cansas1d_badunits.xml" 305 data = CANSASReader().read(fi lename)326 data = CANSASReader().read(find(filename)) 306 327 self.data = data[0] 328 self.assertEqual(len(data), 1) 307 329 self.assertEqual(self.data.filename, filename) 308 330 # The followed should not have been loaded … … 319 341 """ 320 342 filename = "cansas1d_slit.xml" 321 data = CANSASReader().read(fi lename)343 data = CANSASReader().read(find(filename)) 322 344 self.data = data[0] 345 self.assertEqual(len(data), 1) 346 self.assertEqual(len(self.data_list), 1) 323 347 self.assertEqual(self.data.filename, filename) 324 348 self.assertEqual(self.data.run[0], "1234") -
test/sasdataloader/test/utest_ascii.py
ra78a02f r3a473ef 2 2 Unit tests for the ascii (n-column) reader 3 3 """ 4 5 import os.path 4 6 import warnings 7 import math 5 8 warnings.simplefilter("ignore") 6 9 … … 9 12 10 13 14 def find(filename): 15 return os.path.join(os.path.dirname(__file__), filename) 16 17 11 18 class ABSReaderTests(unittest.TestCase): 12 19 13 20 def setUp(self): 14 21 self.loader = Loader() 15 self.f1_list = self.loader.load( "ascii_test_1.txt")22 self.f1_list = self.loader.load(find("ascii_test_1.txt")) 16 23 self.f1 = self.f1_list[0] 17 self.f2_list = self.loader.load( "ascii_test_2.txt")24 self.f2_list = self.loader.load(find("ascii_test_2.txt")) 18 25 self.f2 = self.f2_list[0] 19 self.f3_list = self.loader.load( "ascii_test_3.txt")26 self.f3_list = self.loader.load(find("ascii_test_3.txt")) 20 27 self.f3 = self.f3_list[0] 21 self.f4_list = self.loader.load( "ascii_test_4.abs")28 self.f4_list = self.loader.load(find("ascii_test_4.abs")) 22 29 self.f4 = self.f4_list[0] 23 self.f5_list = self.loader.load( "ascii_test_5.txt")30 self.f5_list = self.loader.load(find("ascii_test_5.txt")) 24 31 self.f5 = self.f5_list[0] 25 32 … … 29 36 """ 30 37 # The length of the data is 10 38 self.assertEqual(len(self.f1_list), 1) 39 self.assertEqual(len(self.f2_list), 1) 40 self.assertEqual(len(self.f3_list), 1) 41 self.assertEqual(len(self.f4_list), 1) 42 self.assertEqual(len(self.f5_list), 1) 31 43 self.assertEqual(len(self.f1.x), 10) 32 44 self.assertEqual(self.f1.x[0],0.002618) … … 94 106 f = None 95 107 try: 96 f = self.loader.load( "ascii_test_6.txt")108 f = self.loader.load(find("ascii_test_6.txt")) 97 109 # The length of the data is 5 98 110 except: 99 111 self.assertEqual(f, None) 100 112 113 def test_nan_values(self): 114 """ 115 Test loading an ascii data file with nan values saved in x, y, or dy. 116 """ 117 f_1d = self.loader.load(find("nans_in_1d_data.dat"))[0] 118 f_2d = self.loader.load(find("nans_in_2d_data.DAT"))[0] 119 for i in range(0, len(f_1d.x) - 1): 120 self.assertFalse(math.isnan(f_1d.x[i])) 121 self.assertFalse(math.isnan(f_1d.y[i])) 122 self.assertFalse(math.isnan(f_1d.dy[i])) 123 f_2d.data = f_2d.data.flatten() 124 f_2d.qx_data = f_2d.qx_data.flatten() 125 f_2d.qy_data = f_2d.qy_data.flatten() 126 for i in range(0, len(f_2d.data) - 1): 127 self.assertFalse(math.isnan(f_2d.data[i])) 128 self.assertFalse(math.isnan(f_2d.qx_data[i])) 129 self.assertFalse(math.isnan(f_2d.qy_data[i])) 130 131 101 132 if __name__ == '__main__': 102 133 unittest.main() -
test/sasdataloader/test/utest_averaging.py
r2a52b0e r3a473ef 13 13 SlabY, get_q, 14 14 reader2D_converter) 15 16 17 def find(filename): 18 return os.path.join(os.path.dirname(__file__), filename) 15 19 16 20 … … 102 106 103 107 def setUp(self): 104 filepath = os.path.join(os.path.dirname(105 os.path.realpath(__file__)), 'MAR07232_rest.h5')106 self.data = Loader().load(filepath)[0]108 filepath = find('MAR07232_rest.h5') 109 self.data_list = Loader().load(filepath) 110 self.data = self.data_list[0] 107 111 108 112 def test_ring(self): … … 117 121 118 122 o = r(self.data) 119 filepath = os.path.join(os.path.dirname( 120 os.path.realpath(__file__)), 'ring_testdata.txt') 121 answer = Loader().load(filepath)[0] 122 123 filepath = find('ring_testdata.txt') 124 answer_list = Loader().load(filepath) 125 answer = answer_list[0] 126 127 self.assertEqual(len(answer_list), 1) 123 128 for i in range(r.nbins_phi - 1): 124 129 self.assertAlmostEqual(o.x[i + 1], answer.x[i], 4) … … 137 142 o = r(self.data) 138 143 139 filepath = os.path.join(os.path.dirname( 140 os.path.realpath(__file__)), 'avg_testdata.txt') 144 filepath = find('avg_testdata.txt') 141 145 answer = Loader().load(filepath)[0] 142 146 for i in range(r.nbins_phi): … … 173 177 o = r(self.data) 174 178 175 filepath = os.path.join(os.path.dirname( 176 os.path.realpath(__file__)), 'slabx_testdata.txt') 179 filepath = find('slabx_testdata.txt') 177 180 answer = Loader().load(filepath)[0] 178 181 for i in range(len(o.x)): … … 192 195 o = r(self.data) 193 196 194 filepath = os.path.join(os.path.dirname( 195 os.path.realpath(__file__)), 'slaby_testdata.txt') 197 filepath = find('slaby_testdata.txt') 196 198 answer = Loader().load(filepath)[0] 197 199 for i in range(len(o.x)): … … 219 221 o = r(self.data) 220 222 221 filepath = os.path.join(os.path.dirname( 222 os.path.realpath(__file__)), 'ring_testdata.txt') 223 filepath = find('ring_testdata.txt') 223 224 answer = Loader().load(filepath)[0] 224 225 for i in range(len(o.x)): … … 237 238 o = r(self.data) 238 239 239 filepath = os.path.join(os.path.dirname( 240 os.path.realpath(__file__)), 'sectorphi_testdata.txt') 240 filepath = find('sectorphi_testdata.txt') 241 241 answer = Loader().load(filepath)[0] 242 242 for i in range(len(o.x)): … … 255 255 o = r(self.data) 256 256 257 filepath = os.path.join(os.path.dirname( 258 os.path.realpath(__file__)), 'sectorq_testdata.txt') 257 filepath = find('sectorq_testdata.txt') 259 258 answer = Loader().load(filepath)[0] 260 259 for i in range(len(o.x)): -
test/sasdataloader/test/utest_cansas.py
rf00072f r3a473ef 31 31 CANSAS_NS = CansasConstants.CANSAS_NS 32 32 33 34 def find(filename): 35 return os.path.join(os.path.dirname(__file__), filename) 36 37 33 38 class cansas_reader_xml(unittest.TestCase): 34 39 35 40 def setUp(self): 36 41 self.loader = Loader() 37 self.xml_valid = "cansas_test_modified.xml"38 self.xml_invalid = "cansas_test.xml"39 self.cansas1d_badunits = "cansas1d_badunits.xml"40 self.cansas1d = "cansas1d.xml"41 self.cansas1d_slit = "cansas1d_slit.xml"42 self.cansas1d_units = "cansas1d_units.xml"43 self.cansas1d_notitle = "cansas1d_notitle.xml"44 self.isis_1_0 = "ISIS_1_0.xml"45 self.isis_1_1 = "ISIS_1_1.xml"46 self.isis_1_1_notrans = "ISIS_1_1_notrans.xml"47 self.isis_1_1_doubletrans = "ISIS_1_1_doubletrans.xml"48 self.schema_1_0 = "cansas1d_v1_0.xsd"49 self.schema_1_1 = "cansas1d_v1_1.xsd"50 self.write_1_0_filename = "isis_1_0_write_test.xml"51 self.write_1_1_filename = "isis_1_1_write_test.xml"42 self.xml_valid = find("cansas_test_modified.xml") 43 self.xml_invalid = find("cansas_test.xml") 44 self.cansas1d_badunits = find("cansas1d_badunits.xml") 45 self.cansas1d = find("cansas1d.xml") 46 self.cansas1d_slit = find("cansas1d_slit.xml") 47 self.cansas1d_units = find("cansas1d_units.xml") 48 self.cansas1d_notitle = find("cansas1d_notitle.xml") 49 self.isis_1_0 = find("ISIS_1_0.xml") 50 self.isis_1_1 = find("ISIS_1_1.xml") 51 self.isis_1_1_notrans = find("ISIS_1_1_notrans.xml") 52 self.isis_1_1_doubletrans = find("ISIS_1_1_doubletrans.xml") 53 self.schema_1_0 = find("cansas1d_v1_0.xsd") 54 self.schema_1_1 = find("cansas1d_v1_1.xsd") 55 self.write_1_0_filename = find("isis_1_0_write_test.xml") 56 self.write_1_1_filename = find("isis_1_1_write_test.xml") 52 57 53 58 def get_number_of_entries(self, dictionary, name, i): … … 254 259 def setUp(self): 255 260 self.loader = Loader() 256 self.datafile_basic = "simpleexamplefile.h5"257 self.datafile_multiplesasentry = "cansas_1Dand2D_samedatafile.h5"258 self.datafile_multiplesasdata = "cansas_1Dand2D_samesasentry.h5"259 self.datafile_multiplesasdata_multiplesasentry = "cansas_1Dand2D_multiplesasentry_multiplesasdata.h5"261 self.datafile_basic = find("simpleexamplefile.h5") 262 self.datafile_multiplesasentry = find("cansas_1Dand2D_samedatafile.h5") 263 self.datafile_multiplesasdata = find("cansas_1Dand2D_samesasentry.h5") 264 self.datafile_multiplesasdata_multiplesasentry = find("cansas_1Dand2D_multiplesasentry_multiplesasdata.h5") 260 265 261 266 def test_real_data(self): -
test/sasdataloader/test/utest_extension_registry.py
rdcb91cf r3a473ef 13 13 logger = logging.getLogger(__name__) 14 14 15 16 def find(filename): 17 return os.path.join(os.path.dirname(__file__), filename) 18 19 15 20 class ExtensionRegistryTests(unittest.TestCase): 16 21 17 22 def setUp(self): 18 self.valid_file = "valid_cansas_xml.xml"19 self.valid_file_wrong_known_ext = "valid_cansas_xml.txt"20 self.valid_file_wrong_unknown_ext = "valid_cansas_xml.xyz"23 self.valid_file = find("valid_cansas_xml.xml") 24 self.valid_file_wrong_known_ext = find("valid_cansas_xml.txt") 25 self.valid_file_wrong_unknown_ext = find("valid_cansas_xml.xyz") 21 26 shutil.copyfile(self.valid_file, self.valid_file_wrong_known_ext) 22 27 shutil.copyfile(self.valid_file, self.valid_file_wrong_unknown_ext) 23 self.invalid_file = "cansas1d_notitle.xml"28 self.invalid_file = find("cansas1d_notitle.xml") 24 29 25 30 self.loader = Loader() -
test/sasdataloader/test/utest_generic_file_reader_class.py
rbeba407 r3a473ef 8 8 import numpy as np 9 9 10 from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D 10 from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D, Data1D 11 from sas.sascalc.dataloader.loader import Loader 12 from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 11 13 from sas.sascalc.dataloader.file_reader_base_class import FileReader 12 14 … … 14 16 15 17 18 def find(filename): 19 return os.path.join(os.path.dirname(__file__), filename) 20 21 16 22 class GenericFileReaderTests(unittest.TestCase): 17 23 18 24 def setUp(self): 19 self.reader = FileReader() 20 self.bad_file = "ACB123.txt" 21 self.good_file = "123ABC.txt" 22 self.msg = "Unable to find file at: {}\n".format(self.bad_file) 23 self.msg += "Please check your file path and try again." 24 x = np.zeros(0) 25 y = np.zeros(0) 26 self.reader.current_dataset = plottable_1D(x, y) 27 self.reader.current_datainfo = DataInfo() 28 self.reader.send_to_output() 25 self.reader = TestFileReader() 26 self.bad_file = find("ACB123.txt") 27 self.good_file = find("123ABC.txt") 28 self.generic_reader = Loader() 29 self.deprecated_file_type = find("FEB18012.ASC") 29 30 30 31 def test_bad_file_path(self): 31 output = self.reader.read(self.bad_file) 32 self.assertEqual(len(output[0].errors), 1) 33 self.assertEqual(output[0].errors[0], self.msg) 32 self.assertRaises(NoKnownLoaderException, self.reader.read, 33 self.bad_file) 34 34 35 35 def test_good_file_path(self): 36 f_open = open(self.good_file, 'w') 37 f_open.close() 36 f = open(self.good_file, 'w') 37 f.write('123ABC exists!') 38 f.close() 38 39 output = self.reader.read(self.good_file) 39 self.assertEqual(len(output[0].errors), 1) 40 self.assertEqual(output[0].errors[0], self.msg) 40 self.assertEqual(len(output), 1) 41 self.assertEqual(output[0].meta_data["blah"], '123ABC exists!') 42 43 def test_old_file_types(self): 44 f = self.generic_reader.load(self.deprecated_file_type) 45 last_f = f[0] 46 if hasattr(last_f, "errors"): 47 self.assertEquals(len(last_f.errors), 1) 48 else: 49 self.fail("Errors did not propogate to the file properly.") 50 51 def test_same_file_unknown_extensions(self): 52 # Five files, all with the same content, but different file extensions 53 no_ext = find("test_data//TestExtensions") 54 not_xml = find("test_data//TestExtensions.notxml") 55 # Deprecated extensions 56 asc_dep = find("test_data//TestExtensions.asc") 57 nxs_dep = find("test_data//TestExtensions.nxs") 58 # Native extension as a baseline 59 xml_native = find("test_data//TestExtensions.xml") 60 # Load the files and check contents 61 no_ext_load = self.generic_reader.load(no_ext) 62 asc_load = self.generic_reader.load(asc_dep) 63 nxs_load = self.generic_reader.load(nxs_dep) 64 not_xml_load = self.generic_reader.load(not_xml) 65 xml_load = self.generic_reader.load(xml_native) 66 self.check_unknown_extension(no_ext_load[0]) 67 self.check_unknown_extension(asc_load[0]) 68 self.check_unknown_extension(nxs_load[0]) 69 self.check_unknown_extension(not_xml_load[0]) 70 self.check_unknown_extension(xml_load[0]) 71 # Be sure the deprecation warning is passed with the file 72 self.assertEquals(len(asc_load[0].errors), 1) 73 self.assertEquals(len(nxs_load[0].errors), 1) 74 75 def check_unknown_extension(self, data): 76 self.assertTrue(isinstance(data, Data1D)) 77 self.assertEquals(len(data.x), 138) 78 self.assertEquals(data.sample.ID, "TK49 c10_SANS") 79 self.assertEquals(data.meta_data["loader"], "CanSAS XML 1D") 41 80 42 81 def tearDown(self): … … 45 84 if os.path.isfile(self.good_file): 46 85 os.remove(self.good_file) 86 87 class TestFileReader(FileReader): 88 def get_file_contents(self): 89 """ 90 Reader specific class to access the contents of the file 91 All reader classes that inherit from FileReader must implement 92 """ 93 x = np.zeros(0) 94 y = np.zeros(0) 95 self.current_dataset = plottable_1D(x,y) 96 self.current_datainfo = DataInfo() 97 self.current_datainfo.meta_data["blah"] = self.nextline() 98 self.send_to_output() -
test/sasdataloader/test/utest_red2d_reader.py
r248ff73 r3a473ef 10 10 import os.path 11 11 12 13 def find(filename): 14 return os.path.join(os.path.dirname(__file__), filename) 15 16 12 17 class abs_reader(unittest.TestCase): 13 18 14 19 def setUp(self): 15 20 self.loader = Loader() 21 self.data_list = self.loader.load(find("exp18_14_igor_2dqxqy.dat")) 16 22 17 23 def test_checkdata(self): … … 19 25 Test .DAT file loaded as IGOR/DAT 2D Q_map 20 26 """ 21 f = self. loader.load("exp18_14_igor_2dqxqy.dat")[0]27 f = self.data_list[0] 22 28 # The length of the data is 10 29 self.assertEqual(len(self.data_list), 1) 23 30 self.assertEqual(len(f.qx_data), 36864) 24 31 self.assertEqual(f.qx_data[0],-0.03573497) -
test/sasdataloader/test/utest_sesans.py
ra78a02f r3a473ef 3 3 """ 4 4 5 import os.path 5 6 import unittest 6 7 from sas.sascalc.dataloader.loader_exceptions import FileContentsException,\ … … 8 9 from sas.sascalc.dataloader.readers.sesans_reader import Reader 9 10 from sas.sascalc.dataloader.loader import Loader 11 12 13 def find(filename): 14 return os.path.join(os.path.dirname(__file__), filename) 15 10 16 11 17 class sesans_reader(unittest.TestCase): … … 19 25 Test .SES in the full loader to make sure that the file type is correctly accepted 20 26 """ 21 file = Loader().load( "sesans_examples/sphere2micron.ses")27 file = Loader().load(find("sesans_examples/sphere2micron.ses")) 22 28 f = file[0] 23 29 # self.assertEqual(f, 5) 30 self.assertEqual(len(file), 1) 24 31 self.assertEqual(len(f.x), 40) 25 32 self.assertEqual(f.x[0], 391.56) … … 37 44 Test .SES loading on a TOF dataset 38 45 """ 39 file = self.loader( "sesans_examples/sphere_isis.ses")46 file = self.loader(find("sesans_examples/sphere_isis.ses")) 40 47 f = file[0] 48 self.assertEqual(len(file), 1) 41 49 self.assertEqual(len(f.x), 57) 42 50 self.assertEqual(f.x[-1], 19303.4) … … 54 62 FileContentsException, 55 63 self.loader, 56 "sesans_examples/sesans_no_data.ses")64 find("sesans_examples/sesans_no_data.ses")) 57 65 58 66 def test_sesans_no_spin_echo_unit(self): … … 63 71 FileContentsException, 64 72 self.loader, 65 "sesans_examples/no_spin_echo_unit.ses")73 find("sesans_examples/no_spin_echo_unit.ses")) 66 74 67 75 def test_sesans_future_version(self): … … 72 80 FileContentsException, 73 81 self.loader, 74 "sesans_examples/next_gen.ses")82 find("sesans_examples/next_gen.ses")) 75 83 76 84 def test_sesans_mandatory_headers(self): … … 81 89 FileContentsException, 82 90 self.loader, 83 "sesans_examples/no_wavelength.ses")91 find("sesans_examples/no_wavelength.ses")) 84 92 85 93 def test_sesans_columns_match_headers(self): … … 90 98 FileContentsException, 91 99 self.loader, 92 "sesans_examples/too_many_headers.ses")100 find("sesans_examples/too_many_headers.ses")) 93 101 94 102 if __name__ == "__main__": -
test/sasguiframe/test/utest_manipulations.py
rc0ca2e3d r3a473ef 15 15 16 16 17 def find(filename): 18 return os.path.join(os.path.dirname(__file__), filename) 19 20 17 21 class DataInfoTests(unittest.TestCase): 18 22 19 23 def setUp(self): 20 data = Loader().load( "cansas1d.xml")24 data = Loader().load(find("cansas1d.xml")) 21 25 self.data = data[0] 22 26 … … 35 39 36 40 def setUp(self): 37 data = Loader().load( "cansas1d.xml")41 data = Loader().load(find("cansas1d.xml")) 38 42 self.data = data[0] 39 43 -
test/sasinvariant/test/utest_data_handling.py
r9a5097c r3a473ef 8 8 copyright 2010, University of Tennessee 9 9 """ 10 11 import os.path 10 12 import unittest 11 13 import math … … 15 17 16 18 from sas.sascalc.invariant import invariant 17 19 20 21 def find(filename): 22 return os.path.join(os.path.dirname(__file__), filename) 23 24 18 25 class TestLinearFit(unittest.TestCase): 19 26 """ … … 94 101 """ 95 102 def setUp(self): 96 data = Loader().load( "latex_smeared_slit.xml")103 data = Loader().load(find("latex_smeared_slit.xml")) 97 104 self.data = data[0] 98 105 self.data.dxl = None … … 676 683 value = math.fabs(test_y[i]- temp[i])/temp[i] 677 684 self.assert_(value < 0.001) 678 -
test/sasinvariant/test/utest_use_cases.py
rb09095a r3a473ef 4 4 """ 5 5 #TODO: there's no test for smeared extrapolation 6 7 import os.path 6 8 import unittest 7 9 from sas.sascalc.dataloader.loader import Loader … … 9 11 10 12 13 def find(filename): 14 return os.path.join(os.path.dirname(__file__), filename) 15 16 11 17 class Data1D: 12 18 pass … … 18 24 """ 19 25 def setUp(self): 20 self.data_list = Loader().load( "linefittest.txt")26 self.data_list = Loader().load(find("linefittest.txt")) 21 27 self.data = self.data_list[0] 22 28 … … 57 63 """ 58 64 def setUp(self): 59 self.data_list = Loader().load( "linefittest_no_weight.txt")65 self.data_list = Loader().load(find("linefittest_no_weight.txt")) 60 66 self.data = self.data_list[0] 61 67 … … 96 102 """ 97 103 def setUp(self): 98 self.data_list = Loader().load( "PolySpheres.txt")104 self.data_list = Loader().load(find("PolySpheres.txt")) 99 105 self.data = self.data_list[0] 100 106 … … 278 284 def setUp(self): 279 285 # data with smear info 280 list = Loader().load( "latex_smeared.xml")286 list = Loader().load(find("latex_smeared.xml")) 281 287 self.data_q_smear = list[0] 282 288
Note: See TracChangeset
for help on using the changeset viewer.