[Twisted-Python] pyunit upgrade

Kevin Turner acapnotic at twistedmatrix.com
Thu Oct 18 06:27:20 EDT 2001


Ok, I upgraded the pyunit in Twisted from the July 2000 version to the
current one (which is also in the standard library these days).  Before
I did so, I checked to see what changes were made from the upstream
source.

Here are the only changes which were not cosmetic.  For your
browsing pleasure, most of this diff doesn't have changes, but it
provides context for people (who need a bit more than 'patch' does).

To further enchance your experience today, we include a special web
bonus.  The upstream source:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pyunit/pyunit/unittestgui.py

Our source:
http://twistedmatrix.com/users/carmstro.twistd/static/viewcvs/cgi/viewcvs.cgi/pyunit/unittestgui.py

--- pyunit-1.2.0/unittestgui.py	Thu Oct 18 02:36:45 2001
+++ Twisted/unittestgui.py	Thu Oct 18 02:36:48 2001
@@ -44,12 +44,12 @@
 class BaseGUITestRunner:
     """Subclass this class to create a GUI TestRunner that uses a specific
     windowing toolkit. The class takes care of running tests in the correct
     manner, and making callbacks to the derived class to obtain information
     or signal that events have occurred.
     """
     def __init__(self, *args, **kwargs):
         self.currentResult = None
         self.running = 0
         self.__rollbackImporter = None
         apply(self.initGUI, args, kwargs)
 
@@ -64,12 +64,12 @@
     def runClicked(self):
         "To be called in response to user choosing to run a test"
         if self.running: return
         testName = self.getSelectedTestName()
         if not testName:
             self.errorDialog("Test name entry", "You must enter a test name")
             return
         if self.__rollbackImporter:
             self.__rollbackImporter.uninstall()
         self.__rollbackImporter = RollbackImporter()
         try:
             test = unittest.createTestInstance(testName)
@@ -148,28 +149,29 @@
 class RollbackImporter:
     """This tricky little class is used to make sure that modules under test
     will be reloaded the next time they are imported. It provides a temporary
     wrapper around __import__ which notes imported modules and unloads them.
 
     Alternative mechanisms using the 'imp' and 'ihooks' standard modules were
     considered but were found to be unworkable. Additionally, use of those
     modules can disturb PythonWin.
     """
     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 = {}
+        # __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():
+        currentModules = sys.modules.copy()
+        for modname in currentModules.keys():
             if not self.previousModules.has_key(modname):
                 # Force reload when modname next imported
                 del(sys.modules[modname])
-        __builtin__.__import__ = self.realImport
+        # __builtin__.__import__ = self.realImport
 

-- 
Kevin Turner <acapnotic at twistedmatrix.com> | OpenPGP encryption welcome here
The moon is waxing crescent, 2.4% illuminated, 1.5 days old.





More information about the Twisted-Python mailing list