From: Jason Kirtland Date: Tue, 3 Jul 2007 21:04:47 +0000 (+0000) Subject: Add a test for that OrderedDict fix, also add more paranoia in the constructor. X-Git-Tag: rel_0_4_6~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e48cab5ad4defae425f609a1117c2e3708116c5;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add a test for that OrderedDict fix, also add more paranoia in the constructor. --- diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 3a59cbbbd5..47e729d7de 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -266,12 +266,12 @@ class OrderedProperties(object): class OrderedDict(dict): """A Dictionary that returns keys/values/items in the order they were added.""" - def __init__(self, d=None, **kwargs): + def __init__(self, ____sequence=None, **kwargs): self._list = [] - if d is None: + if ____sequence is None: self.update(**kwargs) else: - self.update(d, **kwargs) + self.update(____sequence, **kwargs) def clear(self): self._list = [] diff --git a/test/base/alltests.py b/test/base/alltests.py index 70ff83ab8a..44fa9b2ecf 100644 --- a/test/base/alltests.py +++ b/test/base/alltests.py @@ -5,6 +5,7 @@ def suite(): modules_to_test = ( # core utilities 'base.dependency', + 'base.utils', ) alltests = unittest.TestSuite() for name in modules_to_test: diff --git a/test/base/utils.py b/test/base/utils.py new file mode 100644 index 0000000000..ccf6b44197 --- /dev/null +++ b/test/base/utils.py @@ -0,0 +1,36 @@ +import testbase +from sqlalchemy import util + +class OrderedDictTest(testbase.PersistTest): + def test_odict(self): + o = util.OrderedDict() + o['a'] = 1 + o['b'] = 2 + o['snack'] = 'attack' + o['c'] = 3 + + self.assert_(o.keys() == ['a', 'b', 'snack', 'c']) + self.assert_(o.values() == [1, 2, 'attack', 3]) + + o.pop('snack') + + self.assert_(o.keys() == ['a', 'b', 'c']) + self.assert_(o.values() == [1, 2, 3]) + + o2 = util.OrderedDict(d=4) + o2['e'] = 5 + + self.assert_(o2.keys() == ['d', 'e']) + self.assert_(o2.values() == [4, 5]) + + o.update(o2) + self.assert_(o.keys() == ['a', 'b', 'c', 'd', 'e']) + self.assert_(o.values() == [1, 2, 3, 4, 5]) + + o.setdefault('c', 'zzz') + o.setdefault('f', 6) + self.assert_(o.keys() == ['a', 'b', 'c', 'd', 'e', 'f']) + self.assert_(o.values() == [1, 2, 3, 4, 5, 6]) + +if __name__ == "__main__": + testbase.main()