[Checkins] SVN: zope.component/tseaver-test_cleanup/ Avoid doctest in the subprocess: exit with an error if adaptation fails.

Tres Seaver cvs-admin at zope.org
Wed Jun 20 05:20:20 UTC 2012


Log message for revision 126979:
  Avoid doctest in the subprocess:  exit with an error if adaptation fails.
  
  Note that the circular import added to make the 'standalonetests' script
  pass is no longer required.

Changed:
  _U  zope.component/tseaver-test_cleanup/
  U   zope.component/tseaver-test_cleanup/src/zope/component/globalregistry.py
  U   zope.component/tseaver-test_cleanup/src/zope/component/standalonetests.py
  U   zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py
  U   zope.component/tseaver-test_cleanup/tox.ini

-=-
Modified: zope.component/tseaver-test_cleanup/src/zope/component/globalregistry.py
===================================================================
--- zope.component/tseaver-test_cleanup/src/zope/component/globalregistry.py	2012-06-20 05:20:12 UTC (rev 126978)
+++ zope.component/tseaver-test_cleanup/src/zope/component/globalregistry.py	2012-06-20 05:20:17 UTC (rev 126979)
@@ -75,12 +75,3 @@
 
 def provideHandler(factory, adapts=None):
     base.registerHandler(factory, adapts, event=False)
-
-import zope.component._api # see https://bugs.launchpad.net/zope3/+bug/98401
-# Ideally, we will switch to an explicit adapter hook registration.  For now,
-# if you provide an adapter, we want to make sure that the adapter hook is
-# registered, and that registration depends on code in _api, which itself
-# depends on code in this module.  So, for now, we do another of these nasty
-# circular import workarounds.  See also standalonetests.py, as run by
-# tests.py in StandaloneTests, for a test that fails without this hack, and
-# succeeds with it.

Modified: zope.component/tseaver-test_cleanup/src/zope/component/standalonetests.py
===================================================================
--- zope.component/tseaver-test_cleanup/src/zope/component/standalonetests.py	2012-06-20 05:20:12 UTC (rev 126978)
+++ zope.component/tseaver-test_cleanup/src/zope/component/standalonetests.py	2012-06-20 05:20:17 UTC (rev 126979)
@@ -9,46 +9,39 @@
 if __name__ == "__main__":
     sys.path = pickle.loads(sys.stdin.read())
 
-from zope import interface
-from zope.component.testing import setUp, tearDown
+    from zope.interface import Interface
+    from zope.interface import implementer
 
-class I1(interface.Interface):
-    pass
+    with open('/tmp/foo.txt', 'w') as f:
+        print >>f, sys.executable
+        print >>f, '-' * 80
+        for p in sys.path:
+            print >>f, p
+        print >>f, '-' * 80
+        import zope
+        for p in zope.__path__:
+            print >>f, p
 
-class I2(interface.Interface):
-    pass
+    class I1(Interface):
+        pass
 
-class Ob(object):
-    interface.implements(I1)
-    def __repr__(self):
-        return '<instance Ob>'
+    class I2(Interface):
+        pass
 
-ob = Ob()
+    @implementer(I1)
+    class Ob(object):
+        def __repr__(self):
+            return '<instance Ob>'
 
-class Comp(object):
-    interface.implements(I2)
-    def __init__(self, context):
-        self.context = context
+    ob = Ob()
 
-def providing_adapter_sets_adapter_hook():
-    """
-    A side effect of importing installs the adapter hook.  See
-    https://bugs.launchpad.net/zope3/+bug/98401
+    @implementer(I2)
+    class Comp(object):
+        def __init__(self, context):
+            self.context = context
 
-      >>> import zope.component
-      >>> zope.component.provideAdapter(Comp, (I1,), I2)
-      >>> adapter = I2(ob)
-      >>> adapter.__class__ is Comp
-      True
-      >>> adapter.context is ob
-      True
-    """
-
-
-def test_suite():
-    return unittest.TestSuite((
-        doctest.DocTestSuite(setUp=setUp, tearDown=tearDown),
-        ))
-
-if __name__ == "__main__":
-    unittest.main(defaultTest='test_suite')
+    import zope.component
+    zope.component.provideAdapter(Comp, (I1,), I2)
+    adapter = I2(ob)
+    assert adapter.__class__ is Comp
+    assert adapter.context is ob

Modified: zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py
===================================================================
--- zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py	2012-06-20 05:20:12 UTC (rev 126978)
+++ zope.component/tseaver-test_cleanup/src/zope/component/tests/test_doctests.py	2012-06-20 05:20:17 UTC (rev 126979)
@@ -145,7 +145,8 @@
         import pickle
 
         executable = os.path.abspath(sys.executable)
-        program = os.path.join(os.path.dirname(__file__), 'standalonetests.py')
+        where = os.path.dirname(os.path.dirname(__file__))
+        program = os.path.join(where, 'standalonetests.py')
         process = subprocess.Popen([executable, program],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT,
@@ -154,28 +155,11 @@
         process.stdin.close()
 
         try:
-            process.wait()
+            rc = process.wait()
         except OSError, e:
             if e.errno != 4: # MacIntel raises apparently unimportant EINTR?
                 raise # TODO verify sanity of a pass on EINTR :-/
-        lines = process.stdout.readlines()
-        process.stdout.close()
-        success = True
-        # Interpret the result: We scan the output from the end backwards
-        # until we find either a line that says 'OK' (which means the tests
-        # ran successfully) or a line that starts with quite a few dashes
-        # (which means we didn't find a line that says 'OK' within the summary
-        # of the test runner and the tests did not run successfully.)
-        for l in reversed(lines):
-            l = l.strip()
-            if not l:
-                continue
-            if l.startswith('-----'):
-                break
-            if l.endswith('OK'):
-                sucess = True
-        if not success:
-            self.fail(''.join(lines))
+        self.assertEqual(rc, 0)
 
 template = """<configure
    xmlns='http://namespaces.zope.org/zope'

Modified: zope.component/tseaver-test_cleanup/tox.ini
===================================================================
--- zope.component/tseaver-test_cleanup/tox.ini	2012-06-20 05:20:12 UTC (rev 126978)
+++ zope.component/tseaver-test_cleanup/tox.ini	2012-06-20 05:20:17 UTC (rev 126979)
@@ -33,6 +33,9 @@
 #   version, before running nosetests.
     pip uninstall -y zope.component
     pip install -e .
+#   Now, further unfsck pip's setup by making sure that 'zope' is a proper
+#   namespace package.
+    python -c "import shutil; import zope; shutil.copy('{toxinidir}/src/zope/__init__.py', zope.__path__[0])"
     nosetests --with-xunit --with-xcoverage
 deps =
     zope.component



More information about the checkins mailing list