From 1a919fe2e12df6b587191a1985795e7c8a93bf9c Mon Sep 17 00:00:00 2001 From: Adam Jorgensen Date: Sat, 9 Jan 2016 15:55:18 +0200 Subject: [PATCH] #5: Began adding tests for the item extractor. --- rightshift/tests/test_extractors.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 rightshift/tests/test_extractors.py diff --git a/rightshift/tests/test_extractors.py b/rightshift/tests/test_extractors.py new file mode 100644 index 0000000..d5a1355 --- /dev/null +++ b/rightshift/tests/test_extractors.py @@ -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) + +