]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
initializing _labels to an empty list so that the other methods don't throw exception...
authorDiana Clarke <diana.joan.clarke@gmail.com>
Sat, 17 Nov 2012 20:28:50 +0000 (15:28 -0500)
committerDiana Clarke <diana.joan.clarke@gmail.com>
Sat, 17 Nov 2012 20:28:50 +0000 (15:28 -0500)
lib/sqlalchemy/util/_collections.py
test/base/test_utils.py

index cefbb6d7f770a5332c679ea203e0be4fd3d03a42..0ed13f0d58fdd364ce4e04129b74c6894d668274 100644 (file)
@@ -33,6 +33,7 @@ class KeyedTuple(tuple):
 
     def __new__(cls, vals, labels=None):
         t = tuple.__new__(cls, vals)
+        t._labels = []
         if labels:
             t.__dict__.update(zip(labels, vals))
             t._labels = labels
index fe46377a27b0d334f82265d30a9a3aded48d15c0..af881af179e8dc3f71da074709f5935e1876b493 100644 (file)
@@ -13,35 +13,26 @@ class KeyedTupleTest():
         keyed_tuple = util.KeyedTuple([])
         eq_(type(keyed_tuple), util.KeyedTuple)
         eq_(str(keyed_tuple), '()')
-        eq_(keyed_tuple.__dict__, {})
+        eq_(len(keyed_tuple), 0)
 
-        # 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)
+        eq_(keyed_tuple.__dict__, {'_labels': []})
+        eq_(keyed_tuple.keys(), [])
+        eq_(keyed_tuple._fields, ())
+        eq_(keyed_tuple._asdict(), {})
 
     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__, {})
-
-        # TODO: consider returning an empty [] rather than raising
-        assert_raises(AttributeError, keyed_tuple.keys)
+        eq_(len(keyed_tuple), 2)
 
-        # TODO: consider returning an empty {} rather than raising
-        assert_raises(AttributeError, keyed_tuple._asdict)
+        eq_(keyed_tuple.__dict__, {'_labels': []})
+        eq_(keyed_tuple.keys(), [])
+        eq_(keyed_tuple._fields, ())
+        eq_(keyed_tuple._asdict(), {})
 
-        # TODO: consider returning an empty () rather than raising
-        def should_raise():
-            keyed_tuple._fields
-        assert_raises(AttributeError, should_raise)
+        eq_(keyed_tuple[0], 1)
+        eq_(keyed_tuple[1], 2)
 
     def test_basic_creation(self):
         keyed_tuple = util.KeyedTuple([1, 2], ['a', 'b'])