-
Notifications
You must be signed in to change notification settings - Fork 79
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 #423 from flairNLP/reqork-extraction-filter-for-bo…
…olean-values Rework `ExtractionFilter` to adept to boolean values
- Loading branch information
Showing
4 changed files
with
79 additions
and
19 deletions.
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,41 @@ | ||
from fundus import Requires | ||
from fundus.scraping.filter import RequiresAll | ||
|
||
|
||
class TestExtractionFilter: | ||
def test_requires(self): | ||
extraction = {"a": "Some Stuff", "b": [], "c": True} | ||
|
||
assert not Requires("a")(extraction) | ||
|
||
assert (result := Requires("a", "b")(extraction)) | ||
|
||
assert result.missing_attributes == ("b",) | ||
|
||
assert not Requires("c")(extraction) | ||
|
||
extraction = {"a": "Some Stuff", "b": [], "c": False} | ||
|
||
assert (result := Requires("a", "b", "c")(extraction)) | ||
|
||
assert sorted(result.missing_attributes) == sorted(("b", "c")) | ||
|
||
assert not Requires("c", eval_booleans=False)(extraction) | ||
|
||
def test_requires_all(self): | ||
extraction = {"a": "Some Stuff", "b": [], "c": False} | ||
|
||
assert (result := RequiresAll()(extraction)) | ||
assert result.missing_attributes == ("b",) | ||
|
||
extraction = {"a": "Some Stuff", "c": False} | ||
assert not RequiresAll()(extraction) | ||
|
||
# test skip_boolean=False | ||
extraction = {"a": "Some Stuff", "b": [], "c": False} | ||
|
||
assert (result := RequiresAll(eval_booleans=True)(extraction)) | ||
assert sorted(result.missing_attributes) == sorted(("b", "c")) | ||
|
||
extraction = {"a": "Some Stuff", "c": True} | ||
assert not RequiresAll(eval_booleans=True)(extraction) |