-
Notifications
You must be signed in to change notification settings - Fork 76
Closed
Description
Currently, extracting() is used to reduce a list of objects or list of dicts into a simple list of values, like this:
people = [
{ 'first_name': 'Fred', 'age': 36, 'active': True },
{ 'first_name': 'Bob', 'age': 40, 'active': False }
];
assert_that(people).extracting('first_name').contains('Fred','Bob')Enhance extracting() with filter, like this:
assert_that(people).extracting('first_name', filter='active').contains('Fred')
assert_that(people).extracting('first_name', filter={'active': False}).contains('Bob')
assert_that(people).extracting('first_name', filter={'age': 40, 'active': False}).contains('Bob')
assert_that(people).extracting('first_name', filter=lambda x: x['age'] < 40).contains('Fred')Enhance extracting() with sort, like this:
assert_that(people).extracting('first_name', sort='age').is_equal_to(['Fred', 'Bob'])
assert_that(people).extracting('first_name', sort=['age','first_name']).is_equal_to(['Fred', 'Bob'])
assert_that(people).extracting('first_name', sort=lambda x: -x['age']).is_equal_to(['Bob', 'Fred'])