From: W. Trevor King Date: Thu, 8 Sep 2011 14:47:27 +0000 (-0400) Subject: Add pypiezo.test.get_piezo_config and fix ConfigSetting -> Setting typo for PiezoConfig. X-Git-Tag: 0.6~38 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d6ffb6d63fd096392c196af58e8bf82345f15652;p=pypiezo.git Add pypiezo.test.get_piezo_config and fix ConfigSetting -> Setting typo for PiezoConfig. --- diff --git a/pypiezo/config.py b/pypiezo/config.py index a366b31..2039b57 100644 --- a/pypiezo/config.py +++ b/pypiezo/config.py @@ -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 index 0000000..20a383b --- /dev/null +++ b/pypiezo/test.py @@ -0,0 +1,121 @@ +# Copyright (C) 2011 W. Trevor King +# +# 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 . + +"""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