Commit ef8b08c8 authored by Tres Seaver's avatar Tres Seaver

Add test for PURE_PYTHON environment.

parent 70f6dd75
......@@ -5,6 +5,9 @@
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)
------------------
......
......@@ -15,40 +15,55 @@
Fall back to pure Python implementations.
"""
try:
from persistent.cPersistence import Persistent
from persistent.cPersistence import GHOST
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
import os
PURE_PYTHON = os.environ.get('PURE_PYTHON')
if not PURE_PYTHON:
try:
from persistent.cPersistence import Persistent
from persistent.cPersistence import GHOST
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 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']
......@@ -11,6 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import os
import unittest
class _Persistent_Base(object):
......@@ -1321,49 +1322,50 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
_add_to_suite = [PyPersistentTests]
try:
from persistent import cPersistence
except ImportError:
pass
else:
class CPersistentTests(unittest.TestCase, _Persistent_Base):
def _getTargetClass(self):
from persistent.cPersistence import Persistent
return Persistent
def _checkMRU(self, jar, value):
pass # Figure this out later
def _clearMRU(self, jar):
pass # Figure this out later
def _makeCache(self, jar):
from persistent.cPickleCache import PickleCache
return PickleCache(jar)
_add_to_suite.append(CPersistentTests)
class Test_simple_new(unittest.TestCase):
def _callFUT(self, 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_type(self):
import sys
TO_CREATE = [type, list, tuple, object]
# Python 3.3 segfaults when destroying a dict created via
# PyType_GenericNew. See http://bugs.python.org/issue16676
if sys.version_info < (3, 3):
TO_CREATE.append(dict)
for typ in TO_CREATE:
self.assertTrue(isinstance(self._callFUT(typ), typ))
_add_to_suite.append(Test_simple_new)
if not os.environ.get('PURE_PYTHON'):
try:
from persistent import cPersistence
except ImportError:
pass
else:
class CPersistentTests(unittest.TestCase, _Persistent_Base):
def _getTargetClass(self):
from persistent.cPersistence import Persistent
return Persistent
def _checkMRU(self, jar, value):
pass # Figure this out later
def _clearMRU(self, jar):
pass # Figure this out later
def _makeCache(self, jar):
from persistent.cPickleCache import PickleCache
return PickleCache(jar)
_add_to_suite.append(CPersistentTests)
class Test_simple_new(unittest.TestCase):
def _callFUT(self, 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_type(self):
import sys
TO_CREATE = [type, list, tuple, object]
# Python 3.3 segfaults when destroying a dict created via
# PyType_GenericNew. See http://bugs.python.org/issue16676
if sys.version_info < (3, 3):
TO_CREATE.append(dict)
for typ in TO_CREATE:
self.assertTrue(isinstance(self._callFUT(typ), typ))
_add_to_suite.append(Test_simple_new)
def test_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()
py_impl = getattr(platform, 'python_implementation', lambda: None)
is_pypy = py_impl() == 'PyPy'
is_jython = 'java' in sys.platform
is_pure = os.environ.get('PURE_PYTHON')
# Jython cannot build the C optimizations, while on PyPy they are
# anti-optimizations (the C extension compatibility layer is known-slow,
# and defeats JIT opportunities).
if is_pypy or is_jython:
if is_pypy or is_jython or is_pure:
ext_modules = headers = []
else:
ext_modules = [Extension(name = 'persistent.cPersistence',
......
......@@ -3,7 +3,7 @@ envlist =
# 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
# py26,py27,py32,jython,pypy,coverage,docs
py26,py27,pypy,py32,py33,coverage,docs
py26,py27,py27-pure,pypy,py32,py33,coverage,docs
[testenv]
deps =
......@@ -15,6 +15,16 @@ commands =
commands =
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]
basepython =
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