Add pypiezo.test.get_piezo_config and fix ConfigSetting -> Setting typo for PiezoConfig.
authorW. Trevor King <wking@drexel.edu>
Thu, 8 Sep 2011 14:47:27 +0000 (10:47 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 8 Sep 2011 14:47:27 +0000 (10:47 -0400)
pypiezo/config.py
pypiezo/test.py [new file with mode: 0644]

index a366b31d968287e75fa808c2251787314d5dae14..2039b57eef772dbc7d3cb4f792aa6e2320b0ae0e 100644 (file)
@@ -121,7 +121,7 @@ class AxisConfig (_config.Config):
 class PiezoConfig (_config.Config):
     "Configure a piezo experiment"
     settings = [
-        _config.ConfigSetting(
+        _config.Setting(
             name='name',
             help="Piezo name (so the user will know what it's used for).",
             default=None),
diff --git a/pypiezo/test.py b/pypiezo/test.py
new file mode 100644 (file)
index 0000000..20a383b
--- /dev/null
@@ -0,0 +1,121 @@
+# Copyright (C) 2011 W. Trevor King <wking@drexel.edu>
+#
+# This file is part of pypiezo.
+#
+# pypiezo is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# pypiezo is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with pypiezo.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Construct example piezo configurations to simplify testing
+
+These methods make it easier to write tests in packages that depend on
+pypiezo.
+"""
+
+from .config import AxisConfig as _AxisConfig
+from .config import InputChannelConfig as _InputChannelConfig
+from .config import OutputChannelConfig as _OutputChannelConfig
+from .config import PiezoConfig as _PiezoConfig
+
+
+def get_piezo_config(storage=None):
+    """Return a default PiezoConfig instance.
+
+    >>> p = get_piezo_config()
+    >>> print p.dump()
+    name: test piezo
+    axes:
+      0:
+        gain: 1.0
+        sensitivity: 1.0
+        minimum: None
+        maximum: None
+        channel:
+          name: x
+          device: /dev/comedi0
+          subdevice: -1
+          channel: 0
+          maxdata: 100
+          range: 1
+          conversion-coefficients: 0, 1
+          conversion-origin: 0
+          inverse-conversion-coefficients: 0, 1
+          inverse-conversion-origin: 0
+        monitor: 
+      1:
+        gain: 1.0
+        sensitivity: 1.0
+        minimum: None
+        maximum: None
+        channel:
+          name: z
+          device: /dev/comedi0
+          subdevice: -1
+          channel: 1
+          maxdata: 100
+          range: 1
+          conversion-coefficients: 0, 1
+          conversion-origin: 0
+          inverse-conversion-coefficients: 0, 1
+          inverse-conversion-origin: 0
+        monitor: 
+    inputs:
+      0:
+        name: deflection
+        device: /dev/comedi0
+        subdevice: -1
+        channel: 0
+        maxdata: 100
+        range: 1
+        conversion-coefficients: 0, 1
+        conversion-origin: 0
+        inverse-conversion-coefficients: 0, 1
+        inverse-conversion-origin: 0
+      1:
+        name: temperature
+        device: /dev/comedi0
+        subdevice: -1
+        channel: 1
+        maxdata: 100
+        range: 1
+        conversion-coefficients: 0, 1
+        conversion-origin: 0
+        inverse-conversion-coefficients: 0, 1
+        inverse-conversion-origin: 0
+    """
+    piezo_config = _PiezoConfig(storage=storage)
+    piezo_config['name'] = 'test piezo'
+    piezo_config['axes'] = []
+    for i,name in enumerate(['x', 'z']):
+        axis = _AxisConfig()
+        axis['channel'] = _OutputChannelConfig()
+        axis['channel']['name'] = name
+        axis['channel']['channel'] = i
+        axis['channel']['maxdata'] = 100
+        axis['channel']['conversion-coefficients'] = (0,1)
+        axis['channel']['conversion-origin'] = 0
+        axis['channel']['inverse-conversion-coefficients'] = (0,1)
+        axis['channel']['inverse-conversion-origin'] = 0
+        piezo_config['axes'].append(axis)
+    piezo_config['inputs'] = []
+    for i,name in enumerate(['deflection', 'temperature']):
+        channel = _InputChannelConfig()
+        channel = _OutputChannelConfig()
+        channel['name'] = name
+        channel['channel'] = i
+        channel['maxdata'] = 100
+        channel['conversion-coefficients'] = (0,1)
+        channel['conversion-origin'] = 0
+        channel['inverse-conversion-coefficients'] = (0,1)
+        channel['inverse-conversion-origin'] = 0
+        piezo_config['inputs'].append(channel)
+    return piezo_config