[Checkins] SVN: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/ Make package resolution work.

Uli Fouquet uli at gnufix.de
Sat Feb 2 08:08:45 EST 2008


Log message for revision 83419:
  Make package resolution work.

Changed:
  U   Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py
  A   Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/utils.py
  U   Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/util.py

-=-
Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py	2008-02-02 13:07:41 UTC (rev 83418)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py	2008-02-02 13:08:45 UTC (rev 83419)
@@ -6,7 +6,8 @@
 from zope.testing import doctest, cleanup, renormalizing
 import zope.component.eventtesting
 
-TESTFILES = ['basicsetup.py', 'functionalsetup.py', 'unittestsetup.py']
+TESTFILES = ['basicsetup.py', 'functionalsetup.py', 'unittestsetup.py',
+             'utils.py']
 
 def setUpZope(test):
     zope.component.eventtesting.setUp(test)

Added: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/utils.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/utils.py	                        (rev 0)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/utils.py	2008-02-02 13:08:45 UTC (rev 83419)
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+===========================
+Utilities for z3c.testsetup
+===========================
+
+The `util` module defines some helper functions of general use.
+
+For most classes in this package, that accept packages as arguments,
+these packages can be delivered as real packages or as strings
+containing dotted names. To get a package of something, that is either
+a string with dotted names or a real package, the `get_package`
+function is provided.
+
+Such we can get a package from a dotted name string::
+
+   >>> from z3c.testsetup.util import get_package
+   >>> get_package('z3c.testsetup.tests.cave')
+   <module 'z3c.testsetup.tests.cave' from '...'>
+
+The dotted name string can be unicode::
+
+   >>> get_package(u'z3c.testsetup.tests.cave')
+   <module 'z3c.testsetup.tests.cave' from '...'>
+
+We can indeed pass a package as argument::
+
+   >>> from z3c.testsetup.tests import cave
+   >>> get_package(cave)
+   <module 'z3c.testsetup.tests.cave' from '...'>
+
+
+"""

Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/util.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/util.py	2008-02-02 13:07:41 UTC (rev 83418)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/util.py	2008-02-02 13:08:45 UTC (rev 83419)
@@ -13,9 +13,19 @@
 ##############################################################################
 """Helper functions for testsetup.
 """
+from martian.scan import module_info_from_dotted_name
 
 def get_package(pkg_or_dotted_name):
-    """XXX function does nothing currently.
+    """Get a package denoted by the given argument.
+
+    If the given argument is a string, we try to load the module
+    denoting that module and return it.
+
+    Otherwise, the argument is believed to be a package and is
+    returned as-is.
     """
-    return pkg_or_dotted_name
-
+    pkg = pkg_or_dotted_name
+    if isinstance(pkg, basestring):
+        info = module_info_from_dotted_name(pkg)
+        pkg = info.getModule()
+    return pkg



More information about the Checkins mailing list