[Zope3-checkins] SVN: zope.testing/trunk/ Back out my changes that I moved over to a branch.

Christian Theune ct at gocept.com
Mon Feb 16 14:29:34 EST 2009


Log message for revision 96602:
  Back out my changes that I moved over to a branch.
  

Changed:
  U   zope.testing/trunk/CHANGES.txt
  U   zope.testing/trunk/src/zope/testing/module.txt
  D   zope.testing/trunk/src/zope/testing/testrunner/importcheck.py
  D   zope.testing/trunk/src/zope/testing/testrunner/importcheck.txt
  D   zope.testing/trunk/src/zope/testing/testrunner/importchecker-fixtures/
  U   zope.testing/trunk/src/zope/testing/testrunner/options.py
  U   zope.testing/trunk/src/zope/testing/testrunner/runner.py
  U   zope.testing/trunk/src/zope/testing/testrunner/testrunner-debugging-layer-setup.test
  U   zope.testing/trunk/src/zope/testing/testrunner/testrunner-edge-cases.txt
  U   zope.testing/trunk/src/zope/testing/testrunner/testrunner-errors.txt
  U   zope.testing/trunk/src/zope/testing/testrunner/tests.py

-=-
Modified: zope.testing/trunk/CHANGES.txt
===================================================================
--- zope.testing/trunk/CHANGES.txt	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/CHANGES.txt	2009-02-16 19:29:33 UTC (rev 96602)
@@ -1,13 +1,6 @@
 zope.testing Changelog
 **********************
 
-3.7.2 (unreleased)
-==================
-
-- Added feature that warns about re-imports of symbols that originate
-  from a different location. This allows detecting when classes and
-  functions get moved from one module to another.
-
 3.7.1 (2008-10-17)
 ==================
 

Modified: zope.testing/trunk/src/zope/testing/module.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/module.txt	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/module.txt	2009-02-16 19:29:33 UTC (rev 96602)
@@ -89,7 +89,7 @@
   >>> import zope.testing.unlikelymodulename
   Traceback (most recent call last):
     ...
-  ImportError: No module named zope.testing.unlikelymodulename
+  ImportError: No module named unlikelymodulename
 
 This only works for packages that already exist::
  

Deleted: zope.testing/trunk/src/zope/testing/testrunner/importcheck.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/importcheck.py	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/testrunner/importcheck.py	2009-02-16 19:29:33 UTC (rev 96602)
@@ -1,230 +0,0 @@
-# vim:fileencoding=utf-8
-# Copyright (c) 2008 gocept gmbh & co. kg
-# See also LICENSE.txt
-
-# XXX: Is there *any* way to detect instances that are shuffled around?
-
-import ihooks
-import os.path
-import sys
-import types
-import zope.testing.testrunner.feature
-import inspect
-
-
-WHITELIST = [('re', 'match', 'sre'),
-             ('new', 'module', '__builtin__'),
-             ('os', 'error', 'exceptions')]
-
-wrapper_cache = {}
-seen = set()
-
-
-def guess_package_name(frame):
-    """Guess which package a code frame originated from."""
-    if '__name__' in frame.f_globals:
-        return frame.f_globals['__name__']
-    filename = frame.f_globals['__file__']
-    for mod in sys.modules.values():
-        if not hasattr(mod, '__file__'):
-            continue
-        if os.path.dirname(mod.__file__) == os.path.dirname(filename):
-            return mod.__name__
-    raise RuntimeError("Can't guess module name for %r" % frame)
-
-
-def rule_whitelist(import_mod, name, real_mod):
-    # No warning for things on the whitelist.
-    return (import_mod, name, real_mod) in WHITELIST
-
-
-def rule_doctest(import_mod, name, real_mod):
-    # doctest regularly sticks stuff somewhere else. We
-    # ignore those.
-    return real_mod in ['doctest', 'zope.testing.doctest']
-
-
-def rule_stdlib_and_builtins(import_mod, name, real_mod):
-    # Some builtins are redirected within the stdlib (and vice versa)
-    if import_mod == 'sys' and name in ['stdin', 'stdout']:
-        return True
-    if import_mod == 'os' and real_mod == 'posix':
-        return True
-    if name == '__class__' and real_mod == '__builtin__':
-        return True
-    if import_mod == '__builtin__' and real_mod == 'exceptions':
-        return True
-    if (import_mod == 'types' or
-          import_mod.startswith('xml.dom')) and real_mod == '__builtin__':
-        # No warning for the types from the type module that
-        # really originate from builtins
-        return True
-
-
-def rule_intra_package_reimport(import_mod, name, real_mod):
-    # Don't warn if the package of a module re-exports a symbol.
-    return import_mod.split('.') == real_mod.split('.')[:-1]
-
-
-def rule_intra_package_reimport2(import_mod, name, real_mod):
-    # Don't warn if symbols of an underscore module are reimported
-    # by a module belonging to the same package.
-    real_path = real_mod.split('.')
-    real_module = real_path[-1]
-    base = '.'.join(real_path[:-1]) + '.'
-    return real_module.startswith('_') and import_mod.startswith(base)
-
-
-def rule_unclean_c_module(import_mod, name, real_mod):
-    # The real module seems to be a C-Module which is regularly masked using
-    # another Python module in front of it.
-    if (real_mod in sys.modules and
-            hasattr(sys.modules[real_mod], '__file__')):
-        real_file = sys.modules[real_mod].__file__
-        extension = os.path.splitext(real_file)[1]
-        if not extension.startswith('.py'):
-            return True
-    if real_mod.startswith('_') and real_mod == import_mod.split('.')[-1]:
-        # Looks like a C-module which doesn't declare its
-        # package path correctly.
-        return True
-
-
-def rule_zope_deferredimport(import_mod, name, real_mod):
-    if real_mod == 'zope.deferredimport.deferredmodule':
-        return True
-
-
-def rule_internal_underscore_reimport(import_mod, name, real_mod):
-    # Looks like an internal module, prefixed with _ was exported to the same
-    # module name without an _
-    return real_mod.split('.')[-1] == '_' + import_mod.split('.')[-1]
-
-
-
-RULES = [func for name, func in locals().items()
-         if name.startswith('rule_')]
-
-
-class IndirectAttributeAccessChecker(types.ModuleType):
-
-    def __init__(self, module, options):
-        self.__import_checker_module = module
-        self.__import_checker_options = options
-
-    def __eq__(self, other):
-        if isinstance(other, IndirectAttributeAccessChecker):
-            other = (
-                other._IndirectAttributeAccessChecker__import_checker_module)
-        return other == self._IndirectAttributeAccessChecker__import_checker_module
-
-    def __setattr__(self, name, value):
-        if name.startswith('_IndirectAttributeAccessChecker__import_checker_'):
-            object.__setattr__(self, name.replace('_IndirectAttributeAccessChecker', ''), value)
-        else:
-            module = self.__import_checker_module
-            setattr(module, name, value)
-
-    def __getattribute__(self, name):
-        if name.startswith('_IndirectAttributeAccessChecker__import_checker_'):
-            return object.__getattribute__(self, name.replace('_IndirectAttributeAccessChecker', ''))
-        module = self.__import_checker_module
-        attr = getattr(module, name)
-        if not isinstance(attr,
-                (types.ClassType, types.TypeType, types.FunctionType)):
-            return attr
-        if attr.__module__ == module.__name__:
-            return attr
-
-        frame = sys._getframe(1)
-        show_only_from = self.__import_checker_options.indirect_source
-        if show_only_from:
-            for include in show_only_from:
-                if guess_package_name(frame).startswith(include):
-                    break
-            else:
-                # This warning was caused in a module not under the
-                # `indirect source` parameter.
-                return attr
-
-        import_mod, real_mod = module.__name__, attr.__module__
-        for rule in RULES:
-            # Warning suppression rules: if no rule matches, we display
-            # a warning.
-            if rule(import_mod, name, real_mod):
-                break
-        else:
-            attr_type = type(attr).__name__
-            file = frame.f_code.co_filename
-            line = frame.f_lineno
-            signature = (import_mod, name, real_mod, file, line)
-            if signature not in seen:
-                print ("WARNING: indirect import of %s `%s.%s` (originally defined at `%s`)"
-                        % (attr_type, import_mod, name, real_mod))
-                print "caused at %s:%s" % (file, line)
-                seen.add(signature)
-
-        return attr
-
-
-class IndirectImportWarner(ihooks.ModuleImporter):
-
-    def __init__(self, options):
-        ihooks.ModuleImporter.__init__(self)
-        self.options = options
-
-    def import_module(self, name, globals=None, locals=None,
-            fromlist=None):
-        result = ihooks.ModuleImporter.import_module(
-            self, name, globals=globals, locals=locals, fromlist=fromlist)
-        if id(result) not in wrapper_cache:
-            checker = IndirectAttributeAccessChecker(
-                result, self.options)
-            if not hasattr(result, '__all__'):
-                # Support * imports
-                checker.__all__ = [x for x in dir(result) if not
-                        x.startswith('_')]
-            wrapper_cache[id(result)] = checker
-        return wrapper_cache[id(result)]
-
-    def import_it(self, partname, fqname, parent, force_load=0):
-        result = ihooks.ModuleImporter.import_it(self, partname, fqname,
-                parent, force_load)
-        if result is not None:
-            if hasattr(result, '__file__') and not '.' in os.path.basename(result.__file__):
-                # Smells like a package which didn't get __init__.py
-                # attached to its path.
-                result.__file__ = os.path.join(result.__file__, '__init__.py')
-        return result
-
-    def determine_parent(self, globals):
-        if not globals or not "__name__" in globals:
-            return None
-        pname = globals['__name__']
-        if "__path__" in globals:
-            parent = self.modules[pname]
-            # XXX The original class used to use an `assert` here which
-            # conflicts with doctest creating copys of the globs.
-            # assert globals is parent.__dict__
-            return parent
-        if '.' in pname:
-            i = pname.rfind('.')
-            pname = pname[:i]
-            parent = self.modules[pname]
-            assert parent.__name__ == pname
-            return parent
-        return None
-
-
-class ImportChecker(zope.testing.testrunner.feature.Feature):
-    """Monitor indirect imports and warn about them."""
-
-    active = True
-
-    def global_setup(self):
-        if self.runner.options.indirect_imports:
-            ihooks.install(IndirectImportWarner(self.runner.options))
-
-    def global_teardown(self):
-        if self.runner.options.indirect_imports:
-            ihooks.uninstall()

Deleted: zope.testing/trunk/src/zope/testing/testrunner/importcheck.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/importcheck.txt	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/testrunner/importcheck.txt	2009-02-16 19:29:33 UTC (rev 96602)
@@ -1,107 +0,0 @@
-=============
-Import checks
-=============
-
-Import checks are intended to help finding imports of classes and
-functions that have been moved and are still referred to by their old
-location. We usually re-import them at their old location to keep code
-working, but for cleaning up, it's nice to get a heads-up where we still
-refer to the old locations.
-
-Note: Only objects that support `__module__` can be checked for indirect
-reports. This is especially *not* true for instances.
-
-Test-runner integration
-=======================
-
-This test (as it is a test for the test runner) assumes that the test
-runner has the import check enabled. We extend Python's search path to
-include some example modules that trigger the import checker:
-
->>> import sys, os.path
->>> import zope.testing.testrunner
->>> sys.path.insert(0, os.path.join(os.path.dirname(
-...     zope.testing.testrunner.__file__), 'importchecker-fixtures'))
-
-When importing a function or a class from a module that isn't its
-original place of definition, a warning will be printed:
-
->>> import impcheck0
->>> import impcheck0a
->>> import impcheck0b
-WARNING: indirect import of type `impcheck0a.X` (originally defined at `impcheck0`)
-caused at ...impcheck0b.py:NNN
-WARNING: indirect import of function `impcheck0a.y` (originally defined at `impcheck0`)
-caused at ...impcheck0b.py:NNN
-
-
-Heuristics for ignoring re-imports
-==================================
-
-Indirect imports in the standard library
-----------------------------------------
-
-The standard library uses reimports to hide some lower level modules which is
-ok for us.
-
-The types in the `type` module come originally from `__builtin__`. This is ok
-for us and we ignore that:
-
->>> from types import NoneType
->>> NoneType.__module__
-'__builtin__'
-
-The `os` module tends to reimport from locations like `posix`:
-
->>> from os import unlink
->>> unlink.__module__
-'posix'
-
-The `re` module imports its content from the `sre` module:
-
->>> from re import match
-
-
-Indirect imports due to the testing environment
------------------------------------------------
-
-The test runner and `doctest` redirect the stdout temporarily, so sys.stdout
-can be ignored as well:
-
->>> from sys import stdout
->>> stdout.__module__
-'zope.testing.doctest'
-
-
-Indirect imports from packages and their sub-modules
-----------------------------------------------------
-
-We allow indirect imports for the sake of providing an API within a package
-that hides its (sub-)modules. E.g. the following structure is ok, as X is
-defined in module `impcheck1.sub1` and re-imported from `impcheck1`:
-
->>> from impcheck1 import X
->>> from impcheck1.sub1 import X
-
-
-However, we do not allow re-imports from sibling modules:
-
->>> from impcheck1.sub2 import X
-WARNING: indirect import of type `impcheck1.sub2.X` (originally defined at `impcheck1.sub1`)
-caused at <doctest importcheck.txt[15]>:1
-
-
-Also, we only allow one level of re-importing via modules:
-
->>> from impcheck1 import Y
-WARNING: indirect import of type `impcheck1.Y` (originally defined at `impcheck1.sub3.sub3a`)
-caused at <doctest importcheck.txt[16]>:1
-
-
-Indirect imports from C-modules
--------------------------------
-
-Often there are indirect imports from modules that are written in C to provide
-a nicer API for it. We ignore symbols that are re-imported from C:
-
->>> from curses import setupterm

Modified: zope.testing/trunk/src/zope/testing/testrunner/options.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/options.py	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/testrunner/options.py	2009-02-16 19:29:33 UTC (rev 96602)
@@ -314,20 +314,6 @@
 Run the tests under pychecker
 """)
 
-analysis.add_option(
-    '--indirect-imports', '-i', action="store_true", dest='indirect_imports',
-    help="""\
-Inject an import hook and report usage of indirectly imported classes
-and functions.
-""")
-
-analysis.add_option(
-    '--indirect-source', action="append", dest='indirect_source',
-    help="""\
-Only report indirect imports that originated in the given package or
-module (or one of its sub-packages or sub-modules).
-""")
-
 parser.add_option_group(analysis)
 
 ######################################################################
@@ -531,7 +517,6 @@
         args = sys.argv
 
     options, positional = parser.parse_args(args[1:], defaults)
-
     options.original_testrunner_args = args
 
     if options.color:

Modified: zope.testing/trunk/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/runner.py	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/testrunner/runner.py	2009-02-16 19:29:33 UTC (rev 96602)
@@ -46,9 +46,7 @@
 import zope.testing.testrunner.subprocess
 import zope.testing.testrunner.interfaces
 import zope.testing.testrunner.debug
-import zope.testing.testrunner.importcheck
 
-
 PYREFCOUNT_PATTERN = re.compile('\[[0-9]+ refs\]')
 
 is_jython = sys.platform.startswith('java')
@@ -193,7 +191,6 @@
         self.features.append(zope.testing.testrunner.filter.Filter(self))
         self.features.append(zope.testing.testrunner.listing.Listing(self))
         self.features.append(zope.testing.testrunner.statistics.Statistics(self))
-        self.features.append(zope.testing.testrunner.importcheck.ImportChecker(self))
 
         # Remove all features that aren't activated
         self.features = [f for f in self.features if f.active]

Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-debugging-layer-setup.test
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-debugging-layer-setup.test	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-debugging-layer-setup.test	2009-02-16 19:29:33 UTC (rev 96602)
@@ -101,6 +101,7 @@
     ...     zope.testing.testrunner.run(
     ...       ['--path', dir, '-Dvv', '--tests-pattern', 'tests2'])
     ... finally: sys.stdin = real_stdin
+    ... # doctest: +ELLIPSIS +REPORT_NDIFF
     Running tests at level 1
     Running tests2.Layer1 tests:
       Set up tests2.Layer1 in 0.000 seconds.

Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-edge-cases.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-edge-cases.txt	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-edge-cases.txt	2009-02-16 19:29:33 UTC (rev 96602)
@@ -28,8 +28,6 @@
     <BLANKLINE>
     Module: sampletestsf
     <BLANKLINE>
-    Traceback (most recent call last):
-    ...
     ImportError: No module named sampletestsf
     ...
 

Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-errors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-errors.txt	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-errors.txt	2009-02-16 19:29:33 UTC (rev 96602)
@@ -703,12 +703,11 @@
     >>> sys.argv = ('test --tests-pattern ^sampletests(f|_i)?$ --layer 1 '
     ...            ).split()
     >>> testrunner.run(defaults)
-    ... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
+    ... # doctest: +NORMALIZE_WHITESPACE
     Test-module import failures:
     <BLANKLINE>
     Module: sample2.sampletests_i
     <BLANKLINE>
-    ...
       File "testrunner-ex/sample2/sampletests_i.py", line 1
         importx unittest
                        ^
@@ -718,11 +717,9 @@
     Module: sample2.sample21.sampletests_i
     <BLANKLINE>
     Traceback (most recent call last):
-      ...
       File "testrunner-ex/sample2/sample21/sampletests_i.py", line 15, in ?
         import zope.testing.huh
-      ...
-    ImportError: No module named zope.testing.huh
+    ImportError: No module named huh
     <BLANKLINE>
     <BLANKLINE>
     Module: sample2.sample22.sampletests_i
@@ -733,7 +730,6 @@
     Module: sample2.sample23.sampletests_i
     <BLANKLINE>
     Traceback (most recent call last):
-      ...
       File "testrunner-ex/sample2/sample23/sampletests_i.py", line 18, in ?
         class Test(unittest.TestCase):
       File "testrunner-ex/sample2/sample23/sampletests_i.py", line 23, in Test

Modified: zope.testing/trunk/src/zope/testing/testrunner/tests.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/tests.py	2009-02-16 19:24:28 UTC (rev 96601)
+++ zope.testing/trunk/src/zope/testing/testrunner/tests.py	2009-02-16 19:29:33 UTC (rev 96602)
@@ -104,7 +104,6 @@
         'testrunner-repeat.txt',
         'testrunner-gc.txt',
         'testrunner-knit.txt',
-        'importcheck.txt',
         setUp=setUp, tearDown=tearDown,
         optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
         checker=checker),



More information about the Zope3-Checkins mailing list