Commits

dan mackinlay committed d5d931a

serialisation tests

  • Participants
  • Parent commits ddac599

Comments (0)

Files changed (3)

     
     def __init__(self, initval=[], work_dir=None, *args, **kwargs):
         if work_dir is None:
-            work_dir = get_tmp_dir()
-        self.work_dir = path(work_dir)
+            work_dir = unicode(get_tmp_dir())
+        self.work_dir = path(work_dir).realpath().abspath()
         if not self.work_dir.exists():
             self.work_dir.mkdir()
         for key, val in getattr(initval, 'iteritems', initval.__iter__)():
             return all([self[key]==other[key] for key in other]) and \
               len(self.keys())==len(other.keys())
         except KeyError:
-            return False
+            return False
+    
+    def __getstate__(self):
+        state = self.__dict__.copy()
+        # path objects seem to occasionally resurrect gracelessly
+        state['work_dir'] = unicode(state['work_dir'].realpath().abspath())
+        return state
+    
+    def __setstate__(self, dict):
+        self.__dict__ = dict
+        self.work_dir = path(self.work_dir)
+
       description="A class providing dictionary access to a folder.",
       long_description="""\
 A class providing dictionary access to a folder. Handy if you are RAM-constrained but not dsick constrained, or if you want an intuitive way of managing a folders' contents.""",
-      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+      classifiers=[
+        'Development Status :: 4 - Beta',
+        'Topic :: Utilities',
+      ], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       keywords='',
       author='Daniel MacKinlay',
       author_email='fillmewithspam@email.possumpalace.org',

tests/fsdict_tests.py

 from nose import with_setup
 from nose.tools import nottest, assert_equal, assert_true, assert_false
 from fsdict import FSDict
+import pickle
+from pickle import loads, dumps
+
+def test_fsdict_pickles():
+    "occasionally something goes wrong with work_dir in pickling"
+    d1 = FSDict({'a':'b'})
+    d2 = loads(dumps(d1))
+    yield assert_equal, d1, d2
+    yield assert_equal, d1.work_dir, d2.work_dir
 
 def test_fsdict_loads():
     import pickle