Changes in / [0a924c6:8c9e65c] in sasview


Ignore:
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/calculator/instrument.py

    rf4775563 re090ba90  
    128128            self.size = 0 
    129129        else: 
    130             self.size = size 
     130            # TODO: Make sure detector size is number of pixels 
     131            # Could be detector dimensions in e.g., mm, but 
     132            # the resolution calculator assumes it is pixels. 
     133            # Being pixels, it has to be integers rather than float 
     134            self.size = [int(s) for s in size] 
    131135            validate(size[0]) 
    132136 
  • src/sas/sascalc/calculator/resolution_calculator.py

    r574adc7 re090ba90  
    10071007        try: 
    10081008            detector_offset = self.sample2detector_distance[1] 
    1009         except: 
    1010             logger.error(sys.exc_value) 
     1009        except Exception as exc: 
     1010            logger.error(exc) 
    10111011 
    10121012        # detector size in [no of pix_x,no of pix_y] 
     
    10941094            output.qx_data = qx_value 
    10951095            output.qy_data = qy_value 
    1096         except: 
    1097             logger.error(sys.exc_value) 
     1096        except Exception as exc: 
     1097            logger.error(exc) 
    10981098 
    10991099        return output 
  • src/sas/sascalc/corfunc/corfunc_calculator.py

    ra26f67f re090ba90  
    3030            self.start = start 
    3131            self.stop = stop 
    32             self._lastx = [] 
    33             self._lasty = [] 
     32            self._lastx = np.empty(0, dtype='d') 
     33            self._lasty = None 
    3434 
    3535        def __call__(self, x): 
    3636            # If input is a single number, evaluate the function at that number 
    3737            # and return a single number 
    38             if type(x) == float or type(x) == int: 
     38            if isinstance(x, (float, int)): 
    3939                return self._smoothed_function(np.array([x]))[0] 
    4040            # If input is a list, and is different to the last input, evaluate 
     
    4242            # the function was called, return the result that was calculated 
    4343            # last time instead of explicity evaluating the function again. 
    44             elif self._lastx == [] or x.tolist() != self._lastx.tolist(): 
    45                 self._lasty = self._smoothed_function(x) 
    46                 self._lastx = x 
     44            if not np.array_equal(x, self._lastx): 
     45                self._lastx, self._lasty = x, self._smoothed_function(x) 
    4746            return self._lasty 
    4847 
     
    8887        # Only process data of the class Data1D 
    8988        if not issubclass(data.__class__, Data1D): 
    90             raise ValueError("Data must be of the type DataLoader.Data1D") 
     89            raise ValueError("Correlation function cannot be computed with 2D data.") 
    9190 
    9291        # Prepare the data 
     
    246245        """Fit the Guinier region of the curve""" 
    247246        A = np.vstack([q**2, np.ones(q.shape)]).T 
    248         return lstsq(A, np.log(iq)) 
     247        return lstsq(A, np.log(iq), rcond=None) 
    249248 
    250249    def _fit_porod(self, q, iq): 
  • src/sas/sascalc/data_util/calcthread.py

    r574adc7 re090ba90  
    66from __future__ import print_function 
    77 
    8 import traceback 
    98import sys 
    109import logging 
     10import traceback 
     11from time import sleep 
     12 
    1113try: 
    1214    import _thread as thread 
    1315except ImportError: # CRUFT: python 2 support 
    1416    import thread 
    15  
    16 if sys.platform.count("darwin") > 0: 
    17     import time 
    18     stime = time.time() 
    19  
    20     def clock(): 
    21         return time.time() - stime 
    22  
    23     def sleep(t): 
    24         return time.sleep(t) 
    25 else: 
    26     from time import clock 
    27     from time import sleep 
     17try: 
     18    from time import perf_counter as clock 
     19except ImportError: # CRUFT: python < 3.3 
     20    if sys.platform.count("darwin") > 0: 
     21        from time import time as clock 
     22    else: 
     23        from time import clock 
    2824 
    2925logger = logging.getLogger(__name__) 
    30  
    3126 
    3227class CalcThread: 
     
    248243                self.exception_handler(*sys.exc_info()) 
    249244                return 
    250             except Exception: 
     245            except Exception as exc: 
    251246                pass 
    252247        logger.error(traceback.format_exc()) 
  • src/sas/sascalc/data_util/nxsunit.py

    rb011ecb re090ba90  
    9999    Strip '^' from unit names. 
    100100 
    101     * WARNING * this will incorrect transform 10^3 to 103. 
    102     """ 
    103     s.update((k.replace('^',''),v) 
    104              for k, v in list(s.items()) 
    105              if '^' in k) 
     101    * WARNING * this will incorrectly transform 10^3 to 103. 
     102    """ 
     103    stripped = [(k.replace('^',''),v) for k, v in s.items() if '^' in k] 
     104    s.update(stripped) 
    106105 
    107106def _build_all_units(): 
  • src/sas/sascalc/data_util/ordereddicttest.py

    rb699768 re090ba90  
    147147                    ]): 
    148148            self.assert_(dup is not od) 
    149             self.assertEquals(dup, od) 
    150             self.assertEquals(list(dup.items()), list(od.items())) 
    151             self.assertEquals(len(dup), len(od)) 
    152             self.assertEquals(type(dup), type(od)) 
     149            self.assertEqual(dup, od) 
     150            self.assertEqual(list(dup.items()), list(od.items())) 
     151            self.assertEqual(len(dup), len(od)) 
     152            self.assertEqual(type(dup), type(od)) 
    153153 
    154154    def test_repr(self): 
  • src/sas/sascalc/data_util/registry.py

    ra26f67f re090ba90  
    148148            # If file has associated loader(s) and they;ve failed 
    149149            raise last_exc 
    150         raise NoKnownLoaderException(e.message)  # raise generic exception 
     150        raise NoKnownLoaderException(str(message))  # raise generic exception 
  • src/sas/sascalc/data_util/uncertainty.py

    r574adc7 re090ba90  
    1919import numpy as np 
    2020 
    21 from .import err1d 
     21from . import err1d 
    2222from .formatnum import format_uncertainty 
    2323 
  • src/sas/sascalc/dataloader/data_info.py

    r4fdcc65 re090ba90  
    2626import numpy as np 
    2727import math 
     28from math import fabs 
    2829 
    2930class plottable_1D(object): 
     
    656657        return self._perform_operation(other, operation) 
    657658 
    658     def __div__(self, other): 
     659    def __truediv__(self, other): 
    659660        """ 
    660661        Divided a data set by another 
     
    667668            return a/b 
    668669        return self._perform_operation(other, operation) 
    669  
    670     def __rdiv__(self, other): 
     670    __div__ = __truediv__ 
     671 
     672    def __rtruediv__(self, other): 
    671673        """ 
    672674        Divided a data set by another 
     
    679681            return b/a 
    680682        return self._perform_operation(other, operation) 
     683    __rdiv__ = __rtruediv__ 
    681684 
    682685    def __or__(self, other): 
     
    800803            TOLERANCE = 0.01 
    801804            for i in range(len(self.x)): 
    802                 if math.fabs((self.x[i] - other.x[i])/self.x[i]) > TOLERANCE: 
     805                if fabs(self.x[i] - other.x[i]) > self.x[i]*TOLERANCE: 
    803806                    msg = "Incompatible data sets: x-values do not match" 
    804807                    raise ValueError(msg) 
     
    10321035                raise ValueError(msg) 
    10331036            for ind in range(len(self.data)): 
    1034                 if math.fabs((self.qx_data[ind] - other.qx_data[ind])/self.qx_data[ind]) > TOLERANCE: 
     1037                if fabs(self.qx_data[ind] - other.qx_data[ind]) > fabs(self.qx_data[ind])*TOLERANCE: 
    10351038                    msg = "Incompatible data sets: qx-values do not match: %s %s" % (self.qx_data[ind], other.qx_data[ind]) 
    10361039                    raise ValueError(msg) 
    1037                 if math.fabs((self.qy_data[ind] - other.qy_data[ind])/self.qy_data[ind]) > TOLERANCE: 
     1040                if fabs(self.qy_data[ind] - other.qy_data[ind]) > fabs(self.qy_data[ind])*TOLERANCE: 
    10381041                    msg = "Incompatible data sets: qy-values do not match: %s %s" % (self.qy_data[ind], other.qy_data[ind]) 
    10391042                    raise ValueError(msg) 
  • src/sas/sascalc/dataloader/loader.py

    rb1ec23d rb1ec23d  
    169169                        if self._identify_plugin(module): 
    170170                            readers_found += 1 
    171                     except: 
     171                    except Exception as exc: 
    172172                        msg = "Loader: Error importing " 
    173                         msg += "%s\n  %s" % (item, sys.exc_value) 
     173                        msg += "%s\n  %s" % (item, exc) 
    174174                        logger.error(msg) 
    175175 
     
    191191                                if self._identify_plugin(module): 
    192192                                    readers_found += 1 
    193                             except: 
     193                            except Exception as exc: 
    194194                                msg = "Loader: Error importing" 
    195                                 msg += " %s\n  %s" % (mfile, sys.exc_value) 
     195                                msg += " %s\n  %s" % (mfile, exc) 
    196196                                logger.error(msg) 
    197197 
    198                     except: 
     198                    except Exception as exc: 
    199199                        msg = "Loader: Error importing " 
    200                         msg += " %s\n  %s" % (item, sys.exc_value) 
     200                        msg += " %s\n  %s" % (item, exc) 
    201201                        logger.error(msg) 
    202202 
     
    242242                    self.writers[ext].append(loader.write) 
    243243 
    244             except: 
     244            except Exception as exc: 
    245245                msg = "Loader: Error accessing" 
    246                 msg += " Reader in %s\n  %s" % (module.__name__, sys.exc_value) 
     246                msg += " Reader in %s\n  %s" % (module.__name__, exc) 
    247247                logger.error(msg) 
    248248        return reader_found 
     
    275275                    self.wildcards.append(wcard) 
    276276 
    277         except: 
     277        except Exception as exc: 
    278278            msg = "Loader: Error accessing Reader " 
    279             msg += "in %s\n  %s" % (loader.__name__, sys.exc_value) 
     279            msg += "in %s\n  %s" % (loader.__name__, exc) 
    280280            logger.error(msg) 
    281281        return reader_found 
     
    320320                        self.writers[ext].insert(0, loader.write) 
    321321 
    322             except: 
     322            except Exception as exc: 
    323323                msg = "Loader: Error accessing Reader" 
    324                 msg += " in %s\n  %s" % (module.__name__, sys.exc_value) 
     324                msg += " in %s\n  %s" % (module.__name__, exc) 
    325325                logger.error(msg) 
    326326        return reader_found 
  • src/sas/sascalc/dataloader/manipulations.py

    r574adc7 re4e9162  
    928928 
    929929        # Organize the results 
    930         for i in range(self.nbins): 
    931             y[i] = y[i] / y_counts[i] 
    932             y_err[i] = math.sqrt(y_err[i]) / y_counts[i] 
    933  
    934             # The type of averaging: phi,q2, or q 
    935             # Calculate x[i]should be at the center of the bin 
     930        with np.errstate(divide='ignore', invalid='ignore'): 
     931            y = y/y_counts 
     932            y_err = np.sqrt(y_err)/y_counts 
     933            # The type of averaging: phi, q2, or q 
     934            # Calculate x values at the center of the bin 
    936935            if run.lower() == 'phi': 
    937                 x[i] = (self.phi_max - self.phi_min) / self.nbins * \ 
    938                     (1.0 * i + 0.5) + self.phi_min 
     936                step = (self.phi_max - self.phi_min) / self.nbins 
     937                x = (np.arange(self.nbins) + 0.5) * step + self.phi_min 
    939938            else: 
    940                 # We take the center of ring area, not radius. 
    941                 # This is more accurate than taking the radial center of ring. 
    942                 # delta_r = (self.r_max - self.r_min) / self.nbins 
    943                 # r_inner = self.r_min + delta_r * i 
    944                 # r_outer = r_inner + delta_r 
    945                 # x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) 
    946                 x[i] = x[i] / y_counts[i] 
    947         y_err[y_err == 0] = np.average(y_err) 
     939                # set q to the average of the q values within each bin 
     940                x = x/y_counts 
     941 
     942                ### Alternate algorithm 
     943                ## We take the center of ring area, not radius. 
     944                ## This is more accurate than taking the radial center of ring. 
     945                #step = (self.r_max - self.r_min) / self.nbins 
     946                #r_inner = self.r_min + step * np.arange(self.nbins) 
     947                #x = math.sqrt((r_inner**2 + (r_inner + step)**2) / 2) 
     948 
    948949        idx = (np.isfinite(y) & np.isfinite(y_err)) 
    949950        if x_err is not None: 
  • src/sas/sascalc/dataloader/readers/associations.py

    rc7c8143 rc7c8143  
    5454                exec("loader.associate_file_type('%s', %s)" 
    5555                     % (ext.upper(), reader)) 
    56             except: 
     56            except Exception as exc: 
    5757                msg = "read_associations: skipping association" 
    58                 msg += " for %s\n  %s" % (ext.lower(), sys.exc_value) 
     58                msg += " for %s\n  %s" % (ext.lower(), exc) 
    5959                logger.error(msg) 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r058f6c3 re090ba90  
    12391239                        conv = Converter(units) 
    12401240                        setattrchain(storage, variable, conv(value, units=local_unit)) 
    1241                     except Exception: 
    1242                         _, exc_value, _ = sys.exc_info() 
     1241                    except Exception as exc: 
    12431242                        err_mess = "CanSAS reader: could not convert" 
    12441243                        err_mess += " %s unit [%s]; expecting [%s]\n  %s" \ 
    1245                             % (variable, units, local_unit, exc_value) 
     1244                            % (variable, units, local_unit, exc) 
    12461245                        self.errors.add(err_mess) 
    12471246                        if optional: 
  • src/sas/sascalc/fit/expression.py

    r574adc7 re090ba90  
    210210 
    211211    #print("Function: "+functiondef) 
    212     exec functiondef in globals,locals 
     212    exec(functiondef, globals, locals) 
    213213    retfn = locals['eval_expressions'] 
    214214 
  • src/sas/sascalc/fit/models.py

    r0f0fe42 re090ba90  
    1212import py_compile 
    1313import shutil 
     14 
     15from six import reraise 
    1416 
    1517from sasmodels.sasview_model import load_custom_model, load_standard_models 
     
    6264    try: 
    6365        new_instance = model() 
    64     except Exception: 
    65         msg = "Plugin %s error in __init__ \n\t: %s %s\n" % (str(name), 
    66                                                              str(sys.exc_type), 
    67                                                              sys.exc_info()[1]) 
     66    except Exception as exc: 
     67        msg = ("Plugin %s error in __init__ \n\t: %s %s\n" 
     68               % (name, type(exc), exc)) 
    6869        plugin_log(msg) 
    6970        return None 
     
    7273        try: 
    7374            value = new_instance.function() 
    74         except Exception: 
     75        except Exception as exc: 
    7576            msg = "Plugin %s: error writing function \n\t :%s %s\n " % \ 
    76                     (str(name), str(sys.exc_type), sys.exc_info()[1]) 
     77                    (str(name), str(type(exc)), exc) 
    7778            plugin_log(msg) 
    7879            return None 
     
    139140        if type is not None and issubclass(type, py_compile.PyCompileError): 
    140141            print("Problem with", repr(value)) 
    141             raise type, value, tb 
     142            reraise(type, value, tb) 
    142143        return 1 
    143144 
     
    153154        compileall.compile_dir(dir=dir, ddir=dir, force=0, 
    154155                               quiet=report_problem) 
    155     except Exception: 
    156         return sys.exc_info()[1] 
     156    except Exception as exc: 
     157        return exc 
    157158    return None 
    158159 
     
    185186                    model.name = PLUGIN_NAME_BASE + model.name 
    186187                plugins[model.name] = model 
    187             except Exception: 
     188            except Exception as exc: 
    188189                msg = traceback.format_exc() 
    189190                msg += "\nwhile accessing model in %r" % path 
  • src/sas/sascalc/fit/pagestate.py

    r863ac2c re090ba90  
    650650                    #Truncating string so print doesn't complain of being outside margins 
    651651                    if sys.platform != "win32": 
    652                         MAX_STRING_LENGHT = 50 
    653                         if len(file_value) > MAX_STRING_LENGHT: 
    654                             file_value = "File name:.."+file_value[-MAX_STRING_LENGHT+10:] 
     652                        MAX_STRING_LENGTH = 50 
     653                        if len(file_value) > MAX_STRING_LENGTH: 
     654                            file_value = "File name:.."+file_value[-MAX_STRING_LENGTH+10:] 
    655655                    file_name = CENTRE % file_value 
    656656                    if len(title) == 0: 
     
    905905                doc_model = newdoc.createElement('model_list_item') 
    906906                doc_model.setAttribute('checked', str(model[0].GetValue())) 
    907                 keys = model[1].keys() 
     907                keys = list(model[1].keys()) 
    908908                doc_model.setAttribute('name', str(keys[0])) 
    909909                values = model[1].get(keys[0]) 
     
    964964        if node.get('version'): 
    965965            # Get the version for model conversion purposes 
    966             x = re.sub('[^\d.]', '', node.get('version')) 
     966            x = re.sub(r'[^\d.]', '', node.get('version')) 
    967967            self.version = tuple(int(e) for e in str.split(x, ".")) 
    968968            # The tuple must be at least 3 items long 
     
    984984                try: 
    985985                    self.timestamp = float(entry.get('epoch')) 
    986                 except Exception: 
     986                except Exception as exc: 
    987987                    msg = "PageState.fromXML: Could not" 
    988                     msg += " read timestamp\n %s" % sys.exc_value 
     988                    msg += " read timestamp\n %s" % exc 
    989989                    logger.error(msg) 
    990990 
     
    12821282                        if isinstance(data.run_name, dict): 
    12831283                            # Note: key order in dict is not guaranteed, so sort 
    1284                             name = data.run_name.keys()[0] 
     1284                            name = list(data.run_name.keys())[0] 
    12851285                        else: 
    12861286                            name = data.run_name 
  • src/sas/sascalc/invariant/invariant.py

    r574adc7 re090ba90  
    344344        else: 
    345345            A = np.vstack([linearized_data.x / linearized_data.dy, 1.0 / linearized_data.dy]).T 
    346             (p, residuals, _, _) = np.linalg.lstsq(A, linearized_data.y / linearized_data.dy) 
     346            p, residuals, _, _ = np.linalg.lstsq(A, linearized_data.y / linearized_data.dy, 
     347                                                 rcond=None) 
    347348 
    348349            # Get the covariance matrix, defined as inv_cov = a_transposed * a 
  • src/sas/sascalc/pr/distance_explorer.py

    r959eb01 re090ba90  
    9999                results.pos_err.append(pos_err) 
    100100                results.osc.append(osc) 
    101             except: 
     101            except Exception as exc: 
    102102                # This inversion failed, skip this D_max value 
    103103                msg = "ExploreDialog: inversion failed for " 
    104                 msg += "D_max=%s\n %s" % (str(d), sys.exc_value) 
     104                msg += "D_max=%s\n %s" % (str(d), exc) 
    105105                results.errors.append(msg) 
    106106 
  • src/sas/sascalc/pr/fit/expression.py

    r574adc7 re090ba90  
    210210 
    211211    #print("Function: "+functiondef) 
    212     exec functiondef in globals,locals 
     212    exec(functiondef, globals, locals) 
    213213    retfn = locals['eval_expressions'] 
    214214 
  • src/sas/sascalc/pr/num_term.py

    r3e6829d r3e6829d  
    182182                data_y = np.append(data_y, test_y) 
    183183                data_err = np.append(data_err, err) 
    184             except: 
    185                 logger.error(sys.exc_value) 
     184            except Exception as exc: 
     185                logger.error(exc) 
    186186 
    187187    return data_x, data_y, data_err 
  • src/sas/sascalc/realspace/VolumeCanvas.py

    r98e3f24 re090ba90  
    472472            Return a list of the shapes 
    473473        """ 
    474         return self.shapes.keys() 
     474        return list(self.shapes.keys()) 
    475475 
    476476    def _addSingleShape(self, shapeDesc): 
  • test/calculatorview/test/utest_gui_sld.py

    r959eb01 r88d2e70  
    3333        self.sld_frame.panel.ProcessEvent(clickEvent) 
    3434        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour() 
    35         self.assert_(bkg.GetAsString() == 'pink') 
     35        self.assertTrue(bkg.GetAsString() == 'pink') 
    3636        #compute invariant without entering a value for compound 
    3737        self.sld_frame.panel.compound_ctl.SetValue("") 
     
    3939        self.sld_frame.panel.ProcessEvent(clickEvent) 
    4040        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour() 
    41         self.assert_(bkg.GetAsString() == 'pink') 
     41        self.assertTrue(bkg.GetAsString() == 'pink') 
    4242        #compute invariant without entering a value for compound 
    4343        self.sld_frame.panel.compound_ctl.SetValue("H2O") 
     
    4545        self.sld_frame.panel.ProcessEvent(clickEvent) 
    4646        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour() 
    47         self.assert_(bkg.GetAsString() == 'white') 
     47        self.assertTrue(bkg.GetAsString() == 'white') 
    4848        
    4949    def testDensityTextCtrl(self): 
     
    5959        self.sld_frame.panel.ProcessEvent(clickEvent) 
    6060        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour() 
    61         self.assert_(bkg.GetAsString() == 'pink') 
     61        self.assertTrue(bkg.GetAsString() == 'pink') 
    6262        #compute invariant without entering a value for density 
    6363        self.sld_frame.panel.compound_ctl.SetValue("H2O") 
     
    6565        self.sld_frame.panel.ProcessEvent(clickEvent) 
    6666        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour() 
    67         self.assert_(bkg.GetAsString() == 'pink') 
     67        self.assertTrue(bkg.GetAsString() == 'pink') 
    6868        #compute invariant without entering a value for density 
    6969        self.sld_frame.panel.compound_ctl.SetValue("H2O") 
     
    7171        self.sld_frame.panel.ProcessEvent(clickEvent) 
    7272        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour() 
    73         self.assert_(bkg.GetAsString() == 'white') 
     73        self.assertTrue(bkg.GetAsString() == 'white') 
    7474         
    7575    def testWavelengthTextCtrl(self): 
     
    8686        self.sld_frame.panel.ProcessEvent(clickEvent) 
    8787        bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour() 
    88         self.assert_(bkg.GetAsString() == 'pink') 
     88        self.assertTrue(bkg.GetAsString() == 'pink') 
    8989        #compute invariant without entering a value for wavelegnth 
    9090        self.sld_frame.panel.compound_ctl.SetValue("H2O") 
     
    9393        self.sld_frame.panel.ProcessEvent(clickEvent) 
    9494        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour() 
    95         self.assert_(cp_bkg.GetAsString() == 'white') 
     95        self.assertTrue(cp_bkg.GetAsString() == 'white') 
    9696        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour() 
    97         self.assert_(ds_bkg.GetAsString() == 'white') 
     97        self.assertTrue(ds_bkg.GetAsString() == 'white') 
    9898        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour() 
    9999        value = self.sld_frame.panel.wavelength_ctl.GetValue() 
    100         self.assert_(wv_bkg.GetAsString() == 'white') 
    101         self.assert_(float(value) == WAVELENGTH) 
     100        self.assertTrue(wv_bkg.GetAsString() == 'white') 
     101        self.assertTrue(float(value) == WAVELENGTH) 
    102102        sld_real = self.sld_frame.panel.neutron_sld_real_ctl.GetValue() 
    103103        sld_im = self.sld_frame.panel.neutron_sld_im_ctl.GetValue() 
     
    110110        length = self.sld_frame.panel.neutron_length_ctl.GetValue() 
    111111         
    112         self.assertAlmostEquals(float(sld_real), 1.04e-6, 1) 
    113         self.assertAlmostEquals(float(sld_im), -1.5e-7, 1) 
     112        self.assertAlmostEqual(float(sld_real), 1.04e-6, 1) 
     113        self.assertAlmostEqual(float(sld_im), -1.5e-7, 1) 
    114114        #test absorption value 
    115         self.assertAlmostEquals(float(abs) , 0.0741, 2) 
    116         self.assertAlmostEquals(float(incoh), 5.62, 2) 
     115        self.assertAlmostEqual(float(abs) , 0.0741, 2) 
     116        self.assertAlmostEqual(float(incoh), 5.62, 2) 
    117117        #Test length 
    118         self.assertAlmostEquals(float(length), 0.1755, 2) 
     118        self.assertAlmostEqual(float(length), 0.1755, 2) 
    119119        #test Cu sld 
    120         self.assertAlmostEquals(float(cu_real), 9.46e-6, 1) 
    121         self.assertAlmostEquals(float(cu_im), 3.01e-8) 
     120        self.assertAlmostEqual(float(cu_real), 9.46e-6, 1) 
     121        self.assertAlmostEqual(float(cu_im), 3.01e-8) 
    122122        # test Mo sld 
    123         self.assertAlmostEquals(float(mo_real), 9.43e-6) 
    124         self.assertAlmostEquals(float(mo_im), 5.65e-7, 1) 
     123        self.assertAlmostEqual(float(mo_real), 9.43e-6) 
     124        self.assertAlmostEqual(float(mo_im), 5.65e-7, 1) 
    125125        #compute invariant with all correct inputs value 
    126126        self.sld_frame.panel.compound_ctl.SetValue("H2O") 
     
    130130        bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour() 
    131131        value = self.sld_frame.panel.wavelength_ctl.GetValue() 
    132         self.assert_(bkg.GetAsString() == 'white') 
    133         self.assert_(float(value) == WAVELENGTH/2) 
     132        self.assertTrue(bkg.GetAsString() == 'white') 
     133        self.assertTrue(float(value) == WAVELENGTH/2) 
    134134         
    135135    def testSomeCombination(self): 
     
    145145        self.sld_frame.panel.ProcessEvent(clickEvent) 
    146146        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour() 
    147         self.assert_(cp_bkg.GetAsString() == 'white') 
     147        self.assertTrue(cp_bkg.GetAsString() == 'white') 
    148148        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour() 
    149         self.assert_(ds_bkg.GetAsString() == 'white') 
     149        self.assertTrue(ds_bkg.GetAsString() == 'white') 
    150150        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour() 
    151         self.assert_(wv_bkg.GetAsString() == 'pink') 
     151        self.assertTrue(wv_bkg.GetAsString() == 'pink') 
    152152        #density, wavelength is invalid 
    153153        self.sld_frame.panel.compound_ctl.SetValue("H2O") 
     
    158158        self.sld_frame.panel.ProcessEvent(clickEvent) 
    159159        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour() 
    160         self.assert_(cp_bkg.GetAsString() == 'white') 
     160        self.assertTrue(cp_bkg.GetAsString() == 'white') 
    161161        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour() 
    162         self.assert_(ds_bkg.GetAsString() == 'pink') 
     162        self.assertTrue(ds_bkg.GetAsString() == 'pink') 
    163163        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour() 
    164         self.assert_(wv_bkg.GetAsString() == 'pink') 
     164        self.assertTrue(wv_bkg.GetAsString() == 'pink') 
    165165        #density, wavelength is invalid 
    166166        self.sld_frame.panel.compound_ctl.SetValue("invalid compound") 
     
    171171        self.sld_frame.panel.ProcessEvent(clickEvent) 
    172172        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour() 
    173         self.assert_(cp_bkg.GetAsString() == 'pink') 
     173        self.assertTrue(cp_bkg.GetAsString() == 'pink') 
    174174        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour() 
    175         self.assert_(ds_bkg.GetAsString() == 'pink') 
     175        self.assertTrue(ds_bkg.GetAsString() == 'pink') 
    176176        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour() 
    177         self.assert_(wv_bkg.GetAsString() == 'white') 
     177        self.assertTrue(wv_bkg.GetAsString() == 'white') 
    178178        value = self.sld_frame.panel.wavelength_ctl.GetValue() 
    179         self.assert_(float(value) == WAVELENGTH) 
     179        self.assertTrue(float(value) == WAVELENGTH) 
    180180 
    181181         
  • test/pr_inversion/test/utest_explorer.py

    rf53d684 r1852b17  
    33""" 
    44 
     5import sys 
    56import os.path 
    67import unittest, math, numpy 
    7 from utest_invertor import load 
    88from sas.sascalc.pr.invertor import Invertor 
    99from sas.sascalc.pr.distance_explorer import DistExplorer 
    1010 
     11try: 
     12    from utest_invertor import load 
     13except ImportError: 
     14    from .utest_invertor import load 
    1115 
    1216def find(filename): 
     
    3640        self.assertEqual(len(results.errors), 0) 
    3741        self.assertEqual(len(results.chi2), 25) 
    38          
     42 
    3943if __name__ == '__main__': 
    4044    unittest.main() 
  • test/sascalculator/test/utest_sld.py

    ra50da82 r88d2e70  
    5151                                  molecule_formula=self.sld_formula) 
    5252        #test sld 
    53         self.assertAlmostEquals(sld_real * _SCALE, -5.6e-7, 1) 
    54         self.assertAlmostEquals(sld_im * _SCALE, 0) 
     53        self.assertAlmostEqual(sld_real * _SCALE, -5.6e-7, 1) 
     54        self.assertAlmostEqual(sld_im * _SCALE, 0) 
    5555        #test absorption value 
    56         self.assertAlmostEquals(abs, 0.0741, 2) 
    57         self.assertAlmostEquals(incoh, 5.62, 2) 
     56        self.assertAlmostEqual(abs, 0.0741, 2) 
     57        self.assertAlmostEqual(incoh, 5.62, 2) 
    5858        #Test length 
    59         self.assertAlmostEquals(length, 0.1755, 3) 
     59        self.assertAlmostEqual(length, 0.1755, 3) 
    6060        #test Cu sld 
    61         self.assertAlmostEquals(cu_real * _SCALE, 9.46e-6, 1) 
    62         self.assertAlmostEquals(cu_im * _SCALE, 3.01e-8) 
     61        self.assertAlmostEqual(cu_real * _SCALE, 9.46e-6, 1) 
     62        self.assertAlmostEqual(cu_im * _SCALE, 3.01e-8) 
    6363        # test Mo sld 
    64         self.assertAlmostEquals(mo_real * _SCALE, 9.43e-6) 
    65         self.assertAlmostEquals(mo_im * _SCALE, 5.65e-7,1) 
     64        self.assertAlmostEqual(mo_real * _SCALE, 9.43e-6) 
     65        self.assertAlmostEqual(mo_im * _SCALE, 5.65e-7,1) 
    6666 
    6767 
     
    9191                                  molecule_formula=self.sld_formula) 
    9292        #test sld 
    93         self.assertAlmostEquals(sld_real * _SCALE, 6.33e-6, 1) 
    94         self.assertAlmostEquals(sld_im * _SCALE, 0) 
     93        self.assertAlmostEqual(sld_real * _SCALE, 6.33e-6, 1) 
     94        self.assertAlmostEqual(sld_im * _SCALE, 0) 
    9595        #test absorption value 
    96         self.assertAlmostEquals(abs, 1.35e-4, 2) 
    97         self.assertAlmostEquals(incoh, 0.138, 2) 
     96        self.assertAlmostEqual(abs, 1.35e-4, 2) 
     97        self.assertAlmostEqual(incoh, 0.138, 2) 
    9898        #Test length 
    99         self.assertAlmostEquals(length, 1.549, 3) 
     99        self.assertAlmostEqual(length, 1.549, 3) 
    100100        #test Cu sld 
    101         self.assertAlmostEquals(cu_real * _SCALE, 9.36e-6, 1) 
    102         self.assertAlmostEquals(cu_im * _SCALE, 2.98e-8) 
     101        self.assertAlmostEqual(cu_real * _SCALE, 9.36e-6, 1) 
     102        self.assertAlmostEqual(cu_im * _SCALE, 2.98e-8) 
    103103        # test Mo sld 
    104         self.assertAlmostEquals(mo_real * _SCALE, 9.33e-6) 
    105         self.assertAlmostEquals(mo_im * _SCALE, 5.59e-9,1) 
     104        self.assertAlmostEqual(mo_real * _SCALE, 9.33e-6) 
     105        self.assertAlmostEqual(mo_im * _SCALE, 5.59e-9,1) 
    106106 
    107107 
     
    131131                                  molecule_formula=self.sld_formula) 
    132132        #test sld 
    133         self.assertAlmostEquals(sld_real * _SCALE, 1.04e-6, 1) 
    134         self.assertAlmostEquals(sld_im * _SCALE, -1.5e-7, 1) 
     133        self.assertAlmostEqual(sld_real * _SCALE, 1.04e-6, 1) 
     134        self.assertAlmostEqual(sld_im * _SCALE, -1.5e-7, 1) 
    135135        #test absorption value 
    136         self.assertAlmostEquals(abs, 180.0,0) 
    137         self.assertAlmostEquals(incoh, 0.0754, 2) 
     136        self.assertAlmostEqual(abs, 180.0,0) 
     137        self.assertAlmostEqual(incoh, 0.0754, 2) 
    138138        #Test length 
    139         self.assertAlmostEquals(length, 0.005551, 4) 
     139        self.assertAlmostEqual(length, 0.005551, 4) 
    140140        #test Cu sld 
    141         self.assertAlmostEquals(cu_real * _SCALE, 2.89e-5, 1) 
    142         self.assertAlmostEquals(cu_im * _SCALE, 2.81e-6) 
     141        self.assertAlmostEqual(cu_real * _SCALE, 2.89e-5, 1) 
     142        self.assertAlmostEqual(cu_im * _SCALE, 2.81e-6) 
    143143        # test Mo sld 
    144         self.assertAlmostEquals(mo_real * _SCALE, 2.84e-5, 1) 
    145         self.assertAlmostEquals(mo_im * _SCALE, 7.26e-7,1) 
     144        self.assertAlmostEqual(mo_real * _SCALE, 2.84e-5, 1) 
     145        self.assertAlmostEqual(mo_im * _SCALE, 7.26e-7,1) 
    146146 
    147147if __name__ == '__main__': 
  • test/sasdataloader/plugins/test_reader.py

    raaf5e49 r88d2e70  
    4040                    input_f =  open(path,'r') 
    4141                except : 
    42                     raise  RuntimeError, "ascii_reader: cannot open %s" % path 
     42                    raise  RuntimeError("ascii_reader: cannot open %s" % path) 
    4343                buff = input_f.read() 
    4444                lines = buff.split('\n') 
     
    5555                return output 
    5656        else: 
    57             raise RuntimeError, "%s is not a file" % path 
     57            raise RuntimeError("%s is not a file" % path) 
    5858        return None 
    5959     
  • test/sasdataloader/test/utest_abs_reader.py

    rd96744de r4cbb2f5  
    357357        self.assertEqual(self.data.dy[0], 3) 
    358358        self.assertEqual(self.data.x[1], 0.03) 
    359         self.assertAlmostEquals(self.data.y[1], 1001.0) 
     359        self.assertAlmostEqual(self.data.y[1], 1001.0) 
    360360        self.assertEqual(self.data.dxl[1], 0.005) 
    361361        self.assertEqual(self.data.dxw[1], 0.001) 
  • test/sasinvariant/test/utest_data_handling.py

    rf53d684 r88d2e70  
    4545 
    4646        # Test results 
    47         self.assertAlmostEquals(p[0], 1.0, 5) 
    48         self.assertAlmostEquals(p[1], 0.0, 5) 
     47        self.assertAlmostEqual(p[0], 1.0, 5) 
     48        self.assertAlmostEqual(p[1], 0.0, 5) 
    4949 
    5050    def test_fit_linear_data_with_noise(self): 
     
    7474 
    7575        # Test results 
    76         self.assertAlmostEquals(p[0], 1.0, 5) 
    77         self.assertAlmostEquals(p[1], 0.0, 5) 
     76        self.assertAlmostEqual(p[0], 1.0, 5) 
     77        self.assertAlmostEqual(p[1], 0.0, 5) 
    7878 
    7979    def test_fit_linear_data_with_noise_and_fixed_par(self): 
     
    506506        for i in range(len(self.data.x)): 
    507507            value  = math.fabs(test_y[i]-self.data.y[i])/self.data.y[i] 
    508             self.assert_(value < 0.001) 
     508            self.assertTrue(value < 0.001) 
    509509             
    510510class TestDataExtraLowSlitGuinier(unittest.TestCase): 
     
    553553 
    554554        test_y = inv._low_extrapolation_function.evaluate_model(x=self.data.x[:inv._low_extrapolation_npts]) 
    555         self.assert_(len(test_y) == len(self.data.y[:inv._low_extrapolation_npts])) 
     555        self.assertTrue(len(test_y) == len(self.data.y[:inv._low_extrapolation_npts])) 
    556556         
    557557        for i in range(inv._low_extrapolation_npts): 
    558558            value  = math.fabs(test_y[i]-self.data.y[i])/self.data.y[i] 
    559             self.assert_(value < 0.001) 
     559            self.assertTrue(value < 0.001) 
    560560             
    561561    def test_low_data(self): 
     
    589589                                               npts = inv._low_extrapolation_npts)  
    590590        test_y = data_in_range.y 
    591         self.assert_(len(test_y) == len(self.data.y[:inv._low_extrapolation_npts])) 
     591        self.assertTrue(len(test_y) == len(self.data.y[:inv._low_extrapolation_npts])) 
    592592        for i in range(inv._low_extrapolation_npts): 
    593593            value  = math.fabs(test_y[i]-self.data.y[i])/self.data.y[i] 
    594             self.assert_(value < 0.001)     
     594            self.assertTrue(value < 0.001) 
    595595        
    596596             
     
    642642         
    643643        test_y = inv._high_extrapolation_function.evaluate_model(x=self.data.x[start: ]) 
    644         self.assert_(len(test_y) == len(self.data.y[start:])) 
     644        self.assertTrue(len(test_y) == len(self.data.y[start:])) 
    645645         
    646646        for i in range(len(self.data.x[start:])): 
    647647            value  = math.fabs(test_y[i]-self.data.y[start+i])/self.data.y[start+i] 
    648             self.assert_(value < 0.001) 
     648            self.assertTrue(value < 0.001) 
    649649             
    650650    def test_high_data(self): 
     
    677677                                               npts = inv._high_extrapolation_npts)  
    678678        test_y = data_in_range.y 
    679         self.assert_(len(test_y) == len(self.data.y[start:])) 
     679        self.assertTrue(len(test_y) == len(self.data.y[start:])) 
    680680        temp = self.data.y[start:] 
    681681         
    682682        for i in range(len(self.data.x[start:])): 
    683683            value  = math.fabs(test_y[i]- temp[i])/temp[i] 
    684             self.assert_(value < 0.001)                 
     684            self.assertTrue(value < 0.001) 
  • test/sasinvariant/test/utest_use_cases.py

    rf53d684 r88d2e70  
    3939 
    4040        # Test results 
    41         self.assertAlmostEquals(p[0], 2.3983,3) 
    42         self.assertAlmostEquals(p[1], 0.87833,3) 
     41        self.assertAlmostEqual(p[0], 2.3983,3) 
     42        self.assertAlmostEqual(p[1], 0.87833,3) 
    4343 
    4444    def test_fit_line_data_fixed(self): 
     
    5454 
    5555        # Test results 
    56         self.assertAlmostEquals(p[0], 4) 
    57         self.assertAlmostEquals(p[1], -4.0676,3) 
     56        self.assertAlmostEqual(p[0], 4) 
     57        self.assertAlmostEqual(p[1], -4.0676,3) 
    5858 
    5959 
     
    7878 
    7979        # Test results 
    80         self.assertAlmostEquals(p[0], 2.4727,3) 
    81         self.assertAlmostEquals(p[1], 0.6,3) 
     80        self.assertAlmostEqual(p[0], 2.4727,3) 
     81        self.assertAlmostEqual(p[1], 0.6,3) 
    8282 
    8383    def test_fit_line_data_fixed_no_weight(self): 
     
    9393 
    9494        # Test results 
    95         self.assertAlmostEquals(p[0], 4) 
    96         self.assertAlmostEquals(p[1], -7.8,3) 
     95        self.assertAlmostEqual(p[0], 4) 
     96        self.assertAlmostEqual(p[1], -7.8,3) 
    9797 
    9898 
     
    132132 
    133133        # Test results 
    134         self.assertAlmostEquals(qstar, 7.48959e-5,2) 
    135         self.assertAlmostEquals(v, 0.005644689, 4) 
    136         self.assertAlmostEquals(s , 941.7452, 3) 
     134        self.assertAlmostEqual(qstar, 7.48959e-5,2) 
     135        self.assertAlmostEqual(v, 0.005644689, 4) 
     136        self.assertAlmostEqual(s , 941.7452, 3) 
    137137 
    138138    def test_use_case_2(self): 
     
    153153        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
    154154        # Test results 
    155         self.assertAlmostEquals(qstar, 7.48959e-5,2) 
    156         self.assertAlmostEquals(v, 0.005644689, 1) 
    157         self.assertAlmostEquals(s , 941.7452, 3) 
     155        self.assertAlmostEqual(qstar, 7.48959e-5,2) 
     156        self.assertAlmostEqual(v, 0.005644689, 1) 
     157        self.assertAlmostEqual(s , 941.7452, 3) 
    158158 
    159159    def test_use_case_3(self): 
     
    190190 
    191191        # Test results 
    192         self.assertAlmostEquals(qstar, 7.49e-5, 1) 
    193         self.assertAlmostEquals(v, 0.005648401, 4) 
    194         self.assertAlmostEquals(s , 941.7452, 3) 
     192        self.assertAlmostEqual(qstar, 7.49e-5, 1) 
     193        self.assertAlmostEqual(v, 0.005648401, 4) 
     194        self.assertAlmostEqual(s , 941.7452, 3) 
    195195 
    196196    def test_use_case_4(self): 
     
    218218 
    219219        # Test results 
    220         self.assertAlmostEquals(qstar, 7.49e-5,2) 
    221         self.assertAlmostEquals(v, 0.005952674, 3) 
    222         self.assertAlmostEquals(s , 941.7452, 3) 
     220        self.assertAlmostEqual(qstar, 7.49e-5,2) 
     221        self.assertAlmostEqual(v, 0.005952674, 3) 
     222        self.assertAlmostEqual(s , 941.7452, 3) 
    223223 
    224224    def test_use_case_5(self): 
     
    247247 
    248248        # Test results 
    249         self.assertAlmostEquals(qstar, 7.88981e-5,2) 
    250         self.assertAlmostEquals(v, 0.005952674, 3) 
    251         self.assertAlmostEquals(s , 941.7452, 3) 
     249        self.assertAlmostEqual(qstar, 7.88981e-5,2) 
     250        self.assertAlmostEqual(v, 0.005952674, 3) 
     251        self.assertAlmostEqual(s , 941.7452, 3) 
    252252 
    253253    def test_use_case_6(self): 
     
    273273 
    274274        # Test results 
    275         self.assertAlmostEquals(qstar, 7.49e-5,2) 
    276         self.assertAlmostEquals(v, 0.005952674, 3) 
    277         self.assertAlmostEquals(s , 941.7452, 3) 
     275        self.assertAlmostEqual(qstar, 7.49e-5,2) 
     276        self.assertAlmostEqual(v, 0.005952674, 3) 
     277        self.assertAlmostEqual(s , 941.7452, 3) 
    278278 
    279279 
     
    297297        s = inv.get_surface(contrast=2.6e-6, porod_const=2) 
    298298        # Test results 
    299         self.assertAlmostEquals(qstar, 1.361677e-3, 4) 
    300         self.assertAlmostEquals(v, 0.115352622, 2) 
    301         self.assertAlmostEquals(s , 941.7452, 3 ) 
     299        self.assertAlmostEqual(qstar, 1.361677e-3, 4) 
     300        self.assertAlmostEqual(v, 0.115352622, 2) 
     301        self.assertAlmostEqual(s , 941.7452, 3 ) 
    302302 
    303303    def test_use_case_2(self): 
     
    315315        s, ds = inv.get_surface_with_error(contrast=2.6e-6, porod_const=2) 
    316316        # Test results 
    317         self.assertAlmostEquals(qstar, 1.361677e-3, 4) 
    318         self.assertAlmostEquals(v, 0.115352622, 2) 
    319         self.assertAlmostEquals(s , 941.7452, 3 ) 
     317        self.assertAlmostEqual(qstar, 1.361677e-3, 4) 
     318        self.assertAlmostEqual(v, 0.115352622, 2) 
     319        self.assertAlmostEqual(s , 941.7452, 3 ) 
    320320 
    321321    def test_use_case_3(self): 
     
    336336 
    337337        # Test results 
    338         self.assertAlmostEquals(qstar, 0.00138756,2) 
    339         self.assertAlmostEquals(v, 0.117226896,2) 
    340         self.assertAlmostEquals(s ,941.7452, 3) 
     338        self.assertAlmostEqual(qstar, 0.00138756,2) 
     339        self.assertAlmostEqual(v, 0.117226896,2) 
     340        self.assertAlmostEqual(s ,941.7452, 3) 
    341341 
    342342    def test_use_case_4(self): 
     
    354354 
    355355        # Test results 
    356         self.assertAlmostEquals(qstar, 0.0045773,2) 
     356        self.assertAlmostEqual(qstar, 0.0045773,2) 
    357357 
    358358    def test_use_case_5(self): 
     
    374374 
    375375        # Test results 
    376         self.assertAlmostEquals(qstar, 0.00460319,3) 
     376        self.assertAlmostEqual(qstar, 0.00460319,3) 
    377377       
    378378   
  • test/sasrealspace/test/utest_oriented.py

    r1cdbcd8 r88d2e70  
    5959        ana_val = self.ana.runXY([0.1, 0.1]) 
    6060        sim_val = self.model.getIq2D(0.1, 0.1) 
    61         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.1 ) 
     61        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.1 ) 
    6262 
    6363class TestCylinderAddObject(unittest.TestCase): 
     
    101101        #print ana_val, sim_val, sim_val/ana_val 
    102102 
    103         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     103        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    104104 
    105105 
     
    143143        #print ana_val, sim_val, sim_val/ana_val 
    144144 
    145         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     145        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    146146 
    147147    def testalongZ(self): 
     
    156156        #print ana_val, sim_val, sim_val/ana_val 
    157157 
    158         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     158        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    159159 
    160160    def testalongX(self): 
     
    169169        #print ana_val, sim_val, sim_val/ana_val 
    170170 
    171         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     171        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    172172 
    173173class TestEllipsoid(unittest.TestCase): 
     
    213213        #print ana_val, sim_val, sim_val/ana_val 
    214214 
    215         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     215        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    216216 
    217217    def testalongZ(self): 
     
    226226        #print ana_val, sim_val, sim_val/ana_val 
    227227 
    228         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     228        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    229229 
    230230    def testalongY(self): 
     
    240240 
    241241        try: 
    242             self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     242            self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    243243        except Exception: 
    244244            print("Error", ana_val, sim_val, sim_val/ana_val) 
     
    295295        sim_val, err = self.canvas.getIq2DError(0.1, 0.2) 
    296296 
    297         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     297        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    298298 
    299299class TestCoreShellError(unittest.TestCase): 
     
    347347        sim_val, err = self.canvas.getIq2DError(0.1, 0.2) 
    348348 
    349         self.assert_( math.fabs(sim_val-ana_val) < 3.0 * err ) 
     349        self.assertTrue( math.fabs(sim_val-ana_val) < 3.0 * err ) 
    350350 
    351351class TestRunMethods(unittest.TestCase): 
     
    392392 
    393393        try: 
    394             self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     394            self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    395395        except Exception: 
    396396            print("Error", ana_val, sim_val, sim_val/ana_val) 
     
    404404 
    405405        try: 
    406             self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     406            self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    407407        except Exception: 
    408408            print("Error", ana_val, sim_val, sim_val/ana_val) 
     
    416416 
    417417        try: 
    418             self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     418            self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    419419        except Exception: 
    420420            print("Error", ana_val, sim_val, sim_val/ana_val) 
     
    428428 
    429429        try: 
    430             self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     430            self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    431431        except Exception: 
    432432            print("Error", ana_val, sim_val, sim_val/ana_val) 
     
    471471        sim_val = self.model.getIq2D(0.1, 0.2) 
    472472 
    473         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     473        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    474474 
    475475        # Change the radius a re-evaluate 
     
    479479        ana_val = self.ana.runXY([0.1, 0.2]) 
    480480        sim_val = self.model.getIq2D(0.1, 0.2) 
    481         self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
     481        self.assertTrue( math.fabs(sim_val/ana_val-1.0)<0.05 ) 
    482482 
    483483 
  • test/sasrealspace/test/utest_realspace.py

    r1cdbcd8 r88d2e70  
    3838        self.model.add('ellipsoid','elli2') 
    3939        self.model.delete('elli2') 
    40         self.assert_('elli2' not in self.model.getShapeList()) 
     40        self.assertTrue('elli2' not in self.model.getShapeList()) 
    4141 
    4242    def testsetParam(self): 
     
    8181        value_2 = self.canvas.getIq(0.001) 
    8282 
    83         self.assert_( (value_1-value_2)/value_1 < 0.1) 
     83        self.assertTrue( (value_1-value_2)/value_1 < 0.1) 
    8484 
    8585    def testSetDensityTiming(self): 
     
    9999        t_2 = time.time()-t_0 
    100100 
    101         self.assert_( t_2 < t_1 and (t_1-t_2)/t_2 > 2) 
     101        self.assertTrue( t_2 < t_1 and (t_1-t_2)/t_2 > 2) 
    102102 
    103103    def testGetParamList(self): 
    104104        """ Test GetParamList on empty canvas""" 
    105         self.assert_('lores_density' in self.canvas.getParamList()) 
     105        self.assertTrue('lores_density' in self.canvas.getParamList()) 
    106106        handle = self.canvas.add('sphere') 
    107107 
     
    109109        """ Test GetParamList on filled canvas""" 
    110110        self.canvas.add('sphere') 
    111         self.assert_('lores_density' in self.canvas.getParamList()) 
     111        self.assertTrue('lores_density' in self.canvas.getParamList()) 
    112112 
    113113    def testAdd(self): 
     
    151151        # THIS WILL DEPEND ON THE NUMBER OF SPACE POINTS: 
    152152        # that why we need some error analysis. 
    153         self.assert_( (sim_2*ana_1/sim_1 - ana_2)/ana_2 < 0.1) 
     153        self.assertTrue( (sim_2*ana_1/sim_1 - ana_2)/ana_2 < 0.1) 
    154154 
    155155        # test the absolute amplitude 
    156         self.assert_( math.fabs(sim_2-ana_2)/ana_2 < 0.1) 
     156        self.assertTrue( math.fabs(sim_2-ana_2)/ana_2 < 0.1) 
    157157 
    158158    def testGetIq2(self): 
     
    196196        sim_2 = self.canvas.getIq(0.01) 
    197197 
    198         self.assert_((sim_2-sim_1)/sim_1<0.05) 
     198        self.assertTrue((sim_2-sim_1)/sim_1<0.05) 
    199199 
    200200    def testGetIq_time(self): 
     
    216216        delta_2 = time.time()-t_0 
    217217 
    218         self.assert_((delta_2-delta_1)/delta_1<0.05) 
     218        self.assertTrue((delta_2-delta_1)/delta_1<0.05) 
    219219 
    220220 
     
    342342        ana = self.sphere.run(0.05) 
    343343        val, err = self.canvas.getIqError(0.05) 
    344         self.assert_(math.fabs(ana-val)<2.0*err) 
     344        self.assertTrue(math.fabs(ana-val)<2.0*err) 
    345345 
    346346    def testRightOrder(self): 
     
    350350        val, err = self.canvas.getIqError(0.05) 
    351351        #print 'right', ana, val, err 
    352         self.assert_(math.fabs(ana-val)/ana < 1.1) 
     352        self.assertTrue(math.fabs(ana-val)/ana < 1.1) 
    353353 
    354354    def testWrongOrder(self): 
     
    365365        val, err = self.canvas.getIqError(0.05) 
    366366        #print 'wrong', ana, val, err 
    367         self.assert_(math.fabs(ana-val)/ana < 1.1) 
     367        self.assertTrue(math.fabs(ana-val)/ana < 1.1) 
    368368 
    369369 
Note: See TracChangeset for help on using the changeset viewer.