[py-svn] commit/py: hpk: fix issue1 - make py.error.* instances pickleable
Bitbucket
commits-noreply at bitbucket.org
Thu Jan 13 20:11:30 CET 2011
1 new changeset in py:
http://bitbucket.org/hpk42/py/changeset/c5f99061a6f8/
changeset: r1995:c5f99061a6f8
user: hpk
date: 2011-01-13 20:11:17
summary: fix issue1 - make py.error.* instances pickleable
affected #: 4 files (547 bytes)
--- a/CHANGELOG Wed Jan 12 19:16:36 2011 +0100
+++ b/CHANGELOG Thu Jan 13 20:11:17 2011 +0100
@@ -1,6 +1,8 @@
Changes between 1.4.0 and 1.4.1
==================================================
+- fix issue1 - py.error.* classes to be pickleable
+
- fix (pytest-) issue10 and refine assertion reinterpretation
to avoid breaking if the __nonzero__ of an object fails
--- a/py/__init__.py Wed Jan 12 19:16:36 2011 +0100
+++ b/py/__init__.py Thu Jan 13 20:11:17 2011 +0100
@@ -12,6 +12,10 @@
from py import _apipkg
+# so that py.error.* instances are picklable
+import sys
+sys.modules['py.error'] = _apipkg.AliasModule("py.error", "py._error", 'error')
+
_apipkg.initpkg(__name__, attr={'_apipkg': _apipkg}, exportdefs={
# access to all standard lib modules
'std': '._std:std',
@@ -141,3 +145,4 @@
},
})
+
--- a/py/_apipkg.py Wed Jan 12 19:16:36 2011 +0100
+++ b/py/_apipkg.py Thu Jan 13 20:11:17 2011 +0100
@@ -9,7 +9,7 @@
import sys
from types import ModuleType
-__version__ = '1.2.dev5'
+__version__ = '1.2.dev6'
def initpkg(pkgname, exportdefs, attr=dict()):
""" initialize given package from the export definitions. """
@@ -136,18 +136,24 @@
__dict__ = property(__dict__)
-def AliasModule(modname, modpath):
+def AliasModule(modname, modpath, attrname=None):
mod = []
def getmod():
if not mod:
- mod.append(importobj(modpath, None))
+ x = importobj(modpath, None)
+ if attrname is not None:
+ x = getattr(x, attrname)
+ mod.append(x)
return mod[0]
class AliasModule(ModuleType):
def __repr__(self):
- return '<AliasModule %r for %r>' % (modname, modpath)
+ x = modpath
+ if attrname:
+ x += "." + attrname
+ return '<AliasModule %r for %r>' % (modname, x)
def __getattribute__(self, name):
return getattr(getmod(), name)
--- a/testing/root/test_error.py Wed Jan 12 19:16:36 2011 +0100
+++ b/testing/root/test_error.py Thu Jan 13 20:11:17 2011 +0100
@@ -9,6 +9,12 @@
assert issubclass(x, py.error.Error)
assert issubclass(x, EnvironmentError)
+def test_picklability_issue1():
+ e1 = py.error.ENOENT()
+ s = py.std.pickle.dumps(e1)
+ e2 = py.std.pickle.loads(s)
+ assert isinstance(e2, py.error.ENOENT)
+
def test_unknown_error():
num = 3999
cls = py.error._geterrnoclass(num)
Repository URL: https://bitbucket.org/hpk42/py/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list