surface: Ensure min_position < max_position in _get_min_max_positions
[pypiezo.git] / pypiezo / test.py
1 # Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
2 #
3 # This file is part of pypiezo.
4 #
5 # pypiezo is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # pypiezo is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # pypiezo.  If not, see <http://www.gnu.org/licenses/>.
16
17 """Construct example piezo configurations to simplify testing
18
19 These methods make it easier to write tests in packages that depend on
20 pypiezo.
21 """
22
23 from .base import get_axis_name as _get_axis_name
24 from .config import AxisConfig as _AxisConfig
25 from .config import InputChannelConfig as _InputChannelConfig
26 from .config import OutputChannelConfig as _OutputChannelConfig
27 from .config import PiezoConfig as _PiezoConfig
28
29
30 def get_piezo_config(storage=None):
31     """Return a default PiezoConfig instance.
32
33     >>> p = get_piezo_config()
34     >>> print p.dump()  # doctest: +REPORT_UDIFF
35     name: test piezo
36     axes:
37       0:
38         gain: 1.0
39         sensitivity: 1.0
40         minimum: None
41         maximum: None
42         channel:
43           name: x
44           device: /dev/comedi0
45           subdevice: -1
46           channel: 0
47           maxdata: 100
48           range: 0
49           analog-reference: ground
50           conversion-coefficients: 0, 1
51           conversion-origin: 0
52           inverse-conversion-coefficients: 0, 1
53           inverse-conversion-origin: 0
54         monitor: 
55       1:
56         gain: 1.0
57         sensitivity: 1.0
58         minimum: None
59         maximum: None
60         channel:
61           name: z
62           device: /dev/comedi0
63           subdevice: -1
64           channel: 1
65           maxdata: 100
66           range: 0
67           analog-reference: ground
68           conversion-coefficients: 0, 1
69           conversion-origin: 0
70           inverse-conversion-coefficients: 0, 1
71           inverse-conversion-origin: 0
72         monitor: 
73     inputs:
74       0:
75         name: deflection
76         device: /dev/comedi0
77         subdevice: -1
78         channel: 0
79         maxdata: 100
80         range: 0
81         analog-reference: ground
82         conversion-coefficients: 0, 1
83         conversion-origin: 0
84         inverse-conversion-coefficients: 0, 1
85         inverse-conversion-origin: 0
86       1:
87         name: temperature
88         device: /dev/comedi0
89         subdevice: -1
90         channel: 1
91         maxdata: 100
92         range: 0
93         analog-reference: ground
94         conversion-coefficients: 0, 1
95         conversion-origin: 0
96         inverse-conversion-coefficients: 0, 1
97         inverse-conversion-origin: 0
98     >>> _get_axis_name(p['axes'][0])
99     'x'
100     >>> d = p.select_config('inputs', 'deflection')
101     >>> d['name']
102     'deflection'
103     """
104     piezo_config = _PiezoConfig(storage=storage)
105     piezo_config['name'] = 'test piezo'
106     piezo_config['axes'] = []
107     for i,name in enumerate(['x', 'z']):
108         axis = _AxisConfig()
109         axis['channel'] = _OutputChannelConfig()
110         axis['channel']['name'] = name
111         axis['channel']['channel'] = i
112         axis['channel']['maxdata'] = 100
113         axis['channel']['conversion-coefficients'] = (0,1)
114         axis['channel']['conversion-origin'] = 0
115         axis['channel']['inverse-conversion-coefficients'] = (0,1)
116         axis['channel']['inverse-conversion-origin'] = 0
117         piezo_config['axes'].append(axis)
118     piezo_config['inputs'] = []
119     for i,name in enumerate(['deflection', 'temperature']):
120         channel = _InputChannelConfig()
121         channel = _OutputChannelConfig()
122         channel['name'] = name
123         channel['channel'] = i
124         channel['maxdata'] = 100
125         channel['conversion-coefficients'] = (0,1)
126         channel['conversion-origin'] = 0
127         channel['inverse-conversion-coefficients'] = (0,1)
128         channel['inverse-conversion-origin'] = 0
129         piezo_config['inputs'].append(channel)
130     return piezo_config