[Checkins] SVN: z3c.autoinclude/trunk/src/z3c/autoinclude/ various code cleanup

Ethan Jucovy ejucovy at openplans.org
Sat Dec 6 19:41:51 EST 2008


Log message for revision 93739:
  various code cleanup

Changed:
  U   z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.txt
  U   z3c.autoinclude/trunk/src/z3c/autoinclude/plugin.txt
  U   z3c.autoinclude/trunk/src/z3c/autoinclude/tests/SiblingPackage/setup.py
  U   z3c.autoinclude/trunk/src/z3c/autoinclude/tests/tests.py
  U   z3c.autoinclude/trunk/src/z3c/autoinclude/utils.txt

-=-
Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.txt
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.txt	2008-12-07 00:32:09 UTC (rev 93738)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.txt	2008-12-07 00:41:51 UTC (rev 93739)
@@ -14,6 +14,10 @@
 Given the distribution for the project named ``APackage``, we can ask
 for the requirements of that distribution::
 
+    >>> import a
+    >>> from z3c.autoinclude.utils import distributionForPackage
+    >>> a_dist = distributionForPackage(a)
+
     >>> reqs = a_dist.requires()
     >>> pprint(sorted(reqs, key=lambda r:r.project_name))
     [Requirement.parse('BCPackage'),
@@ -30,7 +34,13 @@
     >>> from z3c.autoinclude.dependency import DependencyFinder
     >>> a_include_finder = DependencyFinder(a_dist)
     >>> b_include_finder = DependencyFinder(b_dist)
+    
+    >>> import x.y.z
+    >>> xyz_dist = distributionForPackage(x.y.z)
     >>> xyz_include_finder = DependencyFinder(xyz_dist)
+
+    >>> import F.G
+    >>> sibling_dist = distributionForPackage(F.G)
     >>> sibling_include_finder = DependencyFinder(sibling_dist)
 
 The include finder provides functionality to determine what namespace
@@ -143,10 +153,3 @@
      Traceback (most recent call last):
      ...
      DistributionNotFound: NonexistentPackage
-
-Now let's just clean up our test log in preparation for the next test::
-
-    >>> from testdirective.zcml import clear_test_log
-    >>> clear_test_log()
-    >>> pprint(test_log)
-    []

Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/plugin.txt
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/plugin.txt	2008-12-07 00:32:09 UTC (rev 93738)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/plugin.txt	2008-12-07 00:41:51 UTC (rev 93739)
@@ -35,6 +35,9 @@
 Finally, we know how to get a list of all module dottednames within
 a distribution, through the DistributionManager adapter::
 
+    >>> import foo
+    >>> from z3c.autoinclude.utils import distributionForPackage
+    >>> foo_dist = distributionForPackage(foo)
     >>> from z3c.autoinclude.utils import DistributionManager
     >>> DistributionManager(foo_dist).dottedNames()
     ['foo']

Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/tests/SiblingPackage/setup.py
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/tests/SiblingPackage/setup.py	2008-12-07 00:32:09 UTC (rev 93738)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/tests/SiblingPackage/setup.py	2008-12-07 00:41:51 UTC (rev 93739)
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = '0.1'
+version = '0.0'
 
 setup(name='SiblingPackage',
       version=version,

Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/tests/tests.py
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/tests/tests.py	2008-12-07 00:32:09 UTC (rev 93738)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/tests/tests.py	2008-12-07 00:41:51 UTC (rev 93739)
@@ -1,11 +1,7 @@
-import doctest
-import unittest
+from zc.buildout import testing
 
 import os
-from zc.buildout import testing
-from pprint import pprint
 projects_dir = os.path.dirname(__file__)
-from pkg_resources import working_set
 
 
 # this is the list of test packages that we'll temporarily install
@@ -16,9 +12,9 @@
                  'base2', 'base2_plug', 'TestDirective']
 
 
+from zc.buildout.easy_install import install
+from pkg_resources import working_set
 def install_projects(projects, target_dir):
-    from zc.buildout.easy_install import install
-
     links = []
     for project in projects:
         project_dir = os.path.join(projects_dir, project)
@@ -29,44 +25,49 @@
                 os.path.join('bin', 'buildout'), project_dir))
         links.append(dist_dir)
 
-    return install(projects, target_dir, links=links,
-                   working_set=working_set)
+    new_working_set = install(projects, target_dir, links=links,
+                              working_set=working_set)
 
+    # we must perform a magical incantation on each distribution
+    for dist in new_working_set:
+        dist.activate()
+    return new_working_set
 
 def testSetUp(test):
+    """
+    install test packages so that they can be imported
+    and their egg info examined in test runs
+    """
+    
+    testing.buildoutSetUp(test)
 
-    testing.buildoutSetUp(test)
-        
     import tempfile
-    target_dir = tempfile.mkdtemp('.z3c.autoinclude.test-installs')
-    
-    ws = install_projects(test_packages, target_dir)
+    target_dir = tempfile.mkdtemp('.z3c.autoinclude.test-installs')    
+    install_projects(test_packages, target_dir)
 
-    # we must perform a magical incantation on each distribution
-    for dist in ws:
-        dist.activate()
-        
-        if dist.project_name == 'APackage':
-            test.globs['a_dist'] = dist
-        elif dist.project_name == 'XYZPackage':
-            test.globs['xyz_dist'] = dist
-        elif dist.project_name == 'SiblingPackage':
-            test.globs['sibling_dist'] = dist
-        elif dist.project_name == 'FooPackage':
-            test.globs['foo_dist'] = dist
-        elif dist.project_name == 'BasePackage':
-            test.globs['base_dist'] = dist
 
+def testTearDown(test):
+    from testdirective.zcml import clear_test_log
+    clear_test_log()
 
+    testing.buildoutTearDown(test)
+
+
+import doctest
+import unittest
+    
 def test_suite():
-    suite = doctest.DocFileSuite('../utils.txt', '../dependency.txt', '../plugin.txt',
+
+    from pprint import pprint
+    suite = doctest.DocFileSuite('../utils.txt',
+                                 '../dependency.txt',
+                                 '../plugin.txt',
                                  setUp=testSetUp,
-                                 tearDown=testing.buildoutTearDown,
+                                 tearDown=testTearDown,
                                  globs={'pprint':pprint},
                                  optionflags=doctest.ELLIPSIS)
 
-    return unittest.TestSuite((suite,
-                               ))
+    return unittest.TestSuite((suite,))
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')

Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/utils.txt
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/utils.txt	2008-12-07 00:32:09 UTC (rev 93738)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/utils.txt	2008-12-07 00:41:51 UTC (rev 93739)
@@ -33,3 +33,7 @@
     >>> import foo
     >>> distributionForPackage(foo)
     FooPackage 0.0 (...FooPackage-0.0...egg)
+
+    >>> import F.G
+    >>> distributionForPackage(F.G)
+    SiblingPackage 0.0 (...SiblingPackage-0.0...egg)



More information about the Checkins mailing list