def test_reverse(self): """Test the `reverse` kwarg.""" iterables = [range(4, 0, -1), range(7, 0, -1), range(3, 6, -1)] self.assertEqual(sorted(reduce(list.__add__, [list(it) for it in iterables]), reverse=True), list(collate(*iterables, reverse=True)))
def test_key(self): """Test using a custom `key` function.""" iterables = [xrange(5, 0, -1), xrange(4, 0, -1)] eq_(list(sorted(reduce(list.__add__, [list(it) for it in iterables]), reverse=True)), list(collate(*iterables, key=lambda x: -x)))
def test_key(self): """Test using a custom `key` function.""" iterables = [range(5, 0, -1), range(4, 0, -1)] self.assertEqual( list( sorted(reduce(list.__add__, [list(it) for it in iterables]), reverse=True)), list(collate(*iterables, key=lambda x: -x)))
def _users_watching(self, **kwargs): # Get a sorted iterable of user-watches pairs: users_and_watches = collate( *[e._users_watching(**kwargs) for e in self.events], key=lambda (user, watch): user.email.lower(), reverse=True) # Pick the best User out of each cluster of identical email addresses: return _unique_by_email(users_and_watches)
def test_one(self): """Work when only 1 iterable is passed.""" eq_([0, 1], list(collate(xrange(2))))
def test_empty(self): """Be nice if passed an empty list of iterables.""" eq_([], list(collate()))
def test_default(self): """Test with the default `key` function.""" iterables = [xrange(4), xrange(7), xrange(3, 6)] eq_(sorted(reduce(list.__add__, [list(it) for it in iterables])), list(collate(*iterables)))
def test_default(self): """Test with the default `key` function.""" iterables = [range(4), range(7), range(3, 6)] self.assertEqual( sorted(reduce(list.__add__, [list(it) for it in iterables])), list(collate(*iterables)))
def test_reverse(self): """Test the `reverse` kwarg.""" iterables = [range(4, 0, -1), range(7, 0, -1), range(3, 6, -1)] self.assertEqual( sorted(reduce(list.__add__, [list(it) for it in iterables]), reverse=True), list(collate(*iterables, reverse=True)))
def test_one(self): """Work when only 1 iterable is passed.""" self.assertEqual([0, 1], list(collate(range(2))))
def test_empty(self): """Be nice if passed an empty list of iterables.""" self.assertEqual([], list(collate()))
def test_one(self): """Work when only 1 iterable is passed.""" self.assertEqual([0, 1], list(collate(range(2))))
def test_empty(self): """Be nice if passed an empty list of iterables.""" self.assertEqual([], list(collate()))