-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5: Began adding tests for the item extractor.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from math import isnan | ||
|
||
from rightshift.extractors import item, attr, pattern_group | ||
from hypothesis import given, assume | ||
from hypothesis.strategies import text, integers, floats, lists, booleans, one_of | ||
from random import randint | ||
|
||
|
||
def __common_item_tests(data): | ||
assume(len(data) > 0) | ||
index = randint(0, len(data) - 1) | ||
if isinstance(data[index], float): | ||
assume(not isnan(data[index])) | ||
assert item[index](data) == data[index] | ||
|
||
|
||
@given(text()) | ||
def test_item_with_text(data): | ||
__common_item_tests(data) | ||
|
||
|
||
@given(lists(one_of(text(), integers(), floats(), booleans()))) | ||
def test_item_with_lists(data): | ||
__common_item_tests(data) | ||
|
||
|