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,20 +15,24 @@ ...@@ -15,20 +15,24 @@
Fall back to pure Python implementations. Fall back to pure Python implementations.
""" """
try: import os
PURE_PYTHON = os.environ.get('PURE_PYTHON')
if not PURE_PYTHON:
try:
from persistent.cPersistence import Persistent from persistent.cPersistence import Persistent
from persistent.cPersistence import GHOST from persistent.cPersistence import GHOST
from persistent.cPersistence import UPTODATE from persistent.cPersistence import UPTODATE
from persistent.cPersistence import CHANGED from persistent.cPersistence import CHANGED
from persistent.cPersistence import STICKY from persistent.cPersistence import STICKY
from persistent.cPersistence import simple_new from persistent.cPersistence import simple_new
except ImportError: #pragma NO COVER except ImportError: #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: else:
from persistent._compat import copy_reg from persistent._compat import copy_reg
copy_reg.constructor(simple_new) copy_reg.constructor(simple_new)
# Make an interface declaration for Persistent, if zope.interface # Make an interface declaration for Persistent, if zope.interface
...@@ -41,14 +45,25 @@ else: ...@@ -41,14 +45,25 @@ else:
from persistent.interfaces import IPersistent from persistent.interfaces import IPersistent
classImplements(Persistent, IPersistent) classImplements(Persistent, IPersistent)
try: try:
from persistent.cPickleCache import PickleCache from persistent.cPickleCache import PickleCache
except ImportError: #pragma NO COVER except ImportError: #pragma NO COVER
from persistent.picklecache import PickleCache from persistent.picklecache import PickleCache
try: try:
import persistent.TimeStamp import persistent.TimeStamp
except ImportError: #pragma NO COVER 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 GHOST
from persistent.persistence import UPTODATE
from persistent.persistence import CHANGED
from persistent.persistence import STICKY
from persistent.picklecache import PickleCache
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,11 +1322,12 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base): ...@@ -1321,11 +1322,12 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
_add_to_suite = [PyPersistentTests] _add_to_suite = [PyPersistentTests]
try: if not os.environ.get('PURE_PYTHON'):
try:
from persistent import cPersistence from persistent import cPersistence
except ImportError: except ImportError:
pass pass
else: else:
class CPersistentTests(unittest.TestCase, _Persistent_Base): class CPersistentTests(unittest.TestCase, _Persistent_Base):
def _getTargetClass(self): def _getTargetClass(self):
......
...@@ -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