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