]> granicus.if.org Git - python/commitdiff
Merged revisions 62873,62887,62892-62896,62904 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Thu, 8 May 2008 22:27:58 +0000 (22:27 +0000)
committerBenjamin Peterson <benjamin@python.org>
Thu, 8 May 2008 22:27:58 +0000 (22:27 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r62873 | raymond.hettinger | 2008-05-08 12:18:13 -0500 (Thu, 08 May 2008) | 1 line

  Issue 2778.  Document the temporary frozenset swap in __contains__(), remove(), and discard().
........
  r62887 | brett.cannon | 2008-05-08 14:50:51 -0500 (Thu, 08 May 2008) | 5 lines

  Make test.test_support.catch_warning() take an argument specifying if any
  triggered warnings should be captured. This allows the context manager to be
  used to just prevent the internal state of the 'warnings' framework and thus
  allow triggered warnings to be displayed.
........
  r62892 | brett.cannon | 2008-05-08 15:20:24 -0500 (Thu, 08 May 2008) | 4 lines

  Fix a bug introduced by the addition of the 'record' argument to
  test.test_support.catch_warning() where showwarning() was not being set
  properly.
........
  r62893 | brett.cannon | 2008-05-08 15:20:54 -0500 (Thu, 08 May 2008) | 2 lines

  Document the 'record' argument for test.test_support.catch_warning().
........
  r62894 | brett.cannon | 2008-05-08 15:23:06 -0500 (Thu, 08 May 2008) | 4 lines

  Fix sys.flags to properly expose bytes_warning.

  Closes issue #2790.
........
  r62895 | brett.cannon | 2008-05-08 15:23:54 -0500 (Thu, 08 May 2008) | 2 lines

  Add a missing entry on  the fix for issue #2790.
........
  r62896 | brett.cannon | 2008-05-08 15:24:43 -0500 (Thu, 08 May 2008) | 2 lines

  Add test.test_support.catch_warning()'s new argument.
........
  r62904 | benjamin.peterson | 2008-05-08 17:09:54 -0500 (Thu, 08 May 2008) | 2 lines

  Replace instances of os.path.walk with os.walk
........

Doc/library/stdtypes.rst
Doc/library/test.rst
Lib/distutils/archive_util.py
Lib/test/test_repr.py
Lib/test/test_support.py
Lib/test/test_sys.py

index 14aa28df9bb8524eec744380fa3539c941f2e381..c97e9ae81e6625179dbce9fb5b327adc8c7e2048 100644 (file)
@@ -1539,7 +1539,7 @@ proper superset of the second set (is a superset, but is not equal).
 
 Instances of :class:`set` are compared to instances of :class:`frozenset` based
 on their members.  For example, ``set('abc') == frozenset('abc')`` returns
-``True``.
+``True`` and so does ``set('abc') in set([frozenset('abc')])``.
 
 The subset and equality comparisons do not generalize to a complete ordering
 function.  For example, any two disjoint sets are not equal and are not subsets
@@ -1578,18 +1578,18 @@ apply to immutable instances of :class:`frozenset`:
 
    Update the set, keeping only elements found in either set, but not in both.
 
-.. method:: set.add(el)
+.. method:: set.add(elem)
 
-   Add element *el* to the set.
+   Add element *elem* to the set.
 
-.. method:: set.remove(el)
+.. method:: set.remove(elem)
 
-   Remove element *el* from the set.  Raises :exc:`KeyError` if *el* is not
+   Remove element *elem* from the set.  Raises :exc:`KeyError` if *elem* is not
    contained in the set.
 
-.. method:: set.discard(el)
+.. method:: set.discard(elem)
 
-   Remove element *el* from the set if it is present.
+   Remove element *elem* from the set if it is present.
 
 .. method:: set.pop()
 
@@ -1606,6 +1606,12 @@ Note, the non-operator versions of the :meth:`update`,
 :meth:`symmetric_difference_update` methods will accept any iterable as an
 argument.
 
+Note, the *elem* argument to the :meth:`__contains__`, :meth:`remove`, and
+:meth:`discard` methods may be a set.  To support searching for an equivalent
+frozenset, the *elem* set is temporarily mutated during the search and then
+restored.  During the search, the *elem* set should not be read or mutated
+since it does not have a meaningful value.
+
 
 .. _typesmapping:
 
index 6c35d50263190b3d7a394302afdadbb5f98e12cc..a6a3584823360ab8c581da034f97638f0ee156c2 100644 (file)
@@ -283,13 +283,15 @@ The :mod:`test.test_support` module defines the following functions:
    This will run all tests defined in the named module.
 
 
-.. function:: catch_warning()
+.. function:: catch_warning(record=True)
 
-   This is a context manager that guards the warnings filter from being
+   Return a context manager that guards the warnings filter from being
    permanently changed and records the data of the last warning that has been
-   issued.
+   issued. The ``record`` argument specifies whether any raised warnings are
+   captured by the object returned by :func:`warnings.catch_warning` or allowed
+   to propagate as normal.
 
-   Use like this::
+   The context manager is typically used like this::
 
       with catch_warning() as w:
           warnings.warn("foo")
index f3f65c6a0c16e17dbc29853e277426dcf0307e60..9444ff012fb937cdfd99e031acd018f82c18f122 100644 (file)
@@ -92,18 +92,16 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0):
         log.info("creating '%s' and adding '%s' to it",
                  zip_filename, base_dir)
 
-        def visit (z, dirname, names):
-            for name in names:
-                path = os.path.normpath(os.path.join(dirname, name))
-                if os.path.isfile(path):
-                    z.write(path, path)
-                    log.info("adding '%s'" % path)
-
         if not dry_run:
             z = zipfile.ZipFile(zip_filename, "w",
                                 compression=zipfile.ZIP_DEFLATED)
 
-            os.path.walk(base_dir, visit, z)
+            for dirpath, dirnames, filenames in os.walk(base_dir):
+                for name in filenames:
+                    path = os.path.normpath(os.path.join(dirpath, name))
+                    if os.path.isfile(path):
+                        z.write(path, path)
+                        log.info("adding '%s'" % path)
             z.close()
 
     return zip_filename
index af66e979e0c347fd5319ff3b251ad988b5e31bf9..ac1a0a0f393964763e842286937116cebb4d67cb 100644 (file)
@@ -197,10 +197,6 @@ def touch(path, text=''):
     fp.write(text)
     fp.close()
 
-def zap(actions, dirname, names):
-    for name in names:
-        actions.append(os.path.join(dirname, name))
-
 class LongReprTest(unittest.TestCase):
     def setUp(self):
         longname = 'areallylongpackageandmodulenametotestreprtruncation'
@@ -219,7 +215,9 @@ class LongReprTest(unittest.TestCase):
 
     def tearDown(self):
         actions = []
-        os.path.walk(self.pkgname, zap, actions)
+        for dirpath, dirnames, filenames in os.walk(self.pkgname):
+            for name in dirnames + filenames:
+                actions.append(os.path.join(dirpath, name))
         actions.append(self.pkgname)
         actions.sort()
         actions.reverse()
index 431b66bb092f7a90446a9fc072a0515986755ded..92592eb4d6f3d41765e3f9df692af19adef07084 100644 (file)
@@ -37,6 +37,19 @@ class ResourceDenied(TestSkipped):
     and unexpected skips.
     """
 
+def import_module(name, deprecated=False):
+    """Import the module to be tested, raising TestSkipped if it is not
+    available."""
+    with catch_warning(record=False):
+        if deprecated:
+            warnings.filterwarnings("ignore", ".+ module", DeprecationWarning)
+        try:
+            module = __import__(name, level=0)
+        except ImportError:
+            raise TestSkipped("No module named " + name)
+        else:
+            return module
+
 verbose = 1              # Flag set to 0 by regrtest.py
 use_resources = None     # Flag set to [] by regrtest.py
 max_memuse = 0           # Disable bigmem tests (they will still be run with
@@ -373,7 +386,7 @@ class WarningMessage(object):
 
 
 @contextlib.contextmanager
-def catch_warning(module=warnings):
+def catch_warning(module=warnings, record=True):
     """
     Guard the warnings filter from being permanently changed and record the
     data of the last warning that has been issued.
@@ -384,12 +397,13 @@ def catch_warning(module=warnings):
             warnings.warn("foo")
             assert str(w.message) == "foo"
     """
-    warning_obj = WarningMessage()
     original_filters = module.filters[:]
     original_showwarning = module.showwarning
-    module.showwarning = warning_obj._showwarning
+    if record:
+        warning_obj = WarningMessage()
+        module.showwarning = warning_obj._showwarning
     try:
-        yield warning_obj
+        yield warning_obj if record else None
     finally:
         module.showwarning = original_showwarning
         module.filters = original_filters
index 7961837e53461433b5690be60251e61be68dd363..3a0abe1586bc7ca3b18a0e1ee013f7e9354c2f14 100644 (file)
@@ -324,7 +324,8 @@ class SysModuleTest(unittest.TestCase):
         self.failUnless(sys.flags)
         attrs = ("debug", "division_warning",
                  "inspect", "interactive", "optimize", "dont_write_bytecode",
-                 "no_site", "ignore_environment", "tabcheck", "verbose")
+                 "no_site", "ignore_environment", "tabcheck", "verbose",
+                 "bytes_warning")
         for attr in attrs:
             self.assert_(hasattr(sys.flags, attr), attr)
             self.assertEqual(type(getattr(sys.flags, attr)), int, attr)