From 7a701662c17467a9eb3402cf8641a7dd15f5ad1c Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 13 Apr 2021 17:13:55 -0700 Subject: make fmt --- fuzzycat/utils.py | 2 ++ tests/test_utils.py | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 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_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 - -- cgit v1.2.3