[Python-checkins] r62381 - in python/trunk/Lib/test: regrtest.py test_frozen.py test_pkg.py test_pkgutil.py test_profile.py test_structmembers.py test_warnings.py

amaury.forgeotdarc python-checkins at python.org
Sat Apr 19 01:31:34 CEST 2008


Author: amaury.forgeotdarc
Date: Sat Apr 19 01:31:33 2008
New Revision: 62381

Log:
Some tests did not pass on repeated calls (regrtest -R::)
Perform additional cleanup, mostly deleting from sys.modules, or clearing the warnings registry.


Modified:
   python/trunk/Lib/test/regrtest.py
   python/trunk/Lib/test/test_frozen.py
   python/trunk/Lib/test/test_pkg.py
   python/trunk/Lib/test/test_pkgutil.py
   python/trunk/Lib/test/test_profile.py
   python/trunk/Lib/test/test_structmembers.py
   python/trunk/Lib/test/test_warnings.py

Modified: python/trunk/Lib/test/regrtest.py
==============================================================================
--- python/trunk/Lib/test/regrtest.py	(original)
+++ python/trunk/Lib/test/regrtest.py	Sat Apr 19 01:31:33 2008
@@ -683,6 +683,11 @@
     import struct, filecmp
     from distutils.dir_util import _path_created
 
+    # Clear the warnings registry, so they can be displayed again
+    for mod in sys.modules.values():
+        if hasattr(mod, '__warningregistry__'):
+            del mod.__warningregistry__
+
     # Restore some original values.
     warnings.filters[:] = fs
     copy_reg.dispatch_table.clear()

Modified: python/trunk/Lib/test/test_frozen.py
==============================================================================
--- python/trunk/Lib/test/test_frozen.py	(original)
+++ python/trunk/Lib/test/test_frozen.py	Sat Apr 19 01:31:33 2008
@@ -35,6 +35,10 @@
         self.assertEquals(stdout.getvalue(),
                           'Hello world...\nHello world...\nHello world...\n')
 
+        del sys.modules['__hello__']
+        del sys.modules['__phello__']
+        del sys.modules['__phello__.spam']
+
 
 def test_main():
     run_unittest(FrozenTests)

Modified: python/trunk/Lib/test/test_pkg.py
==============================================================================
--- python/trunk/Lib/test/test_pkg.py	(original)
+++ python/trunk/Lib/test/test_pkg.py	Sat Apr 19 01:31:33 2008
@@ -46,12 +46,20 @@
 
     def setUp(self):
         self.root = None
+        self.pkgname = None
         self.syspath = list(sys.path)
 
     def tearDown(self):
         sys.path[:] = self.syspath
         cleanout(self.root)
 
+        # delete all modules concerning the tested hiearchy
+        if self.pkgname:
+            modules = [name for name in sys.modules
+                       if self.pkgname in name.split('.')]
+            for name in modules:
+                del sys.modules[name]
+
     def run_code(self, code):
         exec(textwrap.dedent(code), globals(), {"self": self})
 
@@ -74,6 +82,8 @@
                     f.write('\n')
                 f.close()
         self.root = root
+        # package name is the name of the first item
+        self.pkgname = descr[0][0]
 
     def test_1(self):
         hier = [("t1", None), ("t1 __init__"+os.extsep+"py", "")]
@@ -223,8 +233,8 @@
 
     def test_7(self):
         hier = [
-                ("t7"+os.extsep+"py", ""),
                 ("t7", None),
+                ("t7"+os.extsep+"py", ""),
                 ("t7 __init__"+os.extsep+"py", ""),
                 ("t7 sub"+os.extsep+"py",
                  "raise RuntimeError('Shouldnt load sub.py')"),

Modified: python/trunk/Lib/test/test_pkgutil.py
==============================================================================
--- python/trunk/Lib/test/test_pkgutil.py	(original)
+++ python/trunk/Lib/test/test_pkgutil.py	Sat Apr 19 01:31:33 2008
@@ -48,6 +48,8 @@
         res2 = pkgutil.get_data(pkg, 'sub/res.txt')
         self.assertEqual(res2, RESOURCE_DATA)
 
+        del sys.modules[pkg]
+
     def test_getdata_zipfile(self):
         zip = 'test_getdata_zipfile.zip'
         pkg = 'test_getdata_zipfile'
@@ -74,6 +76,8 @@
         self.assertEqual(res2, RESOURCE_DATA)
         del sys.path[0]
 
+        del sys.modules[pkg]
+
 class PkgutilPEP302Tests(unittest.TestCase):
 
     class MyTestLoader(object):

Modified: python/trunk/Lib/test/test_profile.py
==============================================================================
--- python/trunk/Lib/test/test_profile.py	(original)
+++ python/trunk/Lib/test/test_profile.py	Sat Apr 19 01:31:33 2008
@@ -21,8 +21,9 @@
     def do_profiling(cls):
         results = []
         prof = cls.profilerclass(timer, 0.001)
+        start_timer = timer()
         prof.runctx("testfunc()", globals(), locals())
-        results.append(timer())
+        results.append(timer() - start_timer)
         for methodname in cls.methodnames:
             s = StringIO()
             stats = pstats.Stats(prof, stream=s)
@@ -33,7 +34,7 @@
 
     def test_cprofile(self):
         results = self.do_profiling()
-        self.assertEqual(results[0], 43000)
+        self.assertEqual(results[0], 1000)
         for i, method in enumerate(self.methodnames):
             self.assertEqual(results[i+1], self.expected_output[method],
                              "Stats.%s output for %s doesn't fit expectation!" %

Modified: python/trunk/Lib/test/test_structmembers.py
==============================================================================
--- python/trunk/Lib/test/test_structmembers.py	(original)
+++ python/trunk/Lib/test/test_structmembers.py	Sat Apr 19 01:31:33 2008
@@ -101,12 +101,6 @@
 
 
 def test_main(verbose=None):
-    # Obscure hack so that this test passes after reloads or repeated calls
-    # to test_main (regrtest -R).
-    if '__warningregistry__' in globals():
-        del globals()['__warningregistry__']
-    if hasattr(sys, '__warningregistry__'):
-        del sys.__warningregistry__
     test_support.run_unittest(__name__)
 
 if __name__ == "__main__":

Modified: python/trunk/Lib/test/test_warnings.py
==============================================================================
--- python/trunk/Lib/test/test_warnings.py	(original)
+++ python/trunk/Lib/test/test_warnings.py	Sat Apr 19 01:31:33 2008
@@ -391,6 +391,8 @@
 
 
 def test_main():
+    py_warnings.onceregistry.clear()
+    c_warnings.onceregistry.clear()
     test_support.run_unittest(CFilterTests,
                                 PyFilterTests,
                                 CWarnTests,


More information about the Python-checkins mailing list