Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

enhance extracting() with filter and sort #71

Copy link
Copy link
@saturnboy

Description

@saturnboy
Issue body actions

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'])
Reactions are currently unavailable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.