From: Michael Trier Date: Mon, 13 Apr 2009 04:25:41 +0000 (+0000) Subject: Added copy and __copy__ methods to the OrderedDict. Fixes #1377. X-Git-Tag: rel_0_5_4~22 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a7e0fdd5fcd62ebb299364f845e496b61ead55a8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Added copy and __copy__ methods to the OrderedDict. Fixes #1377. --- diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 038040d87f..dbc7d3ea48 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -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) diff --git a/test/base/utils.py b/test/base/utils.py index 0b7762b7d6..bc3fc02838 100644 --- a/test/base/utils.py +++ b/test/base/utils.py @@ -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