[Python-3000-checkins] r61205 - in python/branches/py3k: Lib/test/test_audioop.py Lib/test/test_dbm.py Lib/test/test_largefile.py Lib/test/test_logging.py Lib/test/test_pep247.py Misc/ACKS Python/ceval.c

christian.heimes python-3000-checkins at python.org
Mon Mar 3 20:15:45 CET 2008


Author: christian.heimes
Date: Mon Mar  3 20:15:45 2008
New Revision: 61205

Added:
   python/branches/py3k/Lib/test/test_logging.py
      - copied, changed from r61201, python/trunk/Lib/test/test_logging.py
Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_audioop.py
   python/branches/py3k/Lib/test/test_dbm.py
   python/branches/py3k/Lib/test/test_largefile.py
   python/branches/py3k/Lib/test/test_pep247.py
   python/branches/py3k/Misc/ACKS
   python/branches/py3k/Python/ceval.c
Log:
Merged revisions 61189-61190,61192,61194-61195,61198-61199 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r61189 | brett.cannon | 2008-03-03 01:38:58 +0100 (Mon, 03 Mar 2008) | 5 lines
  
  Refactor test_logging to use unittest. This should finally solve the flakiness
  issues.
   
  Thanks to Antoine Pitrou for the patch.
........
  r61190 | jeffrey.yasskin | 2008-03-03 02:27:03 +0100 (Mon, 03 Mar 2008) | 3 lines
  
  compile.c always emits END_FINALLY after WITH_CLEANUP, so predict that in
  ceval.c. This is worth about a .03-.04us speedup on a simple with block.
........
  r61192 | brett.cannon | 2008-03-03 03:41:40 +0100 (Mon, 03 Mar 2008) | 4 lines
  
  Move test_largefile over to using 'with' statements for open files.
  
  Also rename the driver function to test_main() instead of main_test().
........
  r61194 | brett.cannon | 2008-03-03 04:24:48 +0100 (Mon, 03 Mar 2008) | 3 lines
  
  Add a note in the main test class' docstring that the order of execution of the
  tests is important.
........
  r61195 | brett.cannon | 2008-03-03 04:26:43 +0100 (Mon, 03 Mar 2008) | 3 lines
  
  Add a note in the main test class' docstring that the order of execution of the
  tests is important.
........
  r61198 | brett.cannon | 2008-03-03 05:19:29 +0100 (Mon, 03 Mar 2008) | 4 lines
  
  Add test_main() functions to various tests where it was simple to do. Done so
  that regrtest can execute the test_main() directly instead of relying on import
  side-effects.
........
  r61199 | neal.norwitz | 2008-03-03 05:37:45 +0100 (Mon, 03 Mar 2008) | 1 line
  
  Only DECREF if ret != NULL
........


Modified: python/branches/py3k/Lib/test/test_audioop.py
==============================================================================
--- python/branches/py3k/Lib/test/test_audioop.py	(original)
+++ python/branches/py3k/Lib/test/test_audioop.py	Mon Mar  3 20:15:45 2008
@@ -271,7 +271,7 @@
     if not rv:
         print('Test FAILED for audioop.'+name+'()')
 
-def testall():
+def test_main():
     data = [gendata1(), gendata2(), gendata4()]
     names = dir(audioop)
     # We know there is a routine 'add'
@@ -281,4 +281,8 @@
             routines.append(n)
     for n in routines:
         testone(n, data)
-testall()
+
+
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k/Lib/test/test_dbm.py
==============================================================================
--- python/branches/py3k/Lib/test/test_dbm.py	(original)
+++ python/branches/py3k/Lib/test/test_dbm.py	Mon Mar  3 20:15:45 2008
@@ -44,12 +44,18 @@
     d = dbm.open(filename, 'n')
     d.close()
 
-cleanup()
-try:
-    test_keys()
-    test_modes()
-except:
+def test_main():
     cleanup()
-    raise
+    try:
+        test_keys()
+        test_modes()
+    except:
+        cleanup()
+        raise
 
-cleanup()
+    cleanup()
+
+
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k/Lib/test/test_largefile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_largefile.py	(original)
+++ python/branches/py3k/Lib/test/test_largefile.py	Mon Mar  3 20:15:45 2008
@@ -24,13 +24,17 @@
 class TestCase(unittest.TestCase):
     """Test that each file function works as expected for a large
     (i.e. > 2GB, do  we have to check > 4GB) files.
+
+    NOTE: the order of execution of the test methods is important! test_seek
+    must run first to create the test file. File cleanup must also be handled
+    outside the test instances because of this.
+
     """
 
     def test_seek(self):
         if verbose:
             print('create large file via seek (may be sparse file) ...')
-        f = open(TESTFN, 'wb')
-        try:
+        with open(TESTFN, 'wb') as f:
             f.write(b'z')
             f.seek(0)
             f.seek(size)
@@ -39,8 +43,6 @@
             if verbose:
                 print('check file size with os.fstat')
             self.assertEqual(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
-        finally:
-            f.close()
 
     def test_osstat(self):
         if verbose:
@@ -50,8 +52,7 @@
     def test_seek_read(self):
         if verbose:
             print('play around with seek() and read() with the built largefile')
-        f = open(TESTFN, 'rb')
-        try:
+        with open(TESTFN, 'rb') as f:
             self.assertEqual(f.tell(), 0)
             self.assertEqual(f.read(1), b'z')
             self.assertEqual(f.tell(), 1)
@@ -80,14 +81,11 @@
             f.seek(-size-1, 1)
             self.assertEqual(f.read(1), b'z')
             self.assertEqual(f.tell(), 1)
-        finally:
-            f.close()
 
     def test_lseek(self):
         if verbose:
             print('play around with os.lseek() with the built largefile')
-        f = open(TESTFN, 'rb')
-        try:
+        with open(TESTFN, 'rb') as f:
             self.assertEqual(os.lseek(f.fileno(), 0, 0), 0)
             self.assertEqual(os.lseek(f.fileno(), 42, 0), 42)
             self.assertEqual(os.lseek(f.fileno(), 42, 1), 84)
@@ -98,18 +96,15 @@
             self.assertEqual(os.lseek(f.fileno(), size, 0), size)
             # the 'a' that was written at the end of file above
             self.assertEqual(f.read(1), b'a')
-        finally:
-            f.close()
 
     def test_truncate(self):
         if verbose:
             print('try truncate')
-        f = open(TESTFN, 'r+b')
-        # this is already decided before start running the test suite
-        # but we do it anyway for extra protection
-        if not hasattr(f, 'truncate'):
-            raise TestSkipped("open().truncate() not available on this system")
-        try:
+        with open(TESTFN, 'r+b') as f:
+            # this is already decided before start running the test suite
+            # but we do it anyway for extra protection
+            if not hasattr(f, 'truncate'):
+                raise TestSkipped("open().truncate() not available on this system")
             f.seek(0, 2)
             # else we've lost track of the true size
             self.assertEqual(f.tell(), size+1)
@@ -134,10 +129,8 @@
             f.truncate(1)
             self.assertEqual(f.tell(), 0)       # else pointer moved
             self.assertEqual(len(f.read()), 1)  # else wasn't truncated
-        finally:
-            f.close()
 
-def main_test():
+def test_main():
     # On Windows and Mac OSX this test comsumes large resources; It
     # takes a long time to build the >2GB file and takes >2GB of disk
     # space therefore the resource must be enabled to run this test.
@@ -168,13 +161,14 @@
     suite.addTest(TestCase('test_osstat'))
     suite.addTest(TestCase('test_seek_read'))
     suite.addTest(TestCase('test_lseek'))
-    f = open(TESTFN, 'w')
-    if hasattr(f, 'truncate'):
-        suite.addTest(TestCase('test_truncate'))
-    f.close()
-    unlink(TESTFN)
-    run_unittest(suite)
+    with open(TESTFN, 'w') as f:
+        if hasattr(f, 'truncate'):
+            suite.addTest(TestCase('test_truncate'))
     unlink(TESTFN)
+    try:
+        run_unittest(suite)
+    finally:
+        unlink(TESTFN)
 
 if __name__ == '__main__':
-    main_test()
+    test_main()

Copied: python/branches/py3k/Lib/test/test_logging.py (from r61201, python/trunk/Lib/test/test_logging.py)
==============================================================================
--- python/trunk/Lib/test/test_logging.py	(original)
+++ python/branches/py3k/Lib/test/test_logging.py	Mon Mar  3 20:15:45 2008
@@ -26,8 +26,8 @@
 import logging.config
 
 import copy
-import cPickle
-import cStringIO
+import pickle
+import io
 import gc
 import os
 import re
@@ -71,7 +71,7 @@
         self.root_logger = logging.getLogger("")
         self.original_logging_level = self.root_logger.getEffectiveLevel()
 
-        self.stream = cStringIO.StringIO()
+        self.stream = io.StringIO()
         self.root_logger.setLevel(logging.DEBUG)
         self.root_hdlr = logging.StreamHandler(self.stream)
         self.root_formatter = logging.Formatter(self.log_format)
@@ -353,7 +353,7 @@
 
     def setUp(self):
         BaseTest.setUp(self)
-        for k, v in my_logging_levels.items():
+        for k, v in list(my_logging_levels.items()):
             logging.addLevelName(k, v)
 
     def log_at_all_levels(self, logger):
@@ -625,11 +625,11 @@
 
     def test_config2_failure(self):
         # A simple config file which overrides the default settings.
-        self.assertRaises(StandardError, self.apply_config, self.config2)
+        self.assertRaises(Exception, self.apply_config, self.config2)
 
     def test_config3_failure(self):
         # A simple config file which overrides the default settings.
-        self.assertRaises(StandardError, self.apply_config, self.config3)
+        self.assertRaises(Exception, self.apply_config, self.config3)
 
     def test_config4_ok(self):
         # A config file specifying a custom formatter class.
@@ -671,7 +671,7 @@
             self.handle_log_record(record)
 
     def unpickle(self, data):
-        return cPickle.loads(data)
+        return pickle.loads(data)
 
     def handle_log_record(self, record):
         # If the end-of-messages sentinel is seen, tell the server to
@@ -778,7 +778,7 @@
         # Trigger cycle breaking.
         gc.collect()
         dead = []
-        for (id_, repr_), ref in self._survivors.items():
+        for (id_, repr_), ref in list(self._survivors.items()):
             if ref() is None:
                 dead.append(repr_)
         if dead:

Modified: python/branches/py3k/Lib/test/test_pep247.py
==============================================================================
--- python/branches/py3k/Lib/test/test_pep247.py	(original)
+++ python/branches/py3k/Lib/test/test_pep247.py	Mon Mar  3 20:15:45 2008
@@ -5,6 +5,9 @@
 
 import hmac
 
+import hmac
+from test.test_support import verbose
+
 def check_hash_module(module, key=None):
     assert hasattr(module, 'digest_size'), "Must have digest_size"
     assert (module.digest_size is None or
@@ -41,8 +44,13 @@
         hd2 += "%02x" % byte
     assert hd2 == hexdigest, "hexdigest doesn't appear correct"
 
-    print('Module', module.__name__, 'seems to comply with PEP 247')
+    if verbose:
+        print('Module', module.__name__, 'seems to comply with PEP 247')
 
 
-if __name__ == '__main__':
+def test_main():
     check_hash_module(hmac, key=b'abc')
+
+
+if __name__ == '__main__':
+    test_main()

Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS	(original)
+++ python/branches/py3k/Misc/ACKS	Mon Mar  3 20:15:45 2008
@@ -527,6 +527,7 @@
 François Pinard
 Zach Pincus
 Michael Piotrowski
+Antoine Pitrou
 Michael Pomraning
 Iustin Pop
 John Popplewell

Modified: python/branches/py3k/Python/ceval.c
==============================================================================
--- python/branches/py3k/Python/ceval.c	(original)
+++ python/branches/py3k/Python/ceval.c	Mon Mar  3 20:15:45 2008
@@ -1455,6 +1455,7 @@
 			}
 			continue;
 
+		PREDICTED(END_FINALLY);
 		case END_FINALLY:
 			v = POP();
 			if (PyLong_Check(v)) {
@@ -2069,6 +2070,7 @@
 				x = POP();
 				Py_DECREF(x);
 			}
+			PREDICT(END_FINALLY);
 			break;
 		}
 


More information about the Python-3000-checkins mailing list