diff options
author | Jacob Magnusson <m@jacobian.se> | 2016-03-04 16:06:12 +0100 |
---|---|---|
committer | Jacob Magnusson <m@jacobian.se> | 2016-03-04 16:20:33 +0100 |
commit | 4e55ffae0710741e158ba97e7a27ce2f44bd9f16 (patch) | |
tree | eba643462146762db5ace138d4d9b59eb3309432 /test/base/test_utils.py | |
parent | 0e7904e730c3d2b0d3a394ad60010158ee29050c (diff) | |
download | sqlalchemy-pr/245.tar.gz |
Support recursive operation on _asdict and allow passing in dictionary implementationpr/245
Diffstat (limited to 'test/base/test_utils.py')
-rw-r--r-- | test/base/test_utils.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/test/base/test_utils.py b/test/base/test_utils.py index fcb9a59a3..0dafdb63a 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -7,7 +7,7 @@ from sqlalchemy.testing import eq_, is_, ne_, fails_if, mock, expect_warnings from sqlalchemy.testing.util import picklers, gc_collect from sqlalchemy.util import classproperty, WeakSequence, get_callable_argspec from sqlalchemy.sql import column -from sqlalchemy.util import langhelpers, compat +from sqlalchemy.util import OrderedDict, langhelpers, compat import inspect @@ -121,6 +121,33 @@ class _KeyedTupleTest(object): eq_(kt._fields, ('a', 'b')) eq_(kt._asdict(), {'a': 1, 'b': 3}) + def test_asdict_impl(self): + keyed_tuple = self._fixture([1, 2, 3, 4], ['a', 'b', 'c', 'd']) + from sqlalchemy.util import OrderedDict + assert keyed_tuple._asdict(impl=OrderedDict) == OrderedDict( + [['a', 1], ['b', 2], ['c', 3], ['d', 4]] + ) + + def test_asdict_recursive(self): + keyed_tuple = self._fixture( + [1, 2, self._fixture([3, 4], ['d', 'e'])], + ['a', 'b', 'c'] + ) + eq_( + keyed_tuple._asdict(recursive=True), + {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}} + ) + + def test_asdict_impl_recursive(self): + keyed_tuple = self._fixture( + [1, 2, self._fixture([3, 4], ['d', 'e'])], + ['a', 'b', 'c'] + ) + dct = keyed_tuple._asdict(impl=OrderedDict, recursive=True) + assert dct == OrderedDict( + [['a', 1], ['b', 2], ['c', OrderedDict([['d', 3], ['e', 4]])]] + ) + class KeyedTupleTest(_KeyedTupleTest, fixtures.TestBase): def _fixture(self, values, labels): |