From: W. Trevor King Date: Sat, 21 Aug 2010 17:18:34 +0000 (-0400) Subject: Add doctests proving recursive curve->command_stack->arguments->curve serializing... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bef08c58d0c0e2482c8aa65def15f80875b78e5d;p=hooke.git Add doctests proving recursive curve->command_stack->arguments->curve serializing works --- diff --git a/hooke/command_stack.py b/hooke/command_stack.py index 6e84a91..4d5cd01 100644 --- a/hooke/command_stack.py +++ b/hooke/command_stack.py @@ -163,6 +163,25 @@ class CommandStack (list): >>> c.clear() >>> print [repr(cm) for cm in c] [] + + YAMLize a curve argument. + + >>> from .curve import Curve + >>> c.append(CommandMessage('curve info', {'curve': Curve(path=None)})) + >>> print yaml.dump(c) + !!python/object/new:hooke.command_stack.CommandStack + listitems: + - !!python/object:hooke.engine.CommandMessage + arguments: + curve: !!python/object:hooke.curve.Curve + command_stack: !!python/object:hooke.command_stack.CommandStack {} + data: null + driver: null + info: {} + name: null + path: null + command: curve info + """ def execute(self, hooke, filter=None, stack=False): """Execute a stack of commands. diff --git a/hooke/curve.py b/hooke/curve.py index 64b4c61..9f92e59 100644 --- a/hooke/curve.py +++ b/hooke/curve.py @@ -163,6 +163,40 @@ class Curve (object): Another important attribute is :attr:`command_stack`, which holds a :class:`~hooke.command_stack.CommandStack` listing the commands that have been applied to the `Curve` since loading. + + The data-type is pickleable, to ensure we can move it between + processes with :class:`multiprocessing.Queue`\s. + + >>> import pickle + >>> import yaml + >>> from .engine import CommandMessage + >>> c = Curve(path='some/path') + + We add a recursive reference to `c` as you would get from + :meth:`hooke.plugin.curve.CurveCommand._add_to_command_stack`. + + >>> c.command_stack.append(CommandMessage('curve info', {'curve':c})) + + >>> s = pickle.dumps(c) + >>> z = pickle.loads(s) + >>> z + + >>> z.command_stack[-1].arguments['curve'] == z + True + >>> print yaml.dump(c) + &id001 !!python/object:hooke.curve.Curve + command_stack: !!python/object/new:hooke.command_stack.CommandStack + listitems: + - !!python/object:hooke.engine.CommandMessage + arguments: + curve: *id001 + command: curve info + data: null + driver: null + info: {} + name: path + path: some/path + """ def __init__(self, path, info=None): #the data dictionary contains: {name of data: list of data sets [{[x], [y]}] @@ -192,7 +226,6 @@ class Curve (object): def __getstate__(self): state = dict(self.__dict__) # make a copy of the attribute dict. - state['info'] = dict(self.info) # make a copy of the info dict too. del(state['_hooke']) return state