Skip to content

Commit

Permalink
Add missing cidict.copy() method
Browse files Browse the repository at this point in the history
The copy() method vanished when cidict was re-implemented on top of
MutableMapping abstract base class.

See: commit 2a2cef3
Fixes: https://github.com/python-ldap/python-ldap/issues/387
Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed Nov 13, 2020
1 parent 2647f59 commit c2e045d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Lib/ldap/cidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def clear(self):
self._keys.clear()
self._data.clear()

def copy(self):
inst = self.__class__.__new__(self.__class__)
inst._data = self._data.copy()
inst._keys = self._keys.copy()
return inst

__copy__ = copy

# Backwards compatibility

def has_key(self, key):
Expand Down
13 changes: 13 additions & 0 deletions Tests/t_cidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def test_cidict_data(self):
assert data == {'a': 1, 'b': 2}
self.assertEqual(len(w), 1)

def test_copy(self):
cix1 = ldap.cidict.cidict(
{"a": 1, "B": 2}
)
cix2 = cix1.copy()
self.assertEqual(cix1, cix2)
cix1["c"] = 3
self.assertNotIn("c", cix2)
cix2["C"] = 4
self.assertNotEqual(cix1, cix2)
self.assertEqual(list(cix1.keys()), ["a", "B", "c"])
self.assertEqual(list(cix2.keys()), ["a", "B", "C"])


if __name__ == '__main__':
unittest.main()

0 comments on commit c2e045d

Please sign in to comment.