- Timestamp:
- May 2, 2017 8:07:40 AM (8 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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- e123eb9
- Parents:
- b290a9e (diff), 658dd57 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- test
- Files:
-
- 19 added
- 3 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
test/fileconverter/test/utest_nxcansas_writer.py
rc476457 r17c9436 66 66 if os.path.isfile(self.write_file_1d): 67 67 os.remove(self.write_file_1d) 68 if os.path.isfile(self.write_file_2d): 69 os.remove(self.write_file_2d) -
test/pr_inversion/test/utest_invertor.py
rac07a3a raaf5e49 6 6 # Disable "too many methods" complaint 7 7 # pylint: disable-msg=R0904 8 9 10 import unittest, math, numpy 8 from __future__ import print_function 9 10 11 import os 12 import unittest 13 import math 14 import numpy 11 15 from sas.sascalc.pr.invertor import Invertor 12 16 17 13 18 class TestFiguresOfMerit(unittest.TestCase): 14 19 … … 235 240 self.assertTrue(chi2/51.0<10.0) 236 241 except: 237 print "chi2 =", chi2/51.0242 print("chi2 =", chi2/51.0) 238 243 raise 239 244 … … 263 268 self.assertTrue(self.invertor.chi2/len(x)<200.00) 264 269 except: 265 print "Chi2(I(q)) =", self.invertor.chi2/len(x)270 print("Chi2(I(q)) =", self.invertor.chi2/len(x)) 266 271 raise 267 272 … … 297 302 self.assertTrue(chi2/51.0<50.0) 298 303 except: 299 print "chi2(P(r)) =", chi2/51.0304 print("chi2(P(r)) =", chi2/51.0) 300 305 raise 301 306 … … 341 346 self.assertTrue(self.invertor.chi2>0) 342 347 except: 343 print "Chi2 =", self.invertor.chi2348 print("Chi2 =", self.invertor.chi2) 344 349 raise 345 350 … … 365 370 self.assertTrue(self.invertor.chi2>0) 366 371 except: 367 print "Chi2 =", self.invertor.chi2372 print("Chi2 =", self.invertor.chi2) 368 373 raise 369 374 … … 416 421 417 422 # Save 418 self.invertor.to_file("test_output.txt") 423 f_name = "test_output.txt" 424 self.invertor.to_file(f_name) 419 425 420 426 # Load 421 self.invertor.from_file( "test_output.txt")427 self.invertor.from_file(f_name) 422 428 self.assertEqual(self.invertor.d_max, 160.0) 423 429 self.assertEqual(self.invertor.alpha, 0.0007) 424 430 self.assertEqual(self.invertor.chi2, 836.797) 425 431 self.assertAlmostEqual(self.invertor.pr(self.invertor.out, 10.0), 903.31577041, 4) 432 if os.path.isfile(f_name): 433 os.remove(f_name) 426 434 427 435 def test_qmin(self): -
test/run_one.py
raaad4c95 raaf5e49 1 1 #!/usr/bin/env python 2 from __future__ import print_function 2 3 3 4 import os … … 24 25 #print "\n".join(sys.path) 25 26 test_path,test_file = splitpath(abspath(sys.argv[1])) 26 print "=== testing:",sys.argv[1]27 print("=== testing:",sys.argv[1]) 27 28 #print test_path, test_file 28 29 sys.argv = [sys.argv[0]] -
test/sasdataloader/plugins/test_reader.py
r959eb01 raaf5e49 8 8 copyright 2008, University of Tennessee 9 9 """ 10 from __future__ import print_function 11 10 12 import os 11 13 import numpy as np … … 59 61 reader = Reader() 60 62 output = reader.read("../test/test_data.test") 61 print output.x63 print(output.x) 62 64 63 65 -
test/sasdataloader/test/sequence_tests.py
r959eb01 raaf5e49 1 from __future__ import print_function 2 1 3 from DataLoader.loader import Loader 2 4 from DataLoader.readers.IgorReader import Reader as igor_reader … … 8 10 out2 = Loader().load("MAR07232_rest.ASC") 9 11 if len(out2.detector)>1: 10 print "Consecutive reads using Loader failed"12 print("Consecutive reads using Loader failed") 11 13 12 14 def consecutive_reader(): … … 14 16 out2 = igor_reader().read("MAR07232_rest.ASC") 15 17 if len(out2.detector)>1: 16 print "Consecutive reads using Readers failed"17 print out118 print out218 print("Consecutive reads using Readers failed") 19 print(out1) 20 print(out2) 19 21 20 22 def single_abs(): … … 29 31 single_igor() 30 32 single_abs() 31 print "Test passed"33 print("Test passed") -
test/sasdataloader/test/testplugings.py
r959eb01 r17c9436 3 3 """ 4 4 5 import os 5 6 import unittest 6 7 from sas.sascalc.dataloader.loader import Loader, Registry … … 41 42 # Create module 42 43 import zipfile 43 z = zipfile.PyZipFile("plugins.zip", 'w') 44 f_name = "plugins.zip" 45 z = zipfile.PyZipFile(f_name, 'w') 44 46 z.writepy("../plugins", "") 45 47 z.close() 48 if os.path.isfile(f_name): 49 os.remove(f_name) 46 50 47 51 def testplugin_checksetup(self): -
test/sasdataloader/test/utest_abs_reader.py
rdd11014 rc551bb3 2 2 Unit tests for data manipulations 3 3 """ 4 from __future__ import print_function 4 5 5 6 import unittest … … 8 9 from sas.sascalc.dataloader.loader import Loader 9 10 from sas.sascalc.dataloader.readers.IgorReader import Reader as IgorReader 11 from sas.sascalc.dataloader.readers.abs_reader import Reader as AbsReader 12 from sas.sascalc.dataloader.readers.hfir1d_reader import Reader as HFIRReader 13 from sas.sascalc.dataloader.readers.danse_reader import Reader as DANSEReader 14 from sas.sascalc.dataloader.readers.cansas_reader import Reader as CANSASReader 15 10 16 from sas.sascalc.dataloader.data_info import Data1D 11 17 12 18 import os.path 13 19 20 14 21 class abs_reader(unittest.TestCase): 15 22 16 23 def setUp(self): 17 from sas.sascalc.dataloader.readers.abs_reader import Reader18 self.data = Reader().read("jan08002.ABS")19 24 reader = AbsReader() 25 self.data = reader.read("jan08002.ABS") 26 20 27 def test_abs_checkdata(self): 21 28 """ … … 61 68 def test_checkdata2(self): 62 69 self.assertEqual(self.data.dy[126], 1) 63 70 71 def test_generic_loader(self): 72 # the generic loader should work as well 73 data = Loader().load("jan08002.ABS") 74 self.assertEqual(data.meta_data['loader'], "IGOR 1D") 75 76 64 77 class hfir_reader(unittest.TestCase): 65 78 66 79 def setUp(self): 67 self.data = Loader().load("S2-30dq.d1d") 68 80 reader = HFIRReader() 81 self.data = reader.read("S2-30dq.d1d") 82 69 83 def test_hfir_checkdata(self): 70 84 """ … … 83 97 self.assertEqual(self.data.dy[1], 0.000315) 84 98 self.assertEqual(self.data.dx[1], 0.008249) 85 99 100 def test_generic_loader(self): 101 # the generic loader should work as well 102 data = Loader().load("S2-30dq.d1d") 103 self.assertEqual(data.meta_data['loader'], "HFIR 1D") 104 86 105 87 106 class igor_reader(unittest.TestCase): … … 137 156 138 157 def setUp(self): 139 self.data = Loader().load("MP_New.sans") 158 reader = DANSEReader() 159 self.data = reader.read("MP_New.sans") 140 160 141 161 def test_checkdata(self): … … 171 191 self.assertEqual(self.data.err_data[2], 2.06313) 172 192 193 def test_generic_loader(self): 194 # the generic loader should work as well 195 data = Loader().load("MP_New.sans") 196 self.assertEqual(data.meta_data['loader'], "DANSE") 197 173 198 174 199 class cansas_reader(unittest.TestCase): 175 200 176 201 def setUp(self): 202 reader = CANSASReader() 203 data = reader.read("cansas1d.xml") 204 self.data = data[0] 205 206 def test_generic_loader(self): 207 # the generic loader should work as well 177 208 data = Loader().load("cansas1d.xml") 178 self. data = data[0]179 209 self.assertEqual(data[0].meta_data['loader'], "CanSAS XML 1D") 210 180 211 def test_cansas_checkdata(self): 181 212 self.assertEqual(self.data.filename, "cansas1d.xml") … … 190 221 tests won't pass 191 222 """ 192 193 223 self.assertEqual(self.data.run[0], "1234") 194 224 self.assertEqual(self.data.meta_data['loader'], "CanSAS XML 1D") … … 264 294 self.assertEqual(item.distance_unit,'mm') 265 295 266 if item.size.x ==50 \267 and item.distance ==11000.0 \268 and item.name =='source' \269 and item.type =='radius':296 if item.size.x == 50 \ 297 and item.distance == 11000.0 \ 298 and item.name == 'source' \ 299 and item.type == 'radius': 270 300 _found1 = True 271 elif item.size.x ==1.0 \272 and item.name =='sample' \273 and item.type =='radius':301 elif item.size.x == 1.0 \ 302 and item.name == 'sample' \ 303 and item.type == 'radius': 274 304 _found2 = True 275 305 276 if _found1 ==False or _found2==False:306 if _found1 == False or _found2 == False: 277 307 raise RuntimeError, "Could not find all data %s %s" % (_found1, _found2) 278 308 … … 309 339 self.assertTrue(item.date in ['04-Sep-2007 18:35:02', 310 340 '03-SEP-2006 11:42:47']) 311 print item.term341 print(item.term) 312 342 for t in item.term: 313 if t['name']=="ABS:DSTAND" \314 and t['unit'] =='mm' \315 and float(t['value']) ==1.0:343 if (t['name'] == "ABS:DSTAND" 344 and t['unit'] == 'mm' 345 and float(t['value']) == 1.0): 316 346 _found_term2 = True 317 elif t['name']=="radialstep" \318 and t['unit']=='mm' \319 and float(t['value'])==10.0:347 elif (t['name'] == "radialstep" 348 and t['unit'] == 'mm' 349 and float(t['value']) == 10.0): 320 350 _found_term1 = True 321 351 322 if _found_term1==False or _found_term2==False: 323 raise RuntimeError, "Could not find all process terms %s %s" % (_found_term1, _found_term2) 324 325 326 352 if _found_term1 == False or _found_term2 == False: 353 raise RuntimeError, "Could not find all process terms %s %s" % (_found_term1, _found_term2) 327 354 328 355 def test_writer(self): 329 from sas.sascalc.dataloader.readers.cansas_reader import Reader 330 r = Reader() 331 x = np.ones(5) 332 y = np.ones(5) 333 dy = np.ones(5) 334 356 r = CANSASReader() 357 335 358 filename = "write_test.xml" 336 359 r.write(filename, self.data) … … 339 362 self.assertEqual(self.data.filename, filename) 340 363 self._checkdata() 364 if os.path.isfile(filename): 365 os.remove(filename) 341 366 342 367 def test_units(self): … … 346 371 """ 347 372 filename = "cansas1d_units.xml" 348 data = Loader().load(filename)373 data = CANSASReader().read(filename) 349 374 self.data = data[0] 350 375 self.assertEqual(self.data.filename, filename) … … 357 382 """ 358 383 filename = "cansas1d_badunits.xml" 359 data = Loader().load(filename)384 data = CANSASReader().read(filename) 360 385 self.data = data[0] 361 386 self.assertEqual(self.data.filename, filename) … … 366 391 367 392 self.assertEqual(self.data.meta_data['loader'], "CanSAS XML 1D") 368 print self.data.errors393 print(self.data.errors) 369 394 self.assertEqual(len(self.data.errors), 1) 370 371 395 372 396 def test_slits(self): 373 397 """ … … 375 399 """ 376 400 filename = "cansas1d_slit.xml" 377 data = Loader().load(filename)401 data = CANSASReader().read(filename) 378 402 self.data = data[0] 379 403 self.assertEqual(self.data.filename, filename) … … 397 421 self.assertEqual(self.data.run_name['1234'], 'run name') 398 422 self.assertEqual(self.data.title, "Test title") 399 400 423 401 424 402 425 if __name__ == '__main__': -
test/sasdataloader/test/utest_cansas.py
r7432acb r1fc50fb2 46 46 self.schema_1_0 = "cansas1d_v1_0.xsd" 47 47 self.schema_1_1 = "cansas1d_v1_1.xsd" 48 48 self.write_1_0_filename = "isis_1_0_write_test.xml" 49 self.write_1_1_filename = "isis_1_1_write_test.xml" 49 50 50 51 def get_number_of_entries(self, dictionary, name, i): … … 56 57 return name 57 58 58 59 59 def test_invalid_xml(self): 60 60 """ … … 62 62 """ 63 63 invalid = StringIO.StringIO('<a><c></b></a>') 64 reader = XMLreader(invalid) 65 64 XMLreader(invalid) 66 65 67 66 def test_xml_validate(self): … … 82 81 self.assertFalse(xmlschema.validate(invalid)) 83 82 84 85 83 def test_real_xml(self): 86 84 reader = XMLreader(self.xml_valid, self.schema_1_0) … … 90 88 else: 91 89 self.assertFalse(valid) 92 93 90 94 91 def _check_data(self, data): … … 105 102 self.assertTrue(data.meta_data["xmlpreprocess"] is not None) 106 103 107 108 104 def _check_data_1_1(self, data): 109 105 spectrum = data.trans_spectrum[0] 110 106 self.assertTrue(len(spectrum.wavelength) == 138) 111 107 112 113 108 def test_cansas_xml(self): 114 filename = "isis_1_1_write_test.xml"115 109 xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) 116 110 valid = xmlreader.validate_xml() 117 111 xmlreader.set_processing_instructions() 118 112 self.assertTrue(valid) 119 fo = open(self.isis_1_1)120 str = fo.read()121 113 reader_generic = Loader() 122 114 dataloader = reader_generic.load(self.isis_1_1) … … 128 120 self._check_data(cansasreader[i]) 129 121 self._check_data_1_1(cansasreader[i]) 130 reader_generic.save(filename, dataloader[i], None) 131 fo = open(filename) 132 str = fo.read() 122 reader_generic.save(self.write_1_1_filename, dataloader[i], None) 133 123 reader2 = Loader() 134 return_data = reader2.load(filename) 124 self.assertTrue(os.path.isfile(self.write_1_1_filename)) 125 return_data = reader2.load(self.write_1_1_filename) 135 126 written_data = return_data[0] 136 127 self._check_data(written_data) 137 128 if os.path.isfile(self.write_1_1_filename): 129 os.remove(self.write_1_1_filename) 138 130 139 131 def test_double_trans_spectra(self): … … 144 136 for item in data: 145 137 self._check_data(item) 146 147 138 148 139 def test_entry_name_recurse(self): … … 155 146 self.assertTrue(len(d) == 6) 156 147 157 158 148 def test_load_cansas_file(self): 159 valid = []160 149 reader1 = XMLreader(self.xml_valid, self.schema_1_0) 161 150 self.assertTrue(reader1.validate_xml()) … … 173 162 self.assertFalse(reader7.validate_xml()) 174 163 175 176 164 def test_invalid_cansas(self): 177 165 list = self.loader.load(self.cansas1d_notitle) … … 184 172 self.assertTrue(data.detector[0].distance == 4150) 185 173 186 187 174 def test_old_cansas_files(self): 188 175 reader1 = XMLreader(self.cansas1d, self.schema_1_0) 189 176 self.assertTrue(reader1.validate_xml()) 190 177 file_loader = Loader() 191 file 1 = file_loader.load(self.cansas1d)178 file_loader.load(self.cansas1d) 192 179 reader2 = XMLreader(self.cansas1d_units, self.schema_1_0) 193 180 self.assertTrue(reader2.validate_xml()) … … 197 184 self.assertTrue(reader4.validate_xml()) 198 185 199 200 186 def test_save_cansas_v1_0(self): 201 filename = "isis_1_0_write_test.xml"202 187 xmlreader = XMLreader(self.isis_1_0, self.schema_1_0) 203 188 valid = xmlreader.validate_xml() … … 210 195 self._check_data(dataloader[i]) 211 196 self._check_data(cansasreader[i]) 212 reader_generic.save( filename, dataloader[i], None)197 reader_generic.save(self.write_1_0_filename, dataloader[i], None) 213 198 reader2 = Reader() 214 return_data = reader2.read(filename) 199 self.assertTrue(os.path.isfile(self.write_1_0_filename)) 200 return_data = reader2.read(self.write_1_0_filename) 215 201 written_data = return_data[0] 216 xmlwrite = XMLreader(filename, self.schema_1_0)202 XMLreader(self.write_1_0_filename, self.schema_1_0) 217 203 valid = xmlreader.validate_xml() 218 204 self.assertTrue(valid) 219 205 self._check_data(written_data) 220 206 if os.path.isfile(self.write_1_0_filename): 207 os.remove(self.write_1_0_filename) 221 208 222 209 def test_processing_instructions(self): … … 224 211 valid = reader.validate_xml() 225 212 if valid: 226 # #find the processing instructions and make into a dictionary213 # find the processing instructions and make into a dictionary 227 214 dic = self.get_processing_instructions(reader) 228 215 self.assertTrue(dic == {'xml-stylesheet': \ … … 232 219 xmldoc = minidom.parseString(xml) 233 220 234 # #take the processing instructions and put them back in221 # take the processing instructions and put them back in 235 222 xmldoc = self.set_processing_instructions(xmldoc, dic) 236 xml_output = xmldoc.toprettyxml() 237 223 xmldoc.toprettyxml() 238 224 239 225 def set_processing_instructions(self, minidom_object, dic): … … 243 229 minidom_object.insertBefore(pi, xmlroot) 244 230 return minidom_object 245 246 231 247 232 def get_processing_instructions(self, xml_reader_object): -
test/sasrealspace/test/early_test.py
r959eb01 raaf5e49 1 from __future__ import print_function 1 2 2 3 import VolumeCanvas … … 30 31 t_0 = time.time() 31 32 value_1 = 1.0e8*canvas.getIq(0.1) 32 print "density = 0.1: output=%g time=%g" % (value_1, time.time()-t_0)33 print("density = 0.1: output=%g time=%g" % (value_1, time.time()-t_0)) 33 34 34 35 t_0 = time.time() 35 36 canvas.setParam('lores_density', 1) 36 37 value_1 = 1.0e8*canvas.getIq(0.1) 37 print "density = 1000: output=%g time=%g" % (value_1, time.time()-t_0)38 print("density = 1000: output=%g time=%g" % (value_1, time.time()-t_0)) 38 39 39 40 t_0 = time.time() 40 41 canvas.setParam('lores_density', 0.01) 41 42 value_1 = 1.0e8*canvas.getIq(0.1) 42 print "density = 0.00001: output=%g time=%g" % (value_1, time.time()-t_0)43 print 43 print("density = 0.00001: output=%g time=%g" % (value_1, time.time()-t_0)) 44 print() 44 45 45 46 … … 63 64 #ana_1 = form_factor(q, radius) 64 65 65 print "q=%g sim=%g ana=%g ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)66 print("q=%g sim=%g ana=%g ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)) 66 67 67 68 def test_2(): … … 73 74 shell_vol = 4.0/3.0*math.pi*outer_radius*outer_radius*outer_radius - core_vol 74 75 shell_sld = -1.0*core_vol/shell_vol 75 print "Shell SLD", shell_sld76 print("Shell SLD", shell_sld) 76 77 77 78 … … 126 127 ana_1 = sphere.run(q) 127 128 128 print "q=%g sim=%g ana=%g ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)129 print("q=%g sim=%g ana=%g ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)) 129 130 out.write( "%g %g %g\n" % (q, sim_1, ana_1)) 130 131 … … 168 169 #ana_1 = form_factor(q, radius) 169 170 170 print "q=%g sim=%g ana=%g ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)171 print("q=%g sim=%g ana=%g ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)) 171 172 172 173 def test_5(): … … 193 194 ana = ana.runXY([0.1, 0.1]) 194 195 sim = model.getIq2D(0.1, 0.1) 195 print ana, sim, sim/ana, ana/sim196 print(ana, sim, sim/ana, ana/sim) 196 197 197 198 def test_6(): … … 232 233 233 234 234 print model.npts235 print(model.npts) 235 236 for i in range(40): 236 237 qmax = 0.5 … … 240 241 anaY = ana.runXY([0, qmax*i/40.0]) 241 242 simY = model.getIq2D(0, qmax*i/40.0) 242 print anaX, simX, simX/anaX, '|', anaY, simY, simY/anaY243 print(anaX, simX, simX/anaX, '|', anaY, simY, simY/anaY) 243 244 244 245 def test_7(): 245 246 from sas.models.CoreShellModel import CoreShellModel 246 print "Testing core-shell"247 print("Testing core-shell") 247 248 radius = 15 248 249 thickness = 5 … … 287 288 ana_val = ana.runXY([q, 0.2]) 288 289 sim_val, err = canvas.getIq2DError(q, 0.2) 289 print ana_val, sim_val, sim_val/ana_val, err, (sim_val-ana_val)/err290 print(ana_val, sim_val, sim_val/ana_val, err, (sim_val-ana_val)/err) 290 291 291 292 -
test/sasrealspace/test/sim_validation.py
rac07a3a raaf5e49 5 5 @license: This software is provided as part of the DANSE project 6 6 """ 7 from __future__ import print_function 8 7 9 import math, time, pylab 8 10 9 11 try: 10 12 import VolumeCanvas 11 print "Testing local version"13 print("Testing local version") 12 14 except: 13 print "Testing installed version"15 print("Testing installed version") 14 16 import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas 15 17 … … 250 252 ana = validator.run_ana(q) 251 253 sim, err = validator.run_sim(q) 252 print 253 (sim-ana), sim/ana, str(math.fabs(sim-ana)>err)) 254 print("q=%-g ana=%-g sim=%-g err=%-g diff=%-g (%-g) %s" % (q, ana, sim, err, 255 (sim-ana), sim/ana, str(math.fabs(sim-ana)>err))) 254 256 output.write("%g %g %g %g\n" % (q, ana, sim, err)) 255 257 output.close() … … 278 280 ana = validator.run_ana2D(q*math.cos(phi), q*math.sin(phi)) 279 281 sim, err = validator.run_sim2D(q*math.cos(phi), q*math.sin(phi)) 280 print 281 (sim-ana), sim/ana, str(math.fabs(sim-ana)>err)) 282 print("q=%-g ana=%-g sim=%-g err=%-g diff=%-g (%-g) %s" % (q, ana, sim, err, 283 (sim-ana), sim/ana, str(math.fabs(sim-ana)>err))) 282 284 output.write("%g %g %g %g\n" % (q, ana, sim, err)) 283 print "Time elapsed: ", time.time()-t_0285 print("Time elapsed: ", time.time()-t_0) 284 286 output.close() 285 287 … … 306 308 for d in d_list: 307 309 sim, err = validator.run_sim(q, density=d) 308 print 310 print("d=%-g ana=%-g sim=%-g err=%-g diff=%-g (%g) %s" % \ 309 311 (d, ana, sim, err, (sim-ana), (sim-ana)/ana, 310 str(math.fabs(sim-ana)>err)) 312 str(math.fabs(sim-ana)>err))) 311 313 output.write("%g %g %g %g \n" % (d, ana, sim, err)) 312 314 output.close() -
test/sasrealspace/test/utest_oriented.py
r959eb01 raaf5e49 3 3 @copyright: University of Tennessee, for the DANSE project 4 4 """ 5 from __future__ import print_function 5 6 6 7 import unittest, math, sys … … 16 17 try: 17 18 import VolumeCanvas 18 print "Testing local version"19 print("Testing local version") 19 20 except: 20 print sys.exc_value21 print(sys.exc_value) 21 22 #testing the version that is working on 22 print "Testing installed version"23 print("Testing installed version") 23 24 import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas 24 25 … … 241 242 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 242 243 except: 243 print "Error", ana_val, sim_val, sim_val/ana_val244 print("Error", ana_val, sim_val, sim_val/ana_val) 244 245 raise sys.exc_type, sys.exc_value 245 246 … … 395 396 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 396 397 except: 397 print "Error", ana_val, sim_val, sim_val/ana_val398 print("Error", ana_val, sim_val, sim_val/ana_val) 398 399 raise sys.exc_type, sys.exc_value 399 400 … … 407 408 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 408 409 except: 409 print "Error", ana_val, sim_val, sim_val/ana_val410 print("Error", ana_val, sim_val, sim_val/ana_val) 410 411 raise sys.exc_type, sys.exc_value 411 412 … … 419 420 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 420 421 except: 421 print "Error", ana_val, sim_val, sim_val/ana_val422 print("Error", ana_val, sim_val, sim_val/ana_val) 422 423 raise sys.exc_type, sys.exc_value 423 424 … … 431 432 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 432 433 except: 433 print "Error", ana_val, sim_val, sim_val/ana_val434 print("Error", ana_val, sim_val, sim_val/ana_val) 434 435 raise sys.exc_type, sys.exc_value 435 436 -
test/sasrealspace/test/utest_realspace.py
r45dffa69 raaf5e49 3 3 @author: Mathieu Doucet / UTK 4 4 """ 5 from __future__ import print_function 5 6 6 7 import unittest, math, time … … 15 16 try: 16 17 import VolumeCanvas 17 print "Testing local version"18 print("Testing local version") 18 19 except: 19 20 import sys 20 print sys.exc_value21 print(sys.exc_value) 21 22 #testing the version that is working on 22 print "Testing installed version"23 print("Testing installed version") 23 24 import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas 24 25 -
test/utest_sasview.py
r959eb01 raaf5e49 1 1 #!/usr/bin/env python 2 from __future__ import print_function 3 2 4 import os 3 5 import subprocess … … 80 82 if has_failed: 81 83 failed += 1 82 print "Result for %s (%s): FAILED" % (module_name, module_dir)83 print std_out84 print("Result for %s (%s): FAILED" % (module_name, module_dir)) 85 print(std_out) 84 86 else: 85 87 passed += 1 86 print "Result for %s: SUCCESS" % module_name88 print("Result for %s: SUCCESS" % module_name) 87 89 88 print "\n----------------------------------------------"90 print("\n----------------------------------------------") 89 91 if n_tests == 0: 90 print "No tests."92 print("No tests.") 91 93 else: 92 print "Results by test modules:"93 print " PASSED: %d" % passed94 print("Results by test modules:") 95 print(" PASSED: %d" % passed) 94 96 ratio = 100.0*failed/(failed+passed) 95 print " FAILED: %d (%.0f%%)" % (failed,ratio)97 print(" FAILED: %d (%.0f%%)" % (failed,ratio)) 96 98 97 print "Results by tests:"98 print " Tests run: %d" % n_tests99 print " Tests failed: %d" % n_failures100 print " Test errors: %d" % n_errors101 print "----------------------------------------------"99 print("Results by tests:") 100 print(" Tests run: %d" % n_tests) 101 print(" Tests failed: %d" % n_failures) 102 print(" Test errors: %d" % n_errors) 103 print("----------------------------------------------") 102 104 103 105 return failed -
test/sasdataloader/test/utest_averaging.py
r9a5097c rfa4af76 1 1 2 import math 3 import os 2 4 import unittest 3 import math4 5 from sas.sascalc.dataloader.loader import Loader6 from sas.sascalc.dataloader.manipulations import Ring, CircularAverage, SectorPhi, get_q,reader2D_converter7 5 8 6 import numpy as np 7 9 8 import sas.sascalc.dataloader.data_info as data_info 9 from sas.sascalc.dataloader.loader import Loader 10 from sas.sascalc.dataloader.manipulations import (Boxavg, Boxsum, 11 CircularAverage, Ring, 12 SectorPhi, SectorQ, SlabX, 13 SlabY, get_q, 14 reader2D_converter) 15 10 16 11 17 class Averaging(unittest.TestCase): … … 13 19 Test averaging manipulations on a flat distribution 14 20 """ 21 15 22 def setUp(self): 16 23 """ … … 18 25 should return the predefined height of the distribution (1.0). 19 26 """ 20 x_0 = np.ones([100,100])21 dx_0 = np.ones([100, 100])22 27 x_0 = np.ones([100, 100]) 28 dx_0 = np.ones([100, 100]) 29 23 30 self.data = data_info.Data2D(data=x_0, err_data=dx_0) 24 31 detector = data_info.Detector() 25 detector.distance = 1000.0 # mm26 detector.pixel_size.x = 1.0 #mm27 detector.pixel_size.y = 1.0 #mm28 32 detector.distance = 1000.0 # mm 33 detector.pixel_size.x = 1.0 # mm 34 detector.pixel_size.y = 1.0 # mm 35 29 36 # center in pixel position = (len(x_0)-1)/2 30 detector.beam_center.x = (len(x_0) -1)/2 #pixel number31 detector.beam_center.y = (len(x_0) -1)/2 #pixel number37 detector.beam_center.x = (len(x_0) - 1) / 2 # pixel number 38 detector.beam_center.y = (len(x_0) - 1) / 2 # pixel number 32 39 self.data.detector.append(detector) 33 40 34 41 source = data_info.Source() 35 source.wavelength = 10.0 #A42 source.wavelength = 10.0 # A 36 43 self.data.source = source 37 38 # get_q(dx, dy, det_dist, wavelength) where units are mm,mm,mm,and A respectively. 44 45 # get_q(dx, dy, det_dist, wavelength) where units are mm,mm,mm,and A 46 # respectively. 39 47 self.qmin = get_q(1.0, 1.0, detector.distance, source.wavelength) 40 48 41 49 self.qmax = get_q(49.5, 49.5, detector.distance, source.wavelength) 42 50 43 51 self.qstep = len(x_0) 44 x = np.linspace(start= -1*self.qmax,45 stop=self.qmax,46 num=self.qstep,47 endpoint=True )48 y = np.linspace(start= -1*self.qmax,49 stop=self.qmax,50 num=self.qstep,51 endpoint=True)52 self.data.x_bins =x53 self.data.y_bins =y52 x = np.linspace(start=-1 * self.qmax, 53 stop=self.qmax, 54 num=self.qstep, 55 endpoint=True) 56 y = np.linspace(start=-1 * self.qmax, 57 stop=self.qmax, 58 num=self.qstep, 59 endpoint=True) 60 self.data.x_bins = x 61 self.data.y_bins = y 54 62 self.data = reader2D_converter(self.data) 55 63 56 64 def test_ring_flat_distribution(self): 57 65 """ 58 66 Test ring averaging 59 67 """ 60 r = Ring(r_min=2 *self.qmin, r_max=5*self.qmin,61 center_x=self.data.detector[0].beam_center.x, 68 r = Ring(r_min=2 * self.qmin, r_max=5 * self.qmin, 69 center_x=self.data.detector[0].beam_center.x, 62 70 center_y=self.data.detector[0].beam_center.y) 63 71 r.nbins_phi = 20 64 72 65 73 o = r(self.data) 66 74 for i in range(20): 67 75 self.assertEqual(o.y[i], 1.0) 68 76 69 77 def test_sectorphi_full(self): 70 78 """ 71 79 Test sector averaging 72 80 """ 73 r = SectorPhi(r_min=self.qmin, r_max=3 *self.qmin,74 phi_min=0, phi_max=math.pi *2.0)81 r = SectorPhi(r_min=self.qmin, r_max=3 * self.qmin, 82 phi_min=0, phi_max=math.pi * 2.0) 75 83 r.nbins_phi = 20 76 84 o = r(self.data) 77 85 for i in range(7): 78 86 self.assertEqual(o.y[i], 1.0) 79 80 87 81 88 def test_sectorphi_partial(self): 82 89 """ 83 90 """ 84 91 phi_max = math.pi * 1.5 85 r = SectorPhi(r_min=self.qmin, r_max=3 *self.qmin,92 r = SectorPhi(r_min=self.qmin, r_max=3 * self.qmin, 86 93 phi_min=0, phi_max=phi_max) 87 94 self.assertEqual(r.phi_max, phi_max) … … 91 98 for i in range(17): 92 99 self.assertEqual(o.y[i], 1.0) 93 94 95 96 class data_info_tests(unittest.TestCase): 97 100 101 102 class DataInfoTests(unittest.TestCase): 103 98 104 def setUp(self): 99 self.data = Loader().load('MAR07232_rest.ASC') 100 105 filepath = os.path.join(os.path.dirname( 106 os.path.realpath(__file__)), 'MAR07232_rest.ASC') 107 self.data = Loader().load(filepath) 108 101 109 def test_ring(self): 102 110 """ 103 111 Test ring averaging 104 112 """ 105 r = Ring(r_min=.005, r_max=.01, 106 center_x=self.data.detector[0].beam_center.x, 113 r = Ring(r_min=.005, r_max=.01, 114 center_x=self.data.detector[0].beam_center.x, 107 115 center_y=self.data.detector[0].beam_center.y, 108 nbins =20)116 nbins=20) 109 117 ##r.nbins_phi = 20 110 111 o = r(self.data) 112 answer = Loader().load('ring_testdata.txt') 113 118 119 o = r(self.data) 120 filepath = os.path.join(os.path.dirname( 121 os.path.realpath(__file__)), 'ring_testdata.txt') 122 answer = Loader().load(filepath) 123 114 124 for i in range(r.nbins_phi - 1): 115 125 self.assertAlmostEqual(o.x[i + 1], answer.x[i], 4) 116 126 self.assertAlmostEqual(o.y[i + 1], answer.y[i], 4) 117 127 self.assertAlmostEqual(o.dy[i + 1], answer.dy[i], 4) 118 128 119 129 def test_circularavg(self): 120 130 """ 131 Test circular averaging 132 The test data was not generated by IGOR. 133 """ 134 r = CircularAverage(r_min=.00, r_max=.025, 135 bin_width=0.0003) 136 r.nbins_phi = 20 137 138 o = r(self.data) 139 140 filepath = os.path.join(os.path.dirname( 141 os.path.realpath(__file__)), 'avg_testdata.txt') 142 answer = Loader().load(filepath) 143 for i in range(r.nbins_phi): 144 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 145 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 146 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 147 148 def test_box(self): 149 """ 121 150 Test circular averaging 122 151 The test data was not generated by IGOR. 123 152 """ 124 r = CircularAverage(r_min=.00, r_max=.025, 125 bin_width=0.0003) 126 r.nbins_phi = 20 127 128 o = r(self.data) 129 130 answer = Loader().load('avg_testdata.txt') 131 for i in range(r.nbins_phi): 132 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 133 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 134 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 135 136 def test_box(self): 137 """ 138 Test circular averaging 139 The test data was not generated by IGOR. 140 """ 141 from sas.sascalc.dataloader.manipulations import Boxsum, Boxavg 142 153 143 154 r = Boxsum(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) 144 155 s, ds, npoints = r(self.data) 145 156 self.assertAlmostEqual(s, 34.278990899999997, 4) 146 157 self.assertAlmostEqual(ds, 7.8007981835194293, 4) 147 self.assertAlmostEqual(npoints, 324.0000, 4) 148 158 self.assertAlmostEqual(npoints, 324.0000, 4) 159 149 160 r = Boxavg(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) 150 161 s, ds = r(self.data) 151 162 self.assertAlmostEqual(s, 0.10579935462962962, 4) 152 163 self.assertAlmostEqual(ds, 0.024076537603455028, 4) 153 164 154 165 def test_slabX(self): 155 166 """ … … 157 168 The test data was not generated by IGOR. 158 169 """ 159 from sas.sascalc.dataloader.manipulations import SlabX 160 161 r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002,y_max=0.0002, bin_width=0.0004)170 171 r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002, 172 y_max=0.0002, bin_width=0.0004) 162 173 r.fold = False 163 174 o = r(self.data) 164 175 165 answer = Loader().load('slabx_testdata.txt') 166 for i in range(len(o.x)): 167 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 168 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 169 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 170 176 filepath = os.path.join(os.path.dirname( 177 os.path.realpath(__file__)), 'slabx_testdata.txt') 178 answer = Loader().load(filepath) 179 for i in range(len(o.x)): 180 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 181 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 182 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 183 171 184 def test_slabY(self): 172 185 """ … … 174 187 The test data was not generated by IGOR. 175 188 """ 176 from sas.sascalc.dataloader.manipulations import SlabY 177 178 r = SlabY(x_min=.005, x_max=.01, y_min=-0.01, y_max=0.01, bin_width=0.0004)189 190 r = SlabY(x_min=.005, x_max=.01, y_min=- 191 0.01, y_max=0.01, bin_width=0.0004) 179 192 r.fold = False 180 193 o = r(self.data) 181 194 182 answer = Loader().load('slaby_testdata.txt') 183 for i in range(len(o.x)): 184 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 185 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 186 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 187 195 filepath = os.path.join(os.path.dirname( 196 os.path.realpath(__file__)), 'slaby_testdata.txt') 197 answer = Loader().load(filepath) 198 for i in range(len(o.x)): 199 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 200 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 201 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 202 188 203 def test_sectorphi_full(self): 189 204 """ … … 193 208 The test data was not generated by IGOR. 194 209 """ 195 from sas.sascalc.dataloader.manipulations import SectorPhi 196 import math 197 210 198 211 nbins = 19 199 212 phi_min = math.pi / (nbins + 1) 200 213 phi_max = math.pi * 2 - phi_min 201 214 202 215 r = SectorPhi(r_min=.005, 203 216 r_max=.01, … … 207 220 o = r(self.data) 208 221 209 answer = Loader().load('ring_testdata.txt') 210 for i in range(len(o.x)): 211 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 212 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 213 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 214 222 filepath = os.path.join(os.path.dirname( 223 os.path.realpath(__file__)), 'ring_testdata.txt') 224 answer = Loader().load(filepath) 225 for i in range(len(o.x)): 226 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 227 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 228 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 229 215 230 def test_sectorphi_quarter(self): 216 231 """ … … 218 233 The test data was not generated by IGOR. 219 234 """ 220 from sas.sascalc.dataloader.manipulations import SectorPhi 221 import math222 223 r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0)224 r.nbins_phi = 20 225 o = r(self.data)226 227 answer = Loader().load( 'sectorphi_testdata.txt')228 for i in range(len(o.x)): 229 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 230 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 231 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 232 235 236 r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi / 2.0) 237 r.nbins_phi = 20 238 o = r(self.data) 239 240 filepath = os.path.join(os.path.dirname( 241 os.path.realpath(__file__)), 'sectorphi_testdata.txt') 242 answer = Loader().load(filepath) 243 for i in range(len(o.x)): 244 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 245 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 246 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 247 233 248 def test_sectorq_full(self): 234 249 """ … … 236 251 The test data was not generated by IGOR. 237 252 """ 238 from sas.sascalc.dataloader.manipulations import SectorQ 239 import math240 241 r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0)242 r.nbins_phi = 20 243 o = r(self.data)244 245 answer = Loader().load( 'sectorq_testdata.txt')246 for i in range(len(o.x)): 247 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 248 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 249 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 250 253 254 r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi / 2.0) 255 r.nbins_phi = 20 256 o = r(self.data) 257 258 filepath = os.path.join(os.path.dirname( 259 os.path.realpath(__file__)), 'sectorq_testdata.txt') 260 answer = Loader().load(filepath) 261 for i in range(len(o.x)): 262 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 263 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 264 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 265 251 266 252 267 if __name__ == '__main__': -
test/sasguiframe/test/utest_manipulations.py
r959eb01 rc0ca2e3d 2 2 Unit tests for data manipulations 3 3 """ 4 #TODO: what happens if you add a Data1D to a Data2D? 5 4 # TODO: what happens if you add a Data1D to a Data2D? 5 6 import math 7 import os.path 6 8 import unittest 7 import math 9 8 10 import numpy as np 9 from sas.sascalc.dataloader.loader import Loader 10 from sas.sas gui.guiframe.dataFitting import Data1D, Data2D11 from sas.sasgui.guiframe.dataFitting import Data1D as Theory1D12 13 import os.path 14 15 class data_info_tests(unittest.TestCase):16 11 12 from sas.sascalc.dataloader.loader import Loader 13 from sas.sasgui.guiframe.dataFitting import Data1D 14 from sas.sasgui.guiframe.dataFitting import Data2D 15 16 17 class DataInfoTests(unittest.TestCase): 18 17 19 def setUp(self): 18 20 data = Loader().load("cansas1d.xml") 19 21 self.data = data[0] 20 22 21 23 def test_clone1D(self): 22 24 """ … … 24 26 """ 25 27 clone = self.data.clone_without_data() 26 28 27 29 for i in range(len(self.data.detector)): 28 self.assertEqual(self.data.detector[i].distance, clone.detector[i].distance) 29 30 class theory1d_tests(unittest.TestCase): 31 30 self.assertEqual( 31 self.data.detector[i].distance, clone.detector[i].distance) 32 33 34 class Theory1DTests(unittest.TestCase): 35 32 36 def setUp(self): 33 37 data = Loader().load("cansas1d.xml") 34 38 self.data = data[0] 35 39 36 40 def test_clone_theory1D(self): 37 41 """ 38 42 Test basic cloning 39 43 """ 40 theory = Theory1D(x=[], y=[], dy=None)44 theory = Data1D(x=[], y=[], dy=None) 41 45 theory.clone_without_data(clone=self.data) 42 46 theory.copy_from_datainfo(data1d=self.data) 43 47 for i in range(len(self.data.detector)): 44 self.assertEqual(self.data.detector[i].distance, theory.detector[i].distance) 45 48 self.assertEqual( 49 self.data.detector[i].distance, theory.detector[i].distance) 50 46 51 for i in range(len(self.data.x)): 47 52 self.assertEqual(self.data.x[i], theory.x[i]) … … 49 54 self.assertEqual(self.data.dy[i], theory.dy[i]) 50 55 51 class manip_tests(unittest.TestCase): 52 56 57 class ManipTests(unittest.TestCase): 58 53 59 def setUp(self): 54 60 # Create two data sets to play with 55 61 x_0 = np.ones(5) 56 62 for i in range(5): 57 x_0[i] = x_0[i] *(i+1.0)58 59 y_0 = 2.0 *np.ones(5)60 dy_0 = 0.5 *np.ones(5)63 x_0[i] = x_0[i] * (i + 1.0) 64 65 y_0 = 2.0 * np.ones(5) 66 dy_0 = 0.5 * np.ones(5) 61 67 self.data = Data1D(x_0, y_0, dy=dy_0) 62 68 63 69 x = self.data.x 64 70 y = np.ones(5) 65 71 dy = np.ones(5) 66 72 self.data2 = Data1D(x, y, dy=dy) 67 68 73 69 74 def test_load(self): 70 75 """ … … 73 78 # There should be 5 entries in the file 74 79 self.assertEqual(len(self.data.x), 5) 75 80 76 81 for i in range(5): 77 82 # The x values should be from 1 to 5 78 self.assertEqual(self.data.x[i], float(i +1))79 83 self.assertEqual(self.data.x[i], float(i + 1)) 84 80 85 # All y-error values should be 0.5 81 self.assertEqual(self.data.dy[i], 0.5) 82 86 self.assertEqual(self.data.dy[i], 0.5) 87 83 88 # All y values should be 2.0 84 self.assertEqual(self.data.y[i], 2.0) 85 89 self.assertEqual(self.data.y[i], 2.0) 90 86 91 def test_add(self): 87 result = self.data2 +self.data92 result = self.data2 + self.data 88 93 for i in range(5): 89 94 self.assertEqual(result.y[i], 3.0) 90 self.assertEqual(result.dy[i], math.sqrt(0.5**2 +1.0))91 95 self.assertEqual(result.dy[i], math.sqrt(0.5**2 + 1.0)) 96 92 97 def test_sub(self): 93 result = self.data2 -self.data98 result = self.data2 - self.data 94 99 for i in range(5): 95 100 self.assertEqual(result.y[i], -1.0) 96 self.assertEqual(result.dy[i], math.sqrt(0.5**2 +1.0))97 101 self.assertEqual(result.dy[i], math.sqrt(0.5**2 + 1.0)) 102 98 103 def test_mul(self): 99 result = self.data2 *self.data104 result = self.data2 * self.data 100 105 for i in range(5): 101 106 self.assertEqual(result.y[i], 2.0) 102 self.assertEqual(result.dy[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 103 107 self.assertEqual(result.dy[i], math.sqrt( 108 (0.5 * 1.0)**2 + (1.0 * 2.0)**2)) 109 104 110 def test_div(self): 105 result = self.data2 /self.data111 result = self.data2 / self.data 106 112 for i in range(5): 107 113 self.assertEqual(result.y[i], 0.5) 108 self.assertEqual(result.dy[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 109 114 self.assertEqual(result.dy[i], math.sqrt( 115 (1.0 / 2.0)**2 + (0.5 * 1.0 / 4.0)**2)) 116 110 117 def test_radd(self): 111 result = self.data +3.0118 result = self.data + 3.0 112 119 for i in range(5): 113 120 self.assertEqual(result.y[i], 5.0) 114 121 self.assertEqual(result.dy[i], 0.5) 115 116 result = 3.0 +self.data122 123 result = 3.0 + self.data 117 124 for i in range(5): 118 125 self.assertEqual(result.y[i], 5.0) 119 126 self.assertEqual(result.dy[i], 0.5) 120 127 121 128 def test_rsub(self): 122 result = self.data -3.0129 result = self.data - 3.0 123 130 for i in range(5): 124 131 self.assertEqual(result.y[i], -1.0) 125 132 self.assertEqual(result.dy[i], 0.5) 126 127 result = 3.0 -self.data133 134 result = 3.0 - self.data 128 135 for i in range(5): 129 136 self.assertEqual(result.y[i], 1.0) 130 137 self.assertEqual(result.dy[i], 0.5) 131 138 132 139 def test_rmul(self): 133 result = self.data *3.0140 result = self.data * 3.0 134 141 for i in range(5): 135 142 self.assertEqual(result.y[i], 6.0) 136 143 self.assertEqual(result.dy[i], 1.5) 137 138 result = 3.0 *self.data144 145 result = 3.0 * self.data 139 146 for i in range(5): 140 147 self.assertEqual(result.y[i], 6.0) 141 148 self.assertEqual(result.dy[i], 1.5) 142 149 143 150 def test_rdiv(self): 144 result = self.data /4.0151 result = self.data / 4.0 145 152 for i in range(5): 146 153 self.assertEqual(result.y[i], 0.5) 147 154 self.assertEqual(result.dy[i], 0.125) 148 149 result = 6.0 /self.data155 156 result = 6.0 / self.data 150 157 for i in range(5): 151 158 self.assertEqual(result.y[i], 3.0) 152 self.assertEqual(result.dy[i], 6.0*0.5/4.0) 153 154 class manip_2D(unittest.TestCase): 155 159 self.assertEqual(result.dy[i], 6.0 * 0.5 / 4.0) 160 161 162 class Manin2DTests(unittest.TestCase): 163 156 164 def setUp(self): 157 165 # Create two data sets to play with 158 x_0 = 2.0 *np.ones(25)159 dx_0 = 0.5 *np.ones(25)166 x_0 = 2.0 * np.ones(25) 167 dx_0 = 0.5 * np.ones(25) 160 168 qx_0 = np.arange(25) 161 169 qy_0 = np.arange(25) 162 170 mask_0 = np.zeros(25) 163 dqx_0 = np.arange(25) /100164 dqy_0 = np.arange(25) /100171 dqx_0 = np.arange(25) / 100 172 dqy_0 = np.arange(25) / 100 165 173 q_0 = np.sqrt(qx_0 * qx_0 + qy_0 * qy_0) 166 self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 167 qy_data=qy_0, q_data=q_0, mask=mask_0, 174 self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 175 qy_data=qy_0, q_data=q_0, mask=mask_0, 168 176 dqx_data=dqx_0, dqy_data=dqy_0) 169 177 170 178 y = np.ones(25) 171 179 dy = np.ones(25) … … 174 182 mask = np.zeros(25) 175 183 q = np.sqrt(qx * qx + qy * qy) 176 self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy, 184 self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy, 177 185 q_data=q, mask=mask) 178 179 186 180 187 def test_load(self): 181 188 """ … … 184 191 # There should be 5 entries in the file 185 192 self.assertEqual(np.size(self.data.data), 25) 186 193 187 194 for i in range(25): 188 195 # All y-error values should be 0.5 189 self.assertEqual(self.data.err_data[i], 0.5) 190 196 self.assertEqual(self.data.err_data[i], 0.5) 197 191 198 # All y values should be 2.0 192 self.assertEqual(self.data.data[i], 2.0) 193 199 self.assertEqual(self.data.data[i], 2.0) 200 194 201 def test_add(self): 195 result = self.data2 +self.data202 result = self.data2 + self.data 196 203 for i in range(25): 197 204 self.assertEqual(result.data[i], 3.0) 198 self.assertEqual(result.err_data[i], math.sqrt(0.5**2 +1.0))199 205 self.assertEqual(result.err_data[i], math.sqrt(0.5**2 + 1.0)) 206 200 207 def test_sub(self): 201 result = self.data2 -self.data202 for i in range(25): 203 204 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0))205 208 result = self.data2 - self.data 209 for i in range(25): 210 self.assertEqual(result.data[i], -1.0) 211 self.assertEqual(result.err_data[i], math.sqrt(0.5**2 + 1.0)) 212 206 213 def test_mul(self): 207 result = self.data2 *self.data214 result = self.data2 * self.data 208 215 for i in range(25): 209 216 self.assertEqual(result.data[i], 2.0) 210 self.assertEqual(result.err_data[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 211 217 self.assertEqual(result.err_data[i], math.sqrt( 218 (0.5 * 1.0)**2 + (1.0 * 2.0)**2)) 219 212 220 def test_div(self): 213 result = self.data2 /self.data221 result = self.data2 / self.data 214 222 for i in range(25): 215 223 self.assertEqual(result.data[i], 0.5) 216 self.assertEqual(result.err_data[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 217 224 self.assertEqual(result.err_data[i], math.sqrt( 225 (1.0 / 2.0)**2 + (0.5 * 1.0 / 4.0)**2)) 226 218 227 def test_radd(self): 219 result = self.data +3.0228 result = self.data + 3.0 220 229 for i in range(25): 221 230 self.assertEqual(result.data[i], 5.0) 222 231 self.assertEqual(result.err_data[i], 0.5) 223 224 result = 3.0 +self.data232 233 result = 3.0 + self.data 225 234 for i in range(25): 226 235 self.assertEqual(result.data[i], 5.0) 227 236 self.assertEqual(result.err_data[i], 0.5) 228 237 229 238 def test_rsub(self): 230 result = self.data -3.0239 result = self.data - 3.0 231 240 for i in range(25): 232 241 self.assertEqual(result.data[i], -1.0) 233 242 self.assertEqual(result.err_data[i], 0.5) 234 235 result = 3.0 -self.data243 244 result = 3.0 - self.data 236 245 for i in range(25): 237 246 self.assertEqual(result.data[i], 1.0) 238 247 self.assertEqual(result.err_data[i], 0.5) 239 248 240 249 def test_rmul(self): 241 result = self.data *3.0250 result = self.data * 3.0 242 251 for i in range(25): 243 252 self.assertEqual(result.data[i], 6.0) 244 253 self.assertEqual(result.err_data[i], 1.5) 245 246 result = 3.0 *self.data254 255 result = 3.0 * self.data 247 256 for i in range(25): 248 257 self.assertEqual(result.data[i], 6.0) 249 258 self.assertEqual(result.err_data[i], 1.5) 250 259 251 260 def test_rdiv(self): 252 result = self.data /4.0261 result = self.data / 4.0 253 262 for i in range(25): 254 263 self.assertEqual(result.data[i], 0.5) 255 264 self.assertEqual(result.err_data[i], 0.125) 256 265 257 result = 6.0 /self.data266 result = 6.0 / self.data 258 267 for i in range(25): 259 268 self.assertEqual(result.data[i], 3.0) 260 self.assertEqual(result.err_data[i], 6.0*0.5/4.0) 261 262 class extra_manip_2D(unittest.TestCase): 263 269 self.assertEqual(result.err_data[i], 6.0 * 0.5 / 4.0) 270 271 272 class ExtraManip2DTests(unittest.TestCase): 273 264 274 def setUp(self): 265 275 # Create two data sets to play with 266 x_0 = 2.0 *np.ones(25)267 dx_0 = 0.5 *np.ones(25)276 x_0 = 2.0 * np.ones(25) 277 dx_0 = 0.5 * np.ones(25) 268 278 qx_0 = np.arange(25) 269 279 qy_0 = np.arange(25) 270 280 mask_0 = np.zeros(25) 271 dqx_0 = np.arange(25) /100272 dqy_0 = np.arange(25) /100281 dqx_0 = np.arange(25) / 100 282 dqy_0 = np.arange(25) / 100 273 283 q_0 = np.sqrt(qx_0 * qx_0 + qy_0 * qy_0) 274 self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 275 qy_data=qy_0, q_data=q_0, mask=mask_0, 284 self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 285 qy_data=qy_0, q_data=q_0, mask=mask_0, 276 286 dqx_data=dqx_0, dqy_data=dqy_0) 277 287 278 288 y = np.ones(25) 279 289 dy = np.ones(25) … … 282 292 mask = np.zeros(25) 283 293 q = np.sqrt(qx * qx + qy * qy) 284 self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy, 294 self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy, 285 295 q_data=q, mask=mask) 286 287 296 288 297 def test_load(self): 289 298 """ … … 292 301 # There should be 5 entries in the file 293 302 self.assertEqual(np.size(self.data.data), 25) 294 303 295 304 for i in range(25): 296 305 # All y-error values should be 0.5 297 self.assertEqual(self.data.err_data[i], 0.5) 298 306 self.assertEqual(self.data.err_data[i], 0.5) 307 299 308 # All y values should be 2.0 300 self.assertEqual(self.data.data[i], 2.0) 301 309 self.assertEqual(self.data.data[i], 2.0) 310 302 311 def test_add(self): 303 result = self.data2 +self.data312 result = self.data2 + self.data 304 313 for i in range(25): 305 314 self.assertEqual(result.data[i], 3.0) 306 self.assertEqual(result.err_data[i], math.sqrt(0.5**2 +1.0))307 315 self.assertEqual(result.err_data[i], math.sqrt(0.5**2 + 1.0)) 316 308 317 def test_sub(self): 309 result = self.data2 -self.data310 for i in range(25): 311 312 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0))313 318 result = self.data2 - self.data 319 for i in range(25): 320 self.assertEqual(result.data[i], -1.0) 321 self.assertEqual(result.err_data[i], math.sqrt(0.5**2 + 1.0)) 322 314 323 def test_mul(self): 315 result = self.data2 *self.data324 result = self.data2 * self.data 316 325 for i in range(25): 317 326 self.assertEqual(result.data[i], 2.0) 318 self.assertEqual(result.err_data[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 319 327 self.assertEqual(result.err_data[i], math.sqrt( 328 (0.5 * 1.0)**2 + (1.0 * 2.0)**2)) 329 320 330 def test_div(self): 321 result = self.data2 /self.data331 result = self.data2 / self.data 322 332 for i in range(25): 323 333 self.assertEqual(result.data[i], 0.5) 324 self.assertEqual(result.err_data[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 325 334 self.assertEqual(result.err_data[i], math.sqrt( 335 (1.0 / 2.0)**2 + (0.5 * 1.0 / 4.0)**2)) 336 326 337 def test_radd(self): 327 result = self.data +3.0338 result = self.data + 3.0 328 339 for i in range(25): 329 340 self.assertEqual(result.data[i], 5.0) 330 341 self.assertEqual(result.err_data[i], 0.5) 331 332 result = 3.0 +self.data342 343 result = 3.0 + self.data 333 344 for i in range(25): 334 345 self.assertEqual(result.data[i], 5.0) 335 346 self.assertEqual(result.err_data[i], 0.5) 336 347 337 348 def test_rsub(self): 338 result = self.data -3.0349 result = self.data - 3.0 339 350 for i in range(25): 340 351 self.assertEqual(result.data[i], -1.0) 341 352 self.assertEqual(result.err_data[i], 0.5) 342 343 result = 3.0 -self.data353 354 result = 3.0 - self.data 344 355 for i in range(25): 345 356 self.assertEqual(result.data[i], 1.0) 346 357 self.assertEqual(result.err_data[i], 0.5) 347 358 348 359 def test_rmul(self): 349 result = self.data *3.0360 result = self.data * 3.0 350 361 for i in range(25): 351 362 self.assertEqual(result.data[i], 6.0) 352 363 self.assertEqual(result.err_data[i], 1.5) 353 354 result = 3.0 *self.data364 365 result = 3.0 * self.data 355 366 for i in range(25): 356 367 self.assertEqual(result.data[i], 6.0) 357 368 self.assertEqual(result.err_data[i], 1.5) 358 369 359 370 def test_rdiv(self): 360 result = self.data /4.0371 result = self.data / 4.0 361 372 for i in range(25): 362 373 self.assertEqual(result.data[i], 0.5) 363 374 self.assertEqual(result.err_data[i], 0.125) 364 375 365 result = 6.0 /self.data376 result = 6.0 / self.data 366 377 for i in range(25): 367 378 self.assertEqual(result.data[i], 3.0) 368 self.assertEqual(result.err_data[i], 6.0*0.5/4.0) 379 self.assertEqual(result.err_data[i], 6.0 * 0.5 / 4.0) 380 369 381 370 382 if __name__ == '__main__': 371 383 unittest.main() 372
Note: See TracChangeset
for help on using the changeset viewer.