Adapt testlib.py in order to be compatible with Jython which doesn't have a __builtins__ module. Closes #99627.

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset121719962a24
branchstable
phasepublic
hiddenno
parent revision#fe2c72b2dc90 Generalise usage of disutils.sysconfig.get_python_version so eg. is_standard_module works for other python impl. like Jython, IronPython (and should works for pypy). Closes #99493
child revision#8e76e81b594c 0.58.1
files modified by this revision
ChangeLog
testlib.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1342532368 -7200
# Tue Jul 17 15:39:28 2012 +0200
# Branch stable
# Node ID 121719962a24f3b6274e42c22602e3093c2cf85a
# Parent fe2c72b2dc900b0f746a5286b62420aa7cb37f19
Adapt testlib.py in order to be compatible with Jython which doesn't have a __builtins__ module. Closes #99627.

diff --git a/ChangeLog b/ChangeLog
@@ -1,10 +1,10 @@
1  ChangeLog for logilab.common
2  ============================
3 
4 -	--
5 -* modutils: be more python implementation independant (closes #99493)
6 +--
7 +    * modutils, testlib: be more python implementation independant (closes #99493 and #99627)
8 
9  2012-04-12  -- 0.58.0
10      * new `registry` module containing a backport of CubicWeb selectable objects registry (closes #84654)
11 
12      * testlib: DocTestCase fix builtins pollution after doctest execution.
diff --git a/testlib.py b/testlib.py
@@ -51,12 +51,14 @@
13  import math
14  import warnings
15  from shutil import rmtree
16  from operator import itemgetter
17  from ConfigParser import ConfigParser
18 +from itertools import dropwhile
19 +
20  from logilab.common.deprecation import deprecated
21 -from itertools import dropwhile
22 +from logilab.common.compat import builtins
23 
24  import unittest as unittest_legacy
25  if not getattr(unittest_legacy, "__package__", None):
26      try:
27          import unittest2 as unittest
@@ -948,11 +950,11 @@
28 
29      @deprecated('Non-standard. Please use assertMultiLineEqual instead.')
30      def assertTextEquals(self, text1, text2, junk=None,
31              msg_prefix='Text differ', striplines=False):
32          """compare two multiline strings (using difflib and splitlines())
33 -        
34 +
35          :param text1: a Python BaseString
36          :param text2: a second Python Basestring
37          :param junk: List of Caracters
38          :param msg_prefix: String (message prefix)
39          :param striplines: Boolean to trigger line stripping before comparing
@@ -1214,16 +1216,16 @@
40                  suite = doctest.DocTestSuite(self.module)
41          except AttributeError:
42              suite = SkippedSuite()
43          # doctest may gork the builtins dictionnary
44          # This happen to the "_" entry used by gettext
45 -        old_builtins =  __builtins__.copy()
46 +        old_builtins = builtins.__dict__.copy()
47          try:
48              return suite.run(result)
49          finally:
50 -            __builtins__.clear()
51 -            __builtins__.update(old_builtins)
52 +            builtins.__dict__.clear()
53 +            builtins.__dict__.update(old_builtins)
54      run = __call__
55 
56      def test(self):
57          """just there to trigger test execution"""
58