1 | """ |
---|
2 | Unit tests for specific models |
---|
3 | @author: Mathieu Doucet / UTK |
---|
4 | """ |
---|
5 | |
---|
6 | import unittest |
---|
7 | from pyre.applications.Script import Script |
---|
8 | from 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 | |
---|
17 | class 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 | |
---|
36 | class 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 | |
---|
67 | if __name__ == '__main__': |
---|
68 | unittest.main() |
---|