[Python-checkins] cpython (2.7): Issue 12717: Fix-up an earlier backport in ConfigParser.

raymond.hettinger python-checkins at python.org
Tue Aug 9 21:07:23 CEST 2011


http://hg.python.org/cpython/rev/7d5a37ce42d5
changeset:   71789:7d5a37ce42d5
branch:      2.7
user:        Raymond Hettinger <python at rcn.com>
date:        Tue Aug 09 12:07:15 2011 -0700
summary:
  Issue 12717: Fix-up an earlier backport in ConfigParser.

files:
  Lib/ConfigParser.py        |   2 +-
  Lib/test/test_cfgparser.py |  22 ++++++++++++++++++++++
  2 files changed, 23 insertions(+), 1 deletions(-)


diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py
--- a/Lib/ConfigParser.py
+++ b/Lib/ConfigParser.py
@@ -570,7 +570,7 @@
     def keys(self):
         result = []
         seen = set()
-        for mapping in self_maps:
+        for mapping in self._maps:
             for key in mapping:
                 if key not in seen:
                     result.append(key)
diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py
--- a/Lib/test/test_cfgparser.py
+++ b/Lib/test/test_cfgparser.py
@@ -529,6 +529,27 @@
 class SafeConfigParserTestCaseNoValue(SafeConfigParserTestCase):
     allow_no_value = True
 
+class TestChainMap(unittest.TestCase):
+    def test_issue_12717(self):
+        d1 = dict(red=1, green=2)
+        d2 = dict(green=3, blue=4)
+        dcomb = d2.copy()
+        dcomb.update(d1)
+        cm = ConfigParser._Chainmap(d1, d2)
+        self.assertIsInstance(cm.keys(), list)
+        self.assertEqual(set(cm.keys()), set(dcomb.keys()))      # keys()
+        self.assertEqual(set(cm.values()), set(dcomb.values()))  # values()
+        self.assertEqual(set(cm.items()), set(dcomb.items()))    # items()
+        self.assertEqual(set(cm), set(dcomb))                    # __iter__ ()
+        self.assertEqual(cm, dcomb)                              # __eq__()
+        self.assertEqual([cm[k] for k in dcomb], dcomb.values()) # __getitem__()
+        klist = 'red green blue black brown'.split()
+        self.assertEqual([cm.get(k, 10) for k in klist],
+                         [dcomb.get(k, 10) for k in klist])      # get()
+        self.assertEqual([k in cm for k in klist],
+                         [k in dcomb for k in klist])            # __contains__()
+        self.assertEqual([cm.has_key(k) for k in klist],
+                         [dcomb.has_key(k) for k in klist])      # has_key()
 
 class Issue7005TestCase(unittest.TestCase):
     """Test output when None is set() as a value and allow_no_value == False.
@@ -591,6 +612,7 @@
         SafeConfigParserTestCaseNoValue,
         SortedTestCase,
         Issue7005TestCase,
+        TestChainMap,
         )
 
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list