From: W. Trevor King Date: Thu, 15 Mar 2012 21:30:38 +0000 (-0400) Subject: Don't initialize devices explicitly in doctests. X-Git-Tag: v0.4~25 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=79e4110e3972b5dc981b1f68973092efb5cdb28c;p=pyafm.git Don't initialize devices explicitly in doctests. Rely on the internal `.load_from_config()` methods to do that for us. This reduces duplication (e.g. device filename only set in config defaults, not in doctests too). It also makes it posible to use several devices to build your AFM interface, where the old doctests would only work with all the communication going through a single card. --- diff --git a/pyafm/afm.py b/pyafm/afm.py index cac6269..2c228e1 100644 --- a/pyafm/afm.py +++ b/pyafm/afm.py @@ -52,7 +52,6 @@ class AFM (object): >>> import os >>> import tempfile - >>> from pycomedi.device import Device >>> from pycomedi import constant >>> import pypiezo.config >>> import pyafm.config @@ -62,8 +61,7 @@ class AFM (object): >>> fd,filename = tempfile.mkstemp(suffix='.h5', prefix='pyafm-') >>> os.close(fd) - >>> device = Device('/dev/comedi0') - >>> device.open() + >>> devices = [] >>> config = pyafm.config.AFMConfig() >>> config['piezo'] = pypiezo.config.PiezoConfig() @@ -83,7 +81,7 @@ class AFM (object): >>> config['temperature'] = pyafm.config.TemperatureConfig() >>> config['temperature']['name'] = 'test temperature' - >>> afm = AFM(config=config, devices=[device]) + >>> afm = AFM(config=config, devices=devices) >>> afm.setup_config() >>> afm.get_temperature() # doctest: +SKIP @@ -262,14 +260,15 @@ class AFM (object): test temperature Celsius - >>> afm2 = pyafm.storage.load_afm(filename=filename, devices=[device]) + >>> afm2 = pyafm.storage.load_afm(filename=filename, devices=devices) >>> afm2.get_temperature() # doctest: +SKIP 297.37 It's hard to test anything else without pugging into an actual AFM. - >>> device.close() + >>> for device in devices: + ... device.close() Cleanup our temporary config file. diff --git a/pyafm/digital_port.py b/pyafm/digital_port.py index bdce8f8..0abe5c1 100644 --- a/pyafm/digital_port.py +++ b/pyafm/digital_port.py @@ -7,22 +7,21 @@ import pypiezo.base as _base class DigitalPort (object): """A digital input/output port (i.e. cluster of channels). - >>> from pycomedi.device import Device >>> from pyafm.config import DigitalPortConfig - >>> device = Device('/dev/comedi0') - >>> device.open() + >>> devices = [] >>> config = DigitalPortConfig() >>> config['channels'] = [1, 2, 3, 4] >>> config['name'] = 'test port' - >>> port = DigitalPort(config=config, devices=[device]) + >>> port = DigitalPort(config=config, devices=devices) >>> port.write_bitfield(13) >>> port.write([1, 0, 1, 0]) >>> port.write_bitfield(0) - >>> device.close() + >>> for device in devices: + ... device.close() """ def __init__(self, config, devices=None): self.config = config diff --git a/pyafm/stepper.py b/pyafm/stepper.py index cc2573d..d82acce 100644 --- a/pyafm/stepper.py +++ b/pyafm/stepper.py @@ -11,12 +11,10 @@ class Stepper(_stepper.Stepper): Uses `DigitalPort` for transmitting the output. - >>> from pycomedi.device import Device >>> from pycomedi import constant as _constant >>> from pyafm.config import StepperConfig, DigitalPortConfig - >>> device = Device('/dev/comedi0') - >>> device.open() + >>> devices = [] >>> config = StepperConfig() >>> config['port'] = DigitalPortConfig() @@ -25,14 +23,15 @@ class Stepper(_stepper.Stepper): >>> config['port']['name'] = 'stepper port' >>> config['name'] = 'test stepper' - >>> s = Stepper(config=config, devices=[device]) + >>> s = Stepper(config=config, devices=devices) >>> s.position 0 >>> s.single_step(1) >>> s.position 2 - >>> device.close() + >>> for device in devices: + ... device.close() """ def __init__(self, config, devices=None): self.config = config