aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2020-12-14 20:31:54 +0100
committerMartin Czygan <martin.czygan@gmail.com>2020-12-14 20:31:54 +0100
commit54a5fc7f3fa6893a83143a1755aa6b4497efa33c (patch)
treecdce9081d3e4410e757c7a95d57bd8509e7cf57c /tests
parentd3891ff1242627464e7e0eee68ab07a61c0678d4 (diff)
downloadfuzzycat-54a5fc7f3fa6893a83143a1755aa6b4497efa33c.tar.gz
fuzzycat-54a5fc7f3fa6893a83143a1755aa6b4497efa33c.zip
verify: move out some code to utils
Diffstat (limited to 'tests')
-rw-r--r--tests/test_utils.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index a2033ac..38d50a7 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,7 +1,7 @@
import pytest
from fuzzycat.utils import (author_similarity_score, cut, jaccard, nwise, slugify_string,
- token_n_grams, tokenize_string)
+ token_n_grams, tokenize_string, parse_page_string, dict_key_exists)
def test_slugify_string():
@@ -63,3 +63,22 @@ def test_nwise():
assert list(nwise("1234")) == [("1", "2"), ("3", "4")]
assert list(nwise("1234", n=1)) == [("1", ), ("2", ), ("3", ), ("4", )]
assert list(nwise([1, 2, 3, 4, 5], n=3)) == [(1, 2, 3), (4, 5)]
+
+def test_dict_key_exists():
+ assert dict_key_exists({}, "") is False
+ assert dict_key_exists({"a": "a"}, "a") == True
+ assert dict_key_exists({"a": "a"}, "b") == False
+ assert dict_key_exists({"a": {"b": "c"}}, "a.b") == True
+ assert dict_key_exists({"a": {"b": None}}, "a.b") == True
+ assert dict_key_exists({"a": {"b": "c"}}, "a.b.c") == False
+
+def test_page_page_string():
+ reject = ("", "123-2", "123-120", "123a-124", "-2-1")
+ for s in reject:
+ with pytest.raises(ValueError):
+ assert parse_page_string(s)
+ assert parse_page_string("123") == (123, 123, 1)
+ assert parse_page_string("123-5") == (123, 125, 3)
+ assert parse_page_string("123-125") == (123, 125, 3)
+ assert parse_page_string("123-124a") == (123, 124, 2)
+ assert parse_page_string("1-1000") == (1, 1000, 1000)