This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from nolar/multi-callbacks
Provide helpers to combine few callbacks for body-/meta-filters
- Loading branch information
Showing
4 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import kopf | ||
|
||
|
||
def _never1(*_, **__): | ||
return False | ||
|
||
|
||
def _never2(*_, **__): | ||
return False | ||
|
||
|
||
def _always1(*_, **__): | ||
return True | ||
|
||
|
||
def _always2(*_, **__): | ||
return True | ||
|
||
|
||
def test_notfn_when_true(): | ||
combined = kopf.not_(_always1) | ||
result = combined() | ||
assert result is False | ||
|
||
|
||
def test_notfn_when_false(): | ||
combined = kopf.not_(_never1) | ||
result = combined() | ||
assert result is True | ||
|
||
|
||
def test_allfn_when_all_are_true(): | ||
combined = kopf.all_([_always1, _always2]) | ||
result = combined() | ||
assert result is True | ||
|
||
|
||
def test_allfn_when_one_is_false(): | ||
combined = kopf.all_([_always1, _never1]) | ||
result = combined() | ||
assert result is False | ||
|
||
|
||
def test_allfn_when_all_are_false(): | ||
combined = kopf.all_([_never1, _never2]) | ||
result = combined() | ||
assert result is False | ||
|
||
|
||
def test_allfn_when_no_functions(): | ||
combined = kopf.all_([]) | ||
result = combined() | ||
assert result is True | ||
|
||
|
||
def test_anyfn_when_all_are_true(): | ||
combined = kopf.any_([_always1, _always2]) | ||
result = combined() | ||
assert result is True | ||
|
||
|
||
def test_anyfn_when_one_is_false(): | ||
combined = kopf.any_([_always1, _never1]) | ||
result = combined() | ||
assert result is True | ||
|
||
|
||
def test_anyfn_when_all_are_false(): | ||
combined = kopf.any_([_never1, _never2]) | ||
result = combined() | ||
assert result is False | ||
|
||
|
||
def test_anyfn_when_no_functions(): | ||
combined = kopf.any_([]) | ||
result = combined() | ||
assert result is False | ||
|
||
|
||
def test_nonefn_when_all_are_true(): | ||
combined = kopf.none_([_always1, _always2]) | ||
result = combined() | ||
assert result is False | ||
|
||
|
||
def test_nonefn_when_one_is_false(): | ||
combined = kopf.none_([_always1, _never1]) | ||
result = combined() | ||
assert result is False | ||
|
||
|
||
def test_nonefn_when_all_are_false(): | ||
combined = kopf.none_([_never1, _never2]) | ||
result = combined() | ||
assert result is True | ||
|
||
|
||
def test_nonefn_when_no_functions(): | ||
combined = kopf.none_([]) | ||
result = combined() | ||
assert result is True |