]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Added copy and __copy__ methods to the OrderedDict. Fixes #1377.
authorMichael Trier <mtrier@gmail.com>
Mon, 13 Apr 2009 04:25:41 +0000 (04:25 +0000)
committerMichael Trier <mtrier@gmail.com>
Mon, 13 Apr 2009 04:25:41 +0000 (04:25 +0000)
lib/sqlalchemy/util.py
test/base/utils.py

index 038040d87f832b9c03d868524b8af1bfa4d12bb9..dbc7d3ea48a2dce6aa63ea260c836611b082bc1e 100644 (file)
@@ -688,6 +688,12 @@ class OrderedDict(dict):
         self._list = []
         dict.clear(self)
 
+    def copy(self):
+        return self.__copy__()
+
+    def __copy__(self):
+        return OrderedDict(self)
+
     def sort(self, *arg, **kw):
         self._list.sort(*arg, **kw)
 
index 0b7762b7d6b81eb55c37ed9d642e38a97c802d93..bc3fc028384a84ef97ed6d444f814da2ec3f08da 100644 (file)
@@ -1,5 +1,5 @@
 import testenv; testenv.configure_for_tests()
-import threading, unittest
+import copy, threading, unittest
 from sqlalchemy import util, sql, exc
 from testlib import TestBase
 from testlib.testing import eq_, is_, ne_
@@ -55,6 +55,18 @@ class OrderedDictTest(TestBase):
         o = util.OrderedDict([('name', 'jbe'), ('fullname', 'jonathan'), ('password', '')])
         eq_(o.keys(), ['name', 'fullname', 'password'])
 
+    def test_odict_copy(self):
+        o = util.OrderedDict()
+        o["zzz"] = 1
+        o["aaa"] = 2
+        eq_(o.keys(), ['zzz', 'aaa'])
+
+        o2 = o.copy()
+        eq_(o2.keys(), o.keys())
+
+        o3 = copy.copy(o)
+        eq_(o3.keys(), o.keys())
+
 class OrderedSetTest(TestBase):
     def test_mutators_against_iter(self):
         # testing a set modified against an iterator