diff options
author | Martin Czygan <martin@archive.org> | 2021-09-21 18:34:31 +0000 |
---|---|---|
committer | Martin Czygan <martin@archive.org> | 2021-09-21 18:34:31 +0000 |
commit | a37404f30b2c1afa0b46ee30a5b59d7312c119d0 (patch) | |
tree | 8f38d396909049971559a5ab574561960d6d5f22 /tests | |
parent | c587a084defe54103aa147b7ab91542a11a548b1 (diff) | |
parent | 5fa61d89320af880d5bf6b3231f6478887cfb6a6 (diff) | |
download | fuzzycat-a37404f30b2c1afa0b46ee30a5b59d7312c119d0.tar.gz fuzzycat-a37404f30b2c1afa0b46ee30a5b59d7312c119d0.zip |
Merge branch 'wip-martin-review-cleanup' into 'master'
review notes and some cleanup
See merge request webgroup/fuzzycat!7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_matching.py | 45 | ||||
-rw-r--r-- | tests/test_utils.py | 1 |
2 files changed, 37 insertions, 9 deletions
diff --git a/tests/test_matching.py b/tests/test_matching.py index 7ab7b11..90d1fee 100644 --- a/tests/test_matching.py +++ b/tests/test_matching.py @@ -9,7 +9,8 @@ from fatcat_openapi_client import ReleaseEntity from fuzzycat.entities import entity_from_dict from fuzzycat.matching import anything_to_entity, match_release_fuzzy -warnings.filterwarnings("ignore") # InsecureRequestWarning: Unverified HTTPS request is being made to host ... +warnings.filterwarnings( + "ignore") # InsecureRequestWarning: Unverified HTTPS request is being made to host ... from fuzzycat.matching import anything_to_entity, match_release_fuzzy from fuzzycat.config import settings @@ -28,6 +29,7 @@ FATCAT_SEARCH_URL = settings.get("FATCAT_SEARCH_URL", "https://search.fatcat.wik def is_not_reachable(url, timeout=3): return not is_reachable(url) + def is_reachable(url, timeout=3): """ Return true, if URL is reachable and returns HTTP 200. @@ -37,14 +39,21 @@ def is_reachable(url, timeout=3): except Exception: return False + @pytest.fixture def es_client(): return elasticsearch.Elasticsearch([FATCAT_SEARCH_URL]) -@pytest.mark.skipif(is_not_reachable(FATCAT_SEARCH_URL), - reason="{} not reachable, use e.g. FUZZYCAT_FATCAT_SEARCH_URL=localhost:9200 to override".format(FATCAT_SEARCH_URL)) +@pytest.mark.skipif( + is_not_reachable(FATCAT_SEARCH_URL), + reason="{} not reachable, use e.g. FUZZYCAT_FATCAT_SEARCH_URL=localhost:9200 to override". + format(FATCAT_SEARCH_URL)) def test_match_release_fuzzy(es_client, caplog): + """ + This test is tied to the current index contents, so if that changes, this + test may fail as well. + """ cases = ( ("wtv64ahbdzgwnan7rllwr3nurm", 1), ("eqcgtpav3na5jh56o5vjsvb4ei", 1), @@ -63,17 +72,35 @@ def test_match_release_fuzzy(es_client, caplog): "ext_ids": {} }, 5), ({ - "title": "The Future of Digital Scholarship", - "contribs": [{ - "raw_name": "Costantino Thanos" - }], + "title": "unlikelytitle", + "ext_ids": {} + }, 0), + ({ + "title": "Imminent dystopia", + "ext_ids": {} + }, 2), + ({ + "title": "", + "contribs": [{"raw_name": "Aristoteles"}], "ext_ids": {} }, 5), + # ({ + # "title": "Letter", + # "contribs": [{"raw_name": "Claudel"}], + # "ext_ids": {} + # }, 1), + # ({ + # "title": "The Future of Digital Scholarship", + # "contribs": [{ + # "raw_name": "Costantino Thanos" + # }], + # "ext_ids": {} + # }, 5), ) for i, (doc, count) in enumerate(cases): entity = entity_from_dict(doc, ReleaseEntity) result = match_release_fuzzy(entity, es=es_client) with caplog.at_level(logging.INFO): - logging.info("[{}] given {}, found {}, {}".format(i, entity.title, len(result), + logging.info("[{}] given title '{}', found {}, {}".format(i, entity.title, len(result), [v.title for v in result])) - assert len(result) == count + assert len(result) == count, doc diff --git a/tests/test_utils.py b/tests/test_utils.py index 21b85a4..957203f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -124,6 +124,7 @@ def test_es_compat_hits_total(): for r, expected in cases: assert es_compat_hits_total(r) == expected + def test_clean_doi(): assert clean_doi(None) == None assert clean_doi("blah") == None |