PYTHON-2518 SON class should be compatible with Python 3's OrderedDict API (#730)
This commit is contained in:
parent
23fe13fcba
commit
fbd5599deb
@ -62,9 +62,6 @@ class SON(dict):
|
||||
self.__keys.remove(key)
|
||||
dict.__delitem__(self, key)
|
||||
|
||||
def keys(self):
|
||||
return list(self.__keys)
|
||||
|
||||
def copy(self):
|
||||
other = SON()
|
||||
other.update(self)
|
||||
|
||||
@ -23,7 +23,7 @@ sys.path[0:0] = [""]
|
||||
|
||||
from bson.son import SON
|
||||
from test import unittest
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
class TestSON(unittest.TestCase):
|
||||
def test_ordered_dict(self):
|
||||
@ -189,5 +189,21 @@ class TestSON(unittest.TestCase):
|
||||
test_son.popitem()
|
||||
self.assertEqual(2, len(test_son))
|
||||
|
||||
def test_keys(self):
|
||||
# Test to make sure that set operations do not throw an error
|
||||
d = SON().keys()
|
||||
for i in [OrderedDict, dict]:
|
||||
try:
|
||||
d - i().keys()
|
||||
except TypeError:
|
||||
self.fail("SON().keys() is not returning an object compatible "
|
||||
"with %s objects" % (str(i)))
|
||||
# Test to verify correctness
|
||||
d = SON({"k": "v"}).keys()
|
||||
for i in [OrderedDict, dict]:
|
||||
self.assertEqual(d | i({"k1": 0}).keys(), {"k", "k1"})
|
||||
for i in [OrderedDict, dict]:
|
||||
self.assertEqual(d - i({"k": 0}).keys(), set())
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user