source: sasview/sansmodels/src/sans/models/pyre/utest_pyremodels.py @ 8cfdd5e

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 8cfdd5e was ae3ce4e, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

Moving sansmodels to trunk

  • Property mode set to 100644
File size: 2.0 KB
Line 
1"""
2    Unit tests for specific models
3    @author: Mathieu Doucet / UTK
4"""
5
6import unittest
7from pyre.applications.Script import Script
8from sans.models.ModelFactory import ModelFactory
9
10# Disable "missing docstring" complaint
11# pylint: disable-msg=C0111
12# Disable "too many methods" complaint
13# pylint: disable-msg=R0904
14# Disable "could be a function" complaint
15# pylint: disable-msg=R0201
16
17class TestScript(Script):
18   
19    def main(self, *args, **kwds):
20        pass
21
22    def newModel(self, model_name):
23        """
24            Instantiate a new model
25            @param model_name: name of new model [string]
26        """
27        import pyre.inventory
28       
29        fac = pyre.inventory.facility('model', default = model_name)
30        new_model, locator = fac._getDefaultValue(self.inventory)
31        new_model._configure()
32        new_model._init()
33       
34        return new_model
35
36class TestPyreComponent(unittest.TestCase):
37    """ Unit tests for sphere model """
38   
39    def setUp(self):
40        self.pyre_script = TestScript('test')
41        self.pyre_script.run()
42
43    def testSphere(self):
44        sphere = self.pyre_script.newModel('sphere')
45        oracle = ModelFactory().getModel("SphereModel")
46        self.assertEqual(sphere(1.0), oracle.run(1.0))
47
48    def testCylinder(self):
49        sphere = self.pyre_script.newModel('cylinder')
50        oracle = ModelFactory().getModel("CylinderModel")
51        self.assertEqual(sphere(1.0), oracle.run(1.0))
52
53    def test2DSphere(self):
54        sphere = self.pyre_script.newModel('sphere')
55        oracle = ModelFactory().getModel("SphereModel")
56        self.assertEqual(sphere([1.0, 1.57]), oracle.run(1.0))
57
58    def testSetParam(self):
59        sphere = self.pyre_script.newModel('sphere')
60        sphere.set('radius', 10.0)
61        oracle = ModelFactory().getModel("SphereModel")
62        oracle.setParam('radius', 10.0)
63        self.assertEqual(sphere(1.0), oracle.run(1.0))
64
65 
66
67if __name__ == '__main__':
68    unittest.main()
Note: See TracBrowser for help on using the repository browser.