Fix a KeysEqual bug.
authorXiao Hanyu <xiaohanyu1988@gmail.com>
Thu, 13 Jun 2013 07:33:46 +0000 (15:33 +0800)
committerRobert Collins <robertc@robertcollins.net>
Sun, 13 Oct 2013 04:09:05 +0000 (17:09 +1300)
See https://bugs.launchpad.net/testtools/+bug/1177217 for details.

testtools/matchers/_dict.py
testtools/tests/matchers/test_dict.py

index ff05199e6c14b4a33422f43ed9c7a852988af991..b1ec9151b247144f56772c05701cdef32daaf42a 100644 (file)
@@ -241,7 +241,7 @@ class KeysEqual(Matcher):
         """
         super(KeysEqual, self).__init__()
         try:
-            self.expected = expected.keys()
+            self.expected = expected[0].keys()
         except AttributeError:
             self.expected = list(expected)
 
index c6e2c9c48c25e7ba61958952a6223ec9d631f9b3..00368dd6ceb14e9e2f7f6ff16cc0d75a1b4cb807 100644 (file)
@@ -30,7 +30,7 @@ class TestMatchesAllDictInterface(TestCase, TestMatchersInterface):
         ]
 
 
-class TestKeysEqual(TestCase, TestMatchersInterface):
+class TestKeysEqualWithList(TestCase, TestMatchersInterface):
 
     matches_matcher = KeysEqual('foo', 'bar')
     matches_matches = [
@@ -60,6 +60,11 @@ class TestKeysEqual(TestCase, TestMatchersInterface):
                 % (matchee,)))
 
 
+class TestKeysEqualWithDict(TestKeysEqualWithList):
+
+    matches_matcher = KeysEqual({'foo': 3, 'bar': 4})
+
+
 class TestSubDictOf(TestCase, TestMatchersInterface):
 
     matches_matcher = _SubDictOf({'foo': 'bar', 'baz': 'qux'})