From d6ffb6d63fd096392c196af58e8bf82345f15652 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 8 Sep 2011 10:47:27 -0400 Subject: [PATCH] Add pypiezo.test.get_piezo_config and fix ConfigSetting -> Setting typo for PiezoConfig. --- pypiezo/config.py | 2 +- pypiezo/test.py | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 pypiezo/test.py 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 -- 2.26.2