[pypy-svn] r58769 - pypy/branch/2.5-merge/lib-python/modified-2.5.2/test
arigo at codespeak.net
arigo at codespeak.net
Tue Oct 7 17:20:31 CEST 2008
Author: arigo
Date: Tue Oct 7 17:20:28 2008
New Revision: 58769
Added:
pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_support.py
- copied, changed from r58763, pypy/branch/2.5-merge/lib-python/2.5.2/test/test_support.py
Modified:
pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_itertools.py
Log:
Add a proposed extension to test_support to make PyPy-specific extensions
a bit more official. Try to use it in test_itertools.py.
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_itertools.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_itertools.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_itertools.py Tue Oct 7 17:20:28 2008
@@ -195,11 +195,10 @@
zip('abc', 'def'))
self.assertEqual([pair for pair in izip('abc', 'def')],
zip('abc', 'def'))
- # the following test deals with a specific implementation detail,
- # that izip "reuses" the SAME tuple object each time when it can;
- # it does not apply correctly to pypy, so I'm commenting it -- AM
- # ids = map(id, izip('abc', 'def'))
- # self.assertEqual(min(ids), max(ids))
+ if test_support.check_impl_detail:
+ # izip "reuses" the same tuple object each time when it can
+ ids = map(id, izip('abc', 'def'))
+ self.assertEqual(min(ids), max(ids))
ids = map(id, list(izip('abc', 'def')))
self.assertEqual(len(dict.fromkeys(ids)), len(ids))
@@ -364,11 +363,9 @@
self.assertRaises(TypeError, tee, [1,2], 3, 'x')
# tee object should be instantiable
- # XXX why?? the following test would pass too if type(a)('def')
- # just returned iter('abc')...
- #a, b = tee('abc')
- #c = type(a)('def')
- #self.assertEqual(list(c), list('def'))
+ a, b = tee('abc')
+ c = type(a)('def')
+ self.assertEqual(list(c), list('def'))
# test long-lagged and multi-way split
a, b, c = tee(xrange(2000), 3)
@@ -394,20 +391,19 @@
self.assert_(a is c)
# test tee_new
- # XXX the same "why??" as above
- #t1, t2 = tee('abc')
- #tnew = type(t1)
- #self.assertRaises(TypeError, tnew)
- #self.assertRaises(TypeError, tnew, 10)
- #t3 = tnew(t1)
- #self.assert_(list(t1) == list(t2) == list(t3) == list('abc'))
+ t1, t2 = tee('abc')
+ tnew = type(t1)
+ self.assertRaises(TypeError, tnew)
+ self.assertRaises(TypeError, tnew, 10)
+ t3 = tnew(t1)
+ self.assert_(list(t1) == list(t2) == list(t3) == list('abc'))
# test that tee objects are weak referencable
a, b = tee(xrange(10))
p = proxy(a)
self.assertEqual(getattr(p, '__class__'), type(b))
del a
- import gc; gc.collect(); gc.collect(); gc.collect()
+ test_support.gc_collect()
self.assertRaises(ReferenceError, getattr, p, '__class__')
def test_StopIteration(self):
Copied: pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_support.py (from r58763, pypy/branch/2.5-merge/lib-python/2.5.2/test/test_support.py)
==============================================================================
--- pypy/branch/2.5-merge/lib-python/2.5.2/test/test_support.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_support.py Tue Oct 7 17:20:28 2008
@@ -525,3 +525,38 @@
break
except:
break
+
+#=======================================================================
+# distinguishing between language-level tests and implementation details
+
+# Use the following flag to guard CPython's implementation-specific tests.
+check_impl_detail = (hasattr(sys, 'subversion') and
+ sys.subversion[0] == 'CPython')
+
+def impl_detail(f):
+ """A decorator to skip a whole function if not running on top of CPython.
+ """
+ if check_impl_details:
+ return f
+ else:
+ def _skip_check_impl_detail(*args, **kwds):
+ if verbose:
+ sys.stderr.write("Skipping %s because of memory "
+ "constraint\n" % (f.__name__,))
+ return
+ return skip_check_impl_detail
+
+def gc_collect():
+ """Force as many objects as possible to be collected.
+
+ In non-CPython implementations of Python, this is needed because
+ timely deallocation is not guaranteed by the garbage collector.
+ (Even in CPython this can be the case in case of reference cycles.)
+ This means that __del__ methods may be called later than expected
+ and weakrefs may remain alive for longer than expected. This
+ function tries its best to force all garbage objects to disappear.
+ """
+ import gc
+ gc.collect()
+ gc.collect()
+ gc.collect()
More information about the Pypy-commit
mailing list