source: sasview/sansmodels/test/utest_newstylemodels.py @ b11e127

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since b11e127 was 18e250c, checked in by Gervaise Alina <gervyh@…>, 13 years ago

move test to sansmodels top level

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[1b162dfa]1"""
2    Unit tests for dispersion functionality of
3    C++ model classes
4"""
[ae60f86]5print "New style models are still under development"
[1b162dfa]6import unittest, math, numpy
7
8class TestModel(object):
9    """
10        An old-style model
11    """
12    def __init__(self):
13        ## Parameter dictionary
14        self.params = {}
15        self.params['scale']       = 0.05
16       
17        ## Parameter details [units, min, max]
18        self.details = {}
19        self.details['scale']       = ['',     None, None]
20
21    def run(self, x):
22        return self.params['scale']*x
23
[8809e48]24from sans.models.BaseModel import BaseModel, Parameter, ParameterProperty
[1b162dfa]25class NewTestModel(BaseModel):
26    scale = ParameterProperty('scale')
27   
28    def __init__(self): 
29        BaseModel.__init__(self) 
30        self.parameters = {}
31        self.parameters['scale'] = Parameter('scale', 4.0) 
32       
[8809e48]33       
34    def runXY(self, x):
[1b162dfa]35        return self.scale*x
36       
[8809e48]37class TestBogusModel(unittest.TestCase):
38    def setUp(self):
39        self.model = NewTestModel()
40       
41    def test_call(self):
42        self.assertEqual(self.model(1), 4.0)
43        self.model.scale = 1.0
44        self.assertEqual(self.model(1), 1.0)
45        self.model.setParam('scale',2.0)
46        self.assertEqual(self.model(1), 2.0)
47        self.assertEqual(self.model.getParam('scale'), 2.0)
48       
[1b162dfa]49class TestBaseModel(unittest.TestCase):
50    """
51        Testing C++ Cylinder model
52    """
53    def setUp(self):
54        from sans.models.BaseModel import BaseModel
55        self.model = BaseModel()
56       
57       
58    def test_removed_attrs(self):
59        def setop():
60            print self.model.operateOn
61        self.assertRaises(AttributeError, setop)
62        def setother():
63            print self.model.other
64        self.assertRaises(AttributeError, setother)
65       
66class TestAdaptor(unittest.TestCase):
67    """
68        Testing C++ Cylinder model
69    """
70    def setUp(self):
[ae60f86]71        from sans.models.NewCylinderModel import CylinderModel
72        self.model = CylinderModel()
[1b162dfa]73       
74       
75    def test_setparam(self):
[ae60f86]76        self.model.setParam("length", 151.0)
77        self.assertEquals(self.model.getParam("length"), 151.0)
78       
79       
80       
81        print self.model(0.001)
[8809e48]82        print self.model.parameters['length']
[ae60f86]83        self.model.setParam("length", 250.0)
[8809e48]84        self.assertEquals(self.model.getParam("length"), 250.0)
85       
86        print self.model.parameters['length']
[ae60f86]87        print self.model(0.001)
[1b162dfa]88       
89   
90 
91if __name__ == '__main__':
92    unittest.main()
93   
Note: See TracBrowser for help on using the repository browser.