diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2020-11-25 01:22:32 +0100 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2020-11-25 01:22:32 +0100 |
commit | 6bf0cb8a908122eed9cccd7f9fae35377a692c1d (patch) | |
tree | 587b5c4e9c02fbdceb86001bd3bfd269a372cd1b /tests | |
parent | 17582f0b1d5e6a33ec353f3ff63f37f0a2764c0c (diff) | |
download | fuzzycat-6bf0cb8a908122eed9cccd7f9fae35377a692c1d.tar.gz fuzzycat-6bf0cb8a908122eed9cccd7f9fae35377a692c1d.zip |
extend test coverage
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cluster.py | 86 | ||||
-rw-r--r-- | tests/test_utils.py | 23 |
2 files changed, 108 insertions, 1 deletions
diff --git a/tests/test_cluster.py b/tests/test_cluster.py index f2ae4a4..e5944af 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -1,3 +1,5 @@ +import json +import io import collections import os import tempfile @@ -5,7 +7,7 @@ import tempfile import pytest from fuzzycat.cluster import (release_key_title, release_key_title_normalized, - release_key_title_nysiis) + release_key_title_nysiis, Cluster) Case = collections.namedtuple("Case", 'input output') @@ -103,3 +105,85 @@ def test_release_key_title_nysiis(): for case in cases: assert case.output == release_key_title_nysiis(case.input), 'failed case {}'.format( case.input) + + +def test_cluster(): + sio = io.StringIO() + cluster = Cluster([ + json.dumps(line) for line in [ + { + "title": "hello world", + "ident": 1 + }, + { + "title": "hello world!", + "ident": 2 + }, + ] + ], + release_key_title_normalized, + output=sio) + stats = cluster.run() + assert stats == { + "key_fail": 0, + "key_ok": 2, + "key_empty": 0, + "key_denylist": 0, + "num_clusters": 1 + } + assert json.loads(sio.getvalue()) == { + "k": "helloworld", + "v": [{ + "title": "hello world!", + "ident": 2 + }, { + "title": "hello world", + "ident": 1 + }] + } + + sio = io.StringIO() + cluster = Cluster([ + json.dumps(line) for line in [ + { + "title": "hello world", + "ident": 1 + }, + { + "title": "hello world!", + "ident": 2 + }, + { + "title": "other", + "ident": 3 + }, + ] + ], + release_key_title_normalized, + output=sio) + stats = cluster.run() + assert stats == { + "key_fail": 0, + "key_ok": 3, + "key_empty": 0, + "key_denylist": 0, + "num_clusters": 2 + } + assert [json.loads(line) for line in sio.getvalue().split("\n") if line] == [{ + "k": + "helloworld", + "v": [{ + "title": "hello world!", + "ident": 2 + }, { + "title": "hello world", + "ident": 1 + }] + }, { + 'k': + 'other', + 'v': [{ + 'ident': 3, + 'title': 'other' + }] + }] diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..d0e5d48 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,23 @@ +import pytest +from fuzzycat.utils import slugify_string, cut + + +def test_slugify_string(): + assert slugify_string("") == "" + assert slugify_string("X") == "x" + assert slugify_string("Xx") == "xx" + assert slugify_string("Xx x") == "xx x" + assert slugify_string("Xx x x") == "xx x x" + assert slugify_string("Xx?x x") == "xxx x" + assert slugify_string("Xx? ?x x") == "xx x x" + assert slugify_string("Xx?_?x--x") == "xxxx" + assert slugify_string("=?++*") == "" + + +def test_cut(): + assert cut()("a b") == "a" + assert cut(1)("a b") == "b" + assert cut(2, sep=',')("a,b,c") == "c" + assert cut(3, sep=',')("a,b,c") == "" + with pytest.raises(ValueError): + cut(3, sep=',', ignore_missing_column=False)("a,b,c") == "" |