2 # -*- coding: utf-8 -*-
4 This file is part of the hkl library.
6 The hkl library is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 The hkl library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
19 Copyright (C) 2012 Synchrotron SOLEIL
20 L'Orme des Merisiers Saint-Aubin
21 BP 48 91192 GIF-sur-YVETTE CEDEX
22 Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
27 from gi
.repository
import GLib
28 from gi
.repository
import Hkl
31 class TestAPI(unittest
.TestCase
):
33 def test_detector_api(self
):
35 enforce the detector API
38 # create an 0D HklDetector
39 detector
= Hkl
.Detector().factory_new(Hkl
.DetectorType(0))
41 # mount the detector on the 2nd holder of the geometry
42 # yes numbering follow the C convention !
44 self
.assertTrue(detector
.idx
== 1)
46 def test_geometry_api(self
):
48 enforce the geometry API
51 # get the config for a given geometry and create the
52 # corresponding HklGeometry
53 config
= Hkl
.geometry_factory_get_config_from_type(
54 Hkl
.GeometryType
.KAPPA6C
)
55 geometry
= Hkl
.Geometry
.factory_newv(config
, [50. * math
.pi
/ 180.])
57 # axes names are accessible
59 isinstance([axis
.parameter
.name
for axis
in geometry
.axes()],
62 # set the geometry axes values
63 values_w
= [0, 30, 0, 0, 0, 60]
64 geometry
.set_axes_values_unit(values_w
)
65 values_r
= geometry
.get_axes_values_unit()
67 # check that the read and write values of the geometry are
69 for r
, w
in zip(values_w
, values_r
):
70 self
.assertAlmostEqual(r
, w
)
72 def test_pseudoaxis_api(self
):
74 enforce the HklEngine API
77 detector
= Hkl
.Detector().factory_new(Hkl
.DetectorType(0))
80 config
= Hkl
.geometry_factory_get_config_from_type(
81 Hkl
.GeometryType
.KAPPA6C
)
82 geometry
= Hkl
.Geometry
.factory_newv(config
, [math
.radians(50.)])
83 values_w
= [0., 30., 0., 0., 0., 60.]
84 geometry
.set_axes_values_unit(values_w
)
86 sample
= Hkl
.Sample
.new("toto", Hkl
.SampleType
.MONOCRYSTAL
)
87 sample
.set_lattice(1.54, 1.54, 1.54,
92 # compute all the pseudo axes managed by all engines
93 engines
= Hkl
.EngineList
.factory(config
)
94 engines
.init(geometry
, detector
, sample
)
97 # get the hkl engine and do a computation
98 hkl
= engines
.get_by_name("hkl")
99 values
= hkl
.pseudo_axes
.get_values_unit()
101 # set the hkl engine and get the results
104 hkl
.pseudo_axes
.set_values_unit(values
)
105 solutions
= engines
.geometries()
106 for item
in solutions
.items():
107 item
.geometry
.get_axes_values_unit()
108 except GLib
.GError
, err
:
112 # for item in engines.geometries.items():
113 # print item.geometry.get_axes_values_unit()
115 # check that all the values computed are reachable
116 for engine
in engines
.engines():
117 self
.assertTrue(type(engine
) is Hkl
.Engine
)
118 self
.assertTrue(type(engine
.info
.name
) is str)
119 for parameter
in engine
.pseudo_axes
.parameters():
120 self
.assertTrue(type(parameter
) is Hkl
.Parameter
)
121 self
.assertTrue(type(parameter
.get_value()) is float)
123 # check the set result
124 for item
in engines
.geometries().items():
125 self
.assertTrue(type(item
) is Hkl
.GeometryListItem
)
126 self
.assertTrue(type(item
.geometry
) is Hkl
.Geometry
)
128 self
.assertTrue(True)
130 @unittest.skip("for testing figures")
131 def test_doc_exemple(self
):
132 #execfile("../../Documentation/sphinx/source/bindings/python.py")
133 execfile("../../Documentation/sphinx/source/pyplots/trajectory_simple.py")
134 execfile("../../Documentation/sphinx/source/pyplots/trajectory_full.py")
136 self
.assertTrue(False)
138 def test_sample_api(self
):
140 enforce the HklSample API
144 sample
= Hkl
.Sample
.new("toto", Hkl
.SampleType
.MONOCRYSTAL
)
145 self
.assertTrue(sample
.name
== "toto")
147 #set the lattice parameters
148 sample
.set_lattice(1.54, 1.54, 1.54,
154 if __name__
== '__main__':