2 new revisions:
Revision: 6fce476b502f
Author: Pekka Klärck
Date: Sun Nov 6 09:41:17 2011
Log: ItemList.extend: Add all items to internal storage in one go and
not o...
http://code.google.com/p/robotframework/source/detail?r=6fce476b502f
Revision: cf8b0773bc99
Author: Pekka Klärck
Date: Sun Nov 6 09:54:51 2011
Log: ItemList: Slicing should have returned new item list. That would
have ...
http://code.google.com/p/robotframework/source/detail?r=cf8b0773bc99
==============================================================================
Revision: 6fce476b502f
Author: Pekka Klärck
Date: Sun Nov 6 09:41:17 2011
Log: ItemList.extend: Add all items to internal storage in one go and
not one-by-one. Did some timings and noticed that's considerably faster
(depends on how many items are extended) but not sure does it matter in
real life with our code.
http://code.google.com/p/robotframework/source/detail?r=6fce476b502f
Modified:
/src/robot/result/model.py
=======================================
--- /src/robot/result/model.py Sat Nov 5 14:46:42 2011
+++ /src/robot/result/model.py Sun Nov 6 09:41:17 2011
@@ -345,7 +345,7 @@
# parent. Need to investigate why **common_attrs took so much
memory.
self._item_class = item_class
self._parent = parent
- self._items = ()
+ self._items = () # Tuples take less memory than lists
if items:
self.extend(items)
@@ -354,16 +354,20 @@
return self._items[-1]
def append(self, item):
+ self._check_type_and_set_attrs(item)
+ self._items += (item,)
+
+ def _check_type_and_set_attrs(self, item):
if not isinstance(item, self._item_class):
raise TypeError("Only '%s' objects accepted, got '%s'"
% (self._item_class.__name__,
type(item).__name__))
if self._parent:
item.parent = self._parent
- self._items += (item,)
def extend(self, items):
for item in items:
- self.append(item)
+ self._check_type_and_set_attrs(item)
+ self._items += tuple(items)
def visit(self, visitor):
for item in self:
==============================================================================
Revision: cf8b0773bc99
Author: Pekka Klärck
Date: Sun Nov 6 09:54:51 2011
Log: ItemList: Slicing should have returned new item list. That would
have required some more work (basically copy) and it was easier to just
disallow slicing altogether.
http://code.google.com/p/robotframework/source/detail?r=cf8b0773bc99
Modified:
/src/robot/result/model.py
/utest/result/test_resultmodel.py
=======================================
--- /src/robot/result/model.py Sun Nov 6 09:41:17 2011
+++ /src/robot/result/model.py Sun Nov 6 09:54:51 2011
@@ -377,6 +377,8 @@
return iter(self._items)
def __getitem__(self, index):
+ if isinstance(index, slice):
+ raise ValueError("'%s' object does not support slicing" %
type(self).__name__)
return self._items[index]
def __len__(self):
=======================================
--- /utest/result/test_resultmodel.py Sat Nov 5 12:18:44 2011
+++ /utest/result/test_resultmodel.py Sun Nov 6 09:54:51 2011
@@ -229,12 +229,8 @@
assert_true(items[1] is item2)
assert_true(items[-1] is item2)
- def test_getitem_slice(self):
- items = ItemList(int, range(10))
- assert_true(isinstance(items[1:], tuple))
- assert_equal(items[:], tuple(items))
- assert_equal(items[:-1], tuple(range(9)))
- assert_equal(items[-1:1:-2], tuple(range(9, 1, -2)))
+ def test_getitem_slice_is_not_supported(self):
+ assert_raises(ValueError, ItemList(int).__getitem__, slice(0))
def test_len(self):
items = ItemList(object)