Author: kkubasik
Date: 2009-07-22 08:17:49 -0500 (Wed, 22 Jul 2009)
New Revision: 11296

Added:
   django/branches/soc2009/test-improvements/django/test/rollback_importer.py
Modified:
   django/branches/soc2009/test-improvements/
Log:
[gsoc2009-testing] Adding my global importer which can force a reload of all 
modules. (so coverage can account for startup as well)



Property changes on: django/branches/soc2009/test-improvements
___________________________________________________________________
Name: svk:merge
   - 23ef3597-c209-482b-90c0-ea6045f15f7f:/local/django-gsoc:11124
23ef3597-c209-482b-90c0-ea6045f15f7f:/local/django/trunk:10927
bcc190cf-cafb-0310-a4f2-bffc1f526a37:/django/trunk:11285
   + 23ef3597-c209-482b-90c0-ea6045f15f7f:/local/django-gsoc:11125
23ef3597-c209-482b-90c0-ea6045f15f7f:/local/django/trunk:10927
bcc190cf-cafb-0310-a4f2-bffc1f526a37:/django/trunk:11285

Added: 
django/branches/soc2009/test-improvements/django/test/rollback_importer.py
===================================================================
--- django/branches/soc2009/test-improvements/django/test/rollback_importer.py  
                        (rev 0)
+++ django/branches/soc2009/test-improvements/django/test/rollback_importer.py  
2009-07-22 13:17:49 UTC (rev 11296)
@@ -0,0 +1,19 @@
+class RollbackImporter:
+    def __init__(self):
+        "Creates an instance and installs as the global importer"
+        self.previousModules = sys.modules.copy()
+        self.realImport = __builtin__.__import__
+        __builtin__.__import__ = self._import
+        self.newModules = {}
+
+    def _import(self, name, globals=None, locals=None, fromlist=[]):
+        result = apply(self.realImport, (name, globals, locals, fromlist))
+        self.newModules[name] = 1
+        return result
+        
+    def uninstall(self):
+        for modname in self.newModules.keys():
+            if not self.previousModules.has_key(modname):
+                # Force reload when modname next imported
+                del(sys.modules[modname])
+        __builtin__.__import__ = self.realImport


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

Reply via email to