def test_filter_annotations_multiple_sort_reverse_last( mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 3, (sentinel.annotation3, 'foo'): 3, (sentinel.annotation0, 'bar'): 4, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, (sentinel.annotation3, 'bar'): 4, (sentinel.annotation0, 'baz'): 2, (sentinel.annotation1, 'baz'): 0, (sentinel.annotation2, 'baz'): 1, (sentinel.annotation3, 'baz'): 3, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field assert filter_annotations( [ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, sentinel.annotation3, ], filter_fields={ 'foo': 3, 'bar': 4 }, sort_field='baz', sort_reverse=True, action_if_multiple='last') == [sentinel.annotation2]
def test_filter_annotations_multiple_sort_reverse_last( mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 3, (sentinel.annotation3, 'foo'): 3, (sentinel.annotation0, 'bar'): 4, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, (sentinel.annotation3, 'bar'): 4, (sentinel.annotation0, 'baz'): 2, (sentinel.annotation1, 'baz'): 0, (sentinel.annotation2, 'baz'): 1, (sentinel.annotation3, 'baz'): 3, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field assert filter_annotations( [ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, sentinel.annotation3, ], filter_fields={'foo': 3, 'bar': 4}, sort_field='baz', sort_reverse=True, action_if_multiple='last' ) == [sentinel.annotation2]
def test_filter_annotations_zero_raise_with_multiple( mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 3, (sentinel.annotation0, 'bar'): 4, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field assert filter_annotations([ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ], filter_fields={ 'foo': 3, 'bar': 4 }, action_if_zero='raise') == [ sentinel.annotation0, sentinel.annotation2 ]
def test_filter_annotations_multiple_reverse(mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 3, (sentinel.annotation3, 'foo'): 3, (sentinel.annotation0, 'bar'): 4, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, (sentinel.annotation3, 'bar'): 4, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field assert filter_annotations([ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, sentinel.annotation3, ], filter_fields={ 'foo': 3, 'bar': 4 }, sort_reverse=True) == [ sentinel.annotation3, sentinel.annotation2, sentinel.annotation0 ]
def test_filter_annotations_noop(): assert filter_annotations([ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ]) == [ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ]
def test_filter_annotations_noop(): assert filter_annotations([ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ]) == [ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ]
def test_filter_annotations_zero_raise(mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 4, (sentinel.annotation0, 'bar'): 3, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field with raises(ZeroAnnotationsError): filter_annotations( [ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ], filter_fields={'foo': 3, 'bar': 4}, action_if_zero='raise' )
def test_filter_annotations_zero_raise(mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 4, (sentinel.annotation0, 'bar'): 3, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field with raises(ZeroAnnotationsError): filter_annotations([ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ], filter_fields={ 'foo': 3, 'bar': 4 }, action_if_zero='raise')
def test_filter_annotations_multiple_raise_with_one(mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 4, (sentinel.annotation0, 'bar'): 3, (sentinel.annotation1, 'bar'): 4, (sentinel.annotation2, 'bar'): 4, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field assert filter_annotations( [ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ], filter_fields={'foo': 3, 'bar': 4} ) == [sentinel.annotation1]
def test_filter_annotations_zero(mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 4, (sentinel.annotation0, 'bar'): 3, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field assert filter_annotations([ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ], filter_fields={ 'foo': 3, 'bar': 4 }) == []
def test_filter_annotations_multiple_last( mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 3, (sentinel.annotation0, 'bar'): 4, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field assert filter_annotations( [ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, ], filter_fields={'foo': 3, 'bar': 4}, action_if_multiple='last' ) == [sentinel.annotation2]
def test_filter_annotations_multiple_reverse(mock_get_annotation_field): def _mock_get_annotation_field(annotation, field): return { (sentinel.annotation0, 'foo'): 3, (sentinel.annotation1, 'foo'): 3, (sentinel.annotation2, 'foo'): 3, (sentinel.annotation3, 'foo'): 3, (sentinel.annotation0, 'bar'): 4, (sentinel.annotation1, 'bar'): 3, (sentinel.annotation2, 'bar'): 4, (sentinel.annotation3, 'bar'): 4, }[(annotation, field)] mock_get_annotation_field.side_effect = _mock_get_annotation_field assert filter_annotations( [ sentinel.annotation0, sentinel.annotation1, sentinel.annotation2, sentinel.annotation3, ], filter_fields={'foo': 3, 'bar': 4}, sort_reverse=True ) == [sentinel.annotation3, sentinel.annotation2, sentinel.annotation0]