Commit ef8b08c8 authored by Tres Seaver's avatar Tres Seaver

Add test for PURE_PYTHON environment.

parent 70f6dd75
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
4.0.7 (unreleased) 4.0.7 (unreleased)
------------------ ------------------
- Add ``PURE_PYTHON`` environment variable support: if set, the C
extensions will not be built or imported.
4.0.6 (2013-01-03) 4.0.6 (2013-01-03)
------------------ ------------------
......
...@@ -15,40 +15,55 @@ ...@@ -15,40 +15,55 @@
Fall back to pure Python implementations. Fall back to pure Python implementations.
""" """
try: import os
from persistent.cPersistence import Persistent
from persistent.cPersistence import GHOST PURE_PYTHON = os.environ.get('PURE_PYTHON')
from persistent.cPersistence import UPTODATE if not PURE_PYTHON:
from persistent.cPersistence import CHANGED try:
from persistent.cPersistence import STICKY from persistent.cPersistence import Persistent
from persistent.cPersistence import simple_new from persistent.cPersistence import GHOST
except ImportError: #pragma NO COVER from persistent.cPersistence import UPTODATE
from persistent.cPersistence import CHANGED
from persistent.cPersistence import STICKY
from persistent.cPersistence import simple_new
except ImportError: #pragma NO COVER
from persistent.persistence import Persistent
from persistent.persistence import GHOST
from persistent.persistence import UPTODATE
from persistent.persistence import CHANGED
from persistent.persistence import STICKY
else:
from persistent._compat import copy_reg
copy_reg.constructor(simple_new)
# Make an interface declaration for Persistent, if zope.interface
# is available. Note that the Python version already does this.
try:
from zope.interface import classImplements
except ImportError: #pragma NO COVER
pass
else:
from persistent.interfaces import IPersistent
classImplements(Persistent, IPersistent)
try:
from persistent.cPickleCache import PickleCache
except ImportError: #pragma NO COVER
from persistent.picklecache import PickleCache
try:
import persistent.TimeStamp
except ImportError: #pragma NO COVER
import persistent.timestamp as TimeStamp
import sys
sys.modules['persistent.TimeStamp'
] = sys.modules['persistent.timestamp']
else: #pragma NO COVER
from persistent.persistence import Persistent from persistent.persistence import Persistent
from persistent.persistence import GHOST from persistent.persistence import GHOST
from persistent.persistence import UPTODATE from persistent.persistence import UPTODATE
from persistent.persistence import CHANGED from persistent.persistence import CHANGED
from persistent.persistence import STICKY from persistent.persistence import STICKY
else:
from persistent._compat import copy_reg
copy_reg.constructor(simple_new)
# Make an interface declaration for Persistent, if zope.interface
# is available. Note that the Python version already does this.
try:
from zope.interface import classImplements
except ImportError: #pragma NO COVER
pass
else:
from persistent.interfaces import IPersistent
classImplements(Persistent, IPersistent)
try:
from persistent.cPickleCache import PickleCache
except ImportError: #pragma NO COVER
from persistent.picklecache import PickleCache from persistent.picklecache import PickleCache
try:
import persistent.TimeStamp
except ImportError: #pragma NO COVER
import persistent.timestamp as TimeStamp import persistent.timestamp as TimeStamp
import sys import sys
sys.modules['persistent.TimeStamp'] = sys.modules['persistent.timestamp'] sys.modules['persistent.TimeStamp'] = sys.modules['persistent.timestamp']
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
import os
import unittest import unittest
class _Persistent_Base(object): class _Persistent_Base(object):
...@@ -1321,49 +1322,50 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base): ...@@ -1321,49 +1322,50 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
_add_to_suite = [PyPersistentTests] _add_to_suite = [PyPersistentTests]
try: if not os.environ.get('PURE_PYTHON'):
from persistent import cPersistence try:
except ImportError: from persistent import cPersistence
pass except ImportError:
else: pass
class CPersistentTests(unittest.TestCase, _Persistent_Base): else:
class CPersistentTests(unittest.TestCase, _Persistent_Base):
def _getTargetClass(self):
from persistent.cPersistence import Persistent def _getTargetClass(self):
return Persistent from persistent.cPersistence import Persistent
return Persistent
def _checkMRU(self, jar, value):
pass # Figure this out later def _checkMRU(self, jar, value):
pass # Figure this out later
def _clearMRU(self, jar):
pass # Figure this out later def _clearMRU(self, jar):
pass # Figure this out later
def _makeCache(self, jar):
from persistent.cPickleCache import PickleCache def _makeCache(self, jar):
return PickleCache(jar) from persistent.cPickleCache import PickleCache
return PickleCache(jar)
_add_to_suite.append(CPersistentTests)
_add_to_suite.append(CPersistentTests)
class Test_simple_new(unittest.TestCase):
class Test_simple_new(unittest.TestCase):
def _callFUT(self, x):
from persistent.cPersistence import simple_new def _callFUT(self, x):
return simple_new(x) from persistent.cPersistence import simple_new
return simple_new(x)
def test_w_non_type(self):
self.assertRaises(TypeError, self._callFUT, '') def test_w_non_type(self):
self.assertRaises(TypeError, self._callFUT, '')
def test_w_type(self):
import sys def test_w_type(self):
TO_CREATE = [type, list, tuple, object] import sys
# Python 3.3 segfaults when destroying a dict created via TO_CREATE = [type, list, tuple, object]
# PyType_GenericNew. See http://bugs.python.org/issue16676 # Python 3.3 segfaults when destroying a dict created via
if sys.version_info < (3, 3): # PyType_GenericNew. See http://bugs.python.org/issue16676
TO_CREATE.append(dict) if sys.version_info < (3, 3):
for typ in TO_CREATE: TO_CREATE.append(dict)
self.assertTrue(isinstance(self._callFUT(typ), typ)) for typ in TO_CREATE:
self.assertTrue(isinstance(self._callFUT(typ), typ))
_add_to_suite.append(Test_simple_new)
_add_to_suite.append(Test_simple_new)
def test_suite(): def test_suite():
return unittest.TestSuite([unittest.makeSuite(x) for x in _add_to_suite]) return unittest.TestSuite([unittest.makeSuite(x) for x in _add_to_suite])
...@@ -31,11 +31,12 @@ README = (open(os.path.join(here, 'README.rst')).read() ...@@ -31,11 +31,12 @@ README = (open(os.path.join(here, 'README.rst')).read()
py_impl = getattr(platform, 'python_implementation', lambda: None) py_impl = getattr(platform, 'python_implementation', lambda: None)
is_pypy = py_impl() == 'PyPy' is_pypy = py_impl() == 'PyPy'
is_jython = 'java' in sys.platform is_jython = 'java' in sys.platform
is_pure = os.environ.get('PURE_PYTHON')
# Jython cannot build the C optimizations, while on PyPy they are # Jython cannot build the C optimizations, while on PyPy they are
# anti-optimizations (the C extension compatibility layer is known-slow, # anti-optimizations (the C extension compatibility layer is known-slow,
# and defeats JIT opportunities). # and defeats JIT opportunities).
if is_pypy or is_jython: if is_pypy or is_jython or is_pure:
ext_modules = headers = [] ext_modules = headers = []
else: else:
ext_modules = [Extension(name = 'persistent.cPersistence', ext_modules = [Extension(name = 'persistent.cPersistence',
......
...@@ -3,7 +3,7 @@ envlist = ...@@ -3,7 +3,7 @@ envlist =
# Jython support pending 2.7 support, due 2012-07-15 or so. See: # Jython support pending 2.7 support, due 2012-07-15 or so. See:
# http://fwierzbicki.blogspot.com/2012/03/adconion-to-fund-jython-27.html # http://fwierzbicki.blogspot.com/2012/03/adconion-to-fund-jython-27.html
# py26,py27,py32,jython,pypy,coverage,docs # py26,py27,py32,jython,pypy,coverage,docs
py26,py27,pypy,py32,py33,coverage,docs py26,py27,py27-pure,pypy,py32,py33,coverage,docs
[testenv] [testenv]
deps = deps =
...@@ -15,6 +15,16 @@ commands = ...@@ -15,6 +15,16 @@ commands =
commands = commands =
jython setup.py test -q jython setup.py test -q
[testenv:py27-pure]
basepython =
python2.7
setenv =
PURE_PYTHON = 1
deps =
zope.interface
commands =
python setup.py test -q
[testenv:coverage] [testenv:coverage]
basepython = basepython =
python2.6 python2.6
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment