summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2016-12-19 16:07:29 -0800
committerDylan Baker <dylan@pnwbakers.com>2016-12-21 17:14:03 -0800
commit84bee04c1abae4f1832c158b505cb1b724a54f50 (patch)
tree1f4c107b31e6dbec65dc7f8c3e22d10673db5d90 /tests
parent56eb5df98a68a513208ccb837170263d9d78bc3f (diff)
db/thread: don't create multiple lists to sort
Currently this function takes a list, splits into two lists based on whether or not a function returns None, sorts the list that isn't None, and then appends the list of None to the end. This creates 4 new concrete lists on each method call, requires the use of 3 filter + lambda pairs, and calls list.sort(). Pretty complicated and inefficient. This patch replaces that with a single sorted() function call with a kay function that replaces None with a value that is guaranteed to sort less than what Message.get_date() will return, but will not cause a comparison to None (which is an error in Python 3.x). This is all based on iterators and avoids the need for filter or list concatenation. This should result in only one new list being created.
Diffstat (limited to 'tests')
-rw-r--r--tests/db/thread_test.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/tests/db/thread_test.py b/tests/db/thread_test.py
index 41016c61..1194ad81 100644
--- a/tests/db/thread_test.py
+++ b/tests/db/thread_test.py
@@ -44,7 +44,7 @@ class TestThreadGetAuthor(unittest.TestCase):
m.get_author = mock.Mock(return_value=a)
get_messages.append(m)
gm = mock.Mock()
- gm.keys = mock.Mock(return_value=get_messages)
+ gm.iterkeys = mock.Mock(return_value=get_messages)
cls.__patchers.extend([
mock.patch('alot.db.thread.Thread.get_messages',