diff options
author | Diana Clarke <diana.joan.clarke@gmail.com> | 2012-11-17 14:55:26 -0500 |
---|---|---|
committer | Diana Clarke <diana.joan.clarke@gmail.com> | 2012-11-17 14:55:26 -0500 |
commit | dbdd0fdd48bc0baf13a614fd193ad4fd6f697840 (patch) | |
tree | eb0dda39d9805b73b0ac9a90228a2ebd3637c8ad /test/base/test_utils.py | |
parent | 8d85a3c4e5ac731c8fa80b5258c0024c4bddf819 (diff) | |
download | sqlalchemy-dbdd0fdd48bc0baf13a614fd193ad4fd6f697840.tar.gz |
adding _fields, _asdict() to KeyedTuple #2601
Diffstat (limited to 'test/base/test_utils.py')
-rw-r--r-- | test/base/test_utils.py | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/test/base/test_utils.py b/test/base/test_utils.py index 14da4768d..fe46377a2 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -15,21 +15,43 @@ class KeyedTupleTest(): eq_(str(keyed_tuple), '()') eq_(keyed_tuple.__dict__, {}) - # consider returning an empty [] rather than raising + # TODO: consider returning an empty [] rather than raising assert_raises(AttributeError, keyed_tuple.keys) + # TODO: consider returning an empty {} rather than raising + assert_raises(AttributeError, keyed_tuple._asdict) + + # TODO: consider returning an empty () rather than raising + def should_raise(): + keyed_tuple._fields + assert_raises(AttributeError, should_raise) + def test_values_but_no_labels(self): keyed_tuple = util.KeyedTuple([1, 2]) eq_(type(keyed_tuple), util.KeyedTuple) eq_(str(keyed_tuple), '(1, 2)') eq_(keyed_tuple.__dict__, {}) - # consider returning an empty [] rather than raising + # TODO: consider returning an empty [] rather than raising assert_raises(AttributeError, keyed_tuple.keys) - def test_basic_index_access(self): + # TODO: consider returning an empty {} rather than raising + assert_raises(AttributeError, keyed_tuple._asdict) + + # TODO: consider returning an empty () rather than raising + def should_raise(): + keyed_tuple._fields + assert_raises(AttributeError, should_raise) + + def test_basic_creation(self): keyed_tuple = util.KeyedTuple([1, 2], ['a', 'b']) eq_(str(keyed_tuple), '(1, 2)') + eq_(keyed_tuple.keys(), ['a', 'b']) + eq_(keyed_tuple._fields, ('a', 'b')) + eq_(keyed_tuple._asdict(), {'a': 1, 'b': 2}) + + def test_basic_index_access(self): + keyed_tuple = util.KeyedTuple([1, 2], ['a', 'b']) eq_(keyed_tuple[0], 1) eq_(keyed_tuple[1], 2) @@ -39,7 +61,6 @@ class KeyedTupleTest(): def test_basic_attribute_access(self): keyed_tuple = util.KeyedTuple([1, 2], ['a', 'b']) - eq_(str(keyed_tuple), '(1, 2)') eq_(keyed_tuple.a, 1) eq_(keyed_tuple.b, 2) @@ -50,9 +71,13 @@ class KeyedTupleTest(): def test_none_label(self): keyed_tuple = util.KeyedTuple([1, 2, 3], ['a', None, 'b']) eq_(str(keyed_tuple), '(1, 2, 3)') + + # TODO: consider not allowing None labels expected = {'a': 1, None: 2, 'b': 3, '_labels': ['a', None, 'b']} eq_(keyed_tuple.__dict__, expected) eq_(keyed_tuple.keys(), ['a', 'b']) + eq_(keyed_tuple._fields, ('a', 'b')) + eq_(keyed_tuple._asdict(), {'a': 1, 'b': 3}) # attribute access: can't get at value 2 eq_(keyed_tuple.a, 1) @@ -66,9 +91,13 @@ class KeyedTupleTest(): def test_duplicate_labels(self): keyed_tuple = util.KeyedTuple([1, 2, 3], ['a', 'b', 'b']) eq_(str(keyed_tuple), '(1, 2, 3)') + + # TODO: consider not allowing duplicate labels expected = {'a': 1, 'b': 3, '_labels': ['a', 'b', 'b']} eq_(keyed_tuple.__dict__, expected) eq_(keyed_tuple.keys(), ['a', 'b', 'b']) + eq_(keyed_tuple._fields, ('a', 'b', 'b')) + eq_(keyed_tuple._asdict(), {'a': 1, 'b': 3}) # attribute access: can't get at value 2 eq_(keyed_tuple.a, 1) |