Revision: 335474061191
Branch: default
Author: Pekka Klärck
Date: Thu Jun 13 18:17:55 2013
Log: ConnectionCache: better algorithm to calculate current_index
http://code.google.com/p/robotframework/source/detail?r=335474061191
Modified:
/src/robot/utils/connectioncache.py
/utest/utils/test_connectioncache.py
=======================================
--- /src/robot/utils/connectioncache.py Thu Jun 13 15:44:34 2013
+++ /src/robot/utils/connectioncache.py Thu Jun 13 18:17:55 2013
@@ -35,7 +35,11 @@
self._aliases = NormalizedDict()
def _get_current_index(self):
- return self._connections.index(self.current) + 1 if self else None
+ if not self:
+ return None
+ for index, conn in enumerate(self):
+ if conn is self.current:
+ return index + 1
def _set_current_index(self, index):
self.current = self._connections[index - 1] \
=======================================
--- /utest/utils/test_connectioncache.py Thu Jun 13 15:32:53 2013
+++ /utest/utils/test_connectioncache.py Thu Jun 13 18:17:55 2013
@@ -8,15 +8,21 @@
class ConnectionMock:
+
def __init__(self, id=None):
self.id = id
self.closed_by_close = False
self.closed_by_exit = False
+
def close(self):
self.closed_by_close = True
+
def exit(self):
self.closed_by_exit = True
+ def __eq__(self, other):
+ return hasattr(other, 'id') and self.id == other.id
+
class TestConnnectionCache(unittest.TestCase):
@@ -42,7 +48,7 @@
assert_equals(self.cache._aliases, {})
def test_register_multiple(self):
- conns = [ConnectionMock(), ConnectionMock(), ConnectionMock()]
+ conns = [ConnectionMock(1), ConnectionMock(2), ConnectionMock(3)]
for i, conn in enumerate(conns):
index = self.cache.register(conn)
assert_equals(index, i+1)
@@ -50,6 +56,24 @@
assert_equals(self.cache.current_index, i+1)
assert_equals(self.cache._connections, conns)
+ def test_register_multiple_equal_objects(self):
+ conns = [ConnectionMock(1), ConnectionMock(1), ConnectionMock(1)]
+ for i, conn in enumerate(conns):
+ index = self.cache.register(conn)
+ assert_equals(index, i+1)
+ assert_equals(self.cache.current, conn)
+ assert_equals(self.cache.current_index, i+1)
+ assert_equals(self.cache._connections, conns)
+
+ def test_register_multiple_same_object(self):
+ conns = [ConnectionMock()] * 3
+ for i, conn in enumerate(conns):
+ index = self.cache.register(conn)
+ assert_equals(index, i+1)
+ assert_equals(self.cache.current, conn)
+ assert_equals(self.cache.current_index, 1)
+ assert_equals(self.cache._connections, conns)
+
def test_set_current_index(self):
self.cache.current_index = None
assert_equals(self.cache.current_index, None)
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.