Author: SmileyChris
Date: 2011-08-27 19:37:16 -0700 (Sat, 27 Aug 2011)
New Revision: 16703

Added:
   django/trunk/tests/regressiontests/utils/test_no_submodule.py
Modified:
   django/trunk/django/utils/module_loading.py
   django/trunk/tests/regressiontests/utils/module_loading.py
Log:
Fixed #15525 -- Custom template tags loading breaks whenever templatetags is a 
python file

Modified: django/trunk/django/utils/module_loading.py
===================================================================
--- django/trunk/django/utils/module_loading.py 2011-08-28 02:05:32 UTC (rev 
16702)
+++ django/trunk/django/utils/module_loading.py 2011-08-28 02:37:16 UTC (rev 
16703)
@@ -11,10 +11,16 @@
         return sys.modules[name] is not None
     except KeyError:
         pass
+    try:
+        package_path = package.__path__   # No __path__, then not a package.
+    except AttributeError:
+        # Since the remainder of this function assumes that we're dealing with
+        # a package (module with a __path__), so if it's not, then bail here.
+        return False
     for finder in sys.meta_path:
-        if finder.find_module(name, package.__path__):
+        if finder.find_module(name, package_path):
             return True
-    for entry in package.__path__:  # No __path__, then not a package.
+    for entry in package_path:
         try:
             # Try the cached finder.
             finder = sys.path_importer_cache[entry]

Modified: django/trunk/tests/regressiontests/utils/module_loading.py
===================================================================
--- django/trunk/tests/regressiontests/utils/module_loading.py  2011-08-28 
02:05:32 UTC (rev 16702)
+++ django/trunk/tests/regressiontests/utils/module_loading.py  2011-08-28 
02:37:16 UTC (rev 16703)
@@ -18,6 +18,8 @@
     def test_loader(self):
         "Normal module existence can be tested"
         test_module = import_module('regressiontests.utils.test_module')
+        test_no_submodule = import_module(
+            'regressiontests.utils.test_no_submodule')
 
         # An importable child
         self.assertTrue(module_has_submodule(test_module, 'good_module'))
@@ -40,6 +42,11 @@
         import types  # causes attempted import of regressiontests.utils.types
         
self.assertFalse(module_has_submodule(sys.modules['regressiontests.utils'], 
'types'))
 
+        # A module which doesn't have a __path__ (so no submodules)
+        self.assertFalse(module_has_submodule(test_no_submodule, 'anything'))
+        self.assertRaises(ImportError, import_module,
+            'regressiontests.utils.test_no_submodule.anything')
+
 class EggLoader(unittest.TestCase):
     def setUp(self):
         self.old_path = sys.path[:]

Added: django/trunk/tests/regressiontests/utils/test_no_submodule.py
===================================================================
--- django/trunk/tests/regressiontests/utils/test_no_submodule.py               
                (rev 0)
+++ django/trunk/tests/regressiontests/utils/test_no_submodule.py       
2011-08-28 02:37:16 UTC (rev 16703)
@@ -0,0 +1 @@
+# Used to test for modules which don't have submodules.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to