diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-04-14 23:00:33 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-04-14 23:00:33 +0200 |
commit | 1ffae095fdcbe78cf0c3eae21c9725ef9b1aacc1 (patch) | |
tree | 2fe6ca9da3c9c66242930cb1cb40371259a52528 | |
parent | 1a096a775e13b8b2c6f90d706a5805cb047a6372 (diff) | |
download | fuzzycat-1ffae095fdcbe78cf0c3eae21c9725ef9b1aacc1.tar.gz fuzzycat-1ffae095fdcbe78cf0c3eae21c9725ef9b1aacc1.zip |
fix imports and formatting
-rw-r--r-- | fuzzycat/utils.py | 2 | ||||
-rw-r--r-- | tests/test_matching.py | 17 | ||||
-rw-r--r-- | tests/test_utils.py | 17 |
3 files changed, 28 insertions, 8 deletions
diff --git a/fuzzycat/utils.py b/fuzzycat/utils.py index bd7ceed..8e1ffb0 100644 --- a/fuzzycat/utils.py +++ b/fuzzycat/utils.py @@ -19,6 +19,7 @@ CHEM_FORMULA = re.compile(r"([A-Z]{1,2}[0-9]{1,2})+") ParsedPages = collections.namedtuple("ParsedPages", "start end count") + def es_compat_hits_total(resp): """ Given a search response dict, support ES6 and ES7 style total value. See: @@ -32,6 +33,7 @@ def es_compat_hits_total(resp): except TypeError: return resp["hits"]["total"] + def parse_page_string(s): """ Parse typical page strings, e.g. 150-180. diff --git a/tests/test_matching.py b/tests/test_matching.py index 8d70d15..1702792 100644 --- a/tests/test_matching.py +++ b/tests/test_matching.py @@ -1,15 +1,22 @@ -from fuzzycat.matching import anything_to_entity, match_release_fuzzy -from fuzzycat.entities import entity_from_dict -from fatcat_openapi_client import ReleaseEntity -import pytest -import elasticsearch import logging +import warnings + +import elasticsearch +import pytest +import requests from dynaconf import Dynaconf +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 ... logger = logging.getLogger('test_matching') logger.setLevel(logging.DEBUG) settings = Dynaconf(envvar_prefix="FUZZYCAT") +# ad-hoc override search server with: FUZZYCAT_FATCAT_SEARCH_URL=localhost:9200 pytest ... FATCAT_SEARCH_URL = settings.get("FATCAT_SEARCH_URL", "https://search.fatcat.wiki:443") diff --git a/tests/test_utils.py b/tests/test_utils.py index 24be9d1..381c44e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -99,11 +99,22 @@ def test_zstdlines(): with open(fn) as f: assert [s.strip() for s in f.readlines()] == list(zstdlines(zfn)) + def test_es_compat_hits_total(): cases = ( - ({"hits": {"total": 6}}, 6), - ({"hits": {"total": {"value": 7, "relation": "eq"}}}, 7), + ({ + "hits": { + "total": 6 + } + }, 6), + ({ + "hits": { + "total": { + "value": 7, + "relation": "eq" + } + } + }, 7), ) for r, expected in cases: assert es_compat_hits_total(r) == expected - |