

def test_sortBy(self):
    res = _([{
        'age': '59',
        'name': 'foo',
    }, {
        'age': '39',
        'name': 'bar',
    }, {
        'age': '49',
        'name': 'baz',
    }]).sortBy('age')
    self.assertEqual([{
        'age': '39',
        'name': 'bar',
    }, {
        'age': '49',
        'name': 'baz',
    }, {
        'age': '59',
        'name': 'foo',
    }], res, 'filter by key did not work')
    res = _([{
        'age': '59',
        'name': 'foo',
    }, {
        'age': '39',
        'name': 'bar',
    }, {
        'age': '49',
        'name': 'baz',
    }]).sortBy((lambda x: x['age']))
    self.assertEqual([{
        'age': '39',
        'name': 'bar',
    }, {
        'age': '49',
        'name': 'baz',
    }, {
        'age': '59',
        'name': 'foo',
    }], res, 'filter by lambda did not work')
    res = _([50, 78, 30, 15, 90]).sortBy()
    self.assertEqual([15, 30, 50, 78, 90], res, 'filter list did not work')

dataset/ETHPy150Open serkanyersen/underscore.py/tests/test_collections.py TestCollections.test_sortBy/original