Add doctests proving recursive curve->command_stack->arguments->curve serializing...
authorW. Trevor King <wking@drexel.edu>
Sat, 21 Aug 2010 17:18:34 +0000 (13:18 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 21 Aug 2010 17:18:34 +0000 (13:18 -0400)
hooke/command_stack.py
hooke/curve.py

index 6e84a913f1ff9731ad2da74927bb7694361b946d..4d5cd01f0aeec343c584c43991e27d55d46369ae 100644 (file)
@@ -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
+    <BLANKLINE>
     """
     def execute(self, hooke, filter=None, stack=False):
         """Execute a stack of commands.
index 64b4c61db56c13d5fd56b73b32a9fe6416db6267..9f92e599acad6c62f499a4d8d815422aabb95a87 100644 (file)
@@ -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
+    <Curve path>
+    >>> 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
+    <BLANKLINE>
     """
     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