Skip to content

Commit

Permalink
Use ExceptionUpperBound from HDX Python Utilities
Browse files Browse the repository at this point in the history
Fix test for changes in HDX dataset
  • Loading branch information
Mike committed Jan 11, 2024
1 parent 07b40d2 commit c47d549
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ classifiers = [
requires-python = ">=3.8"

dependencies = [
"hdx-python-utilities>=3.6.2",
"hdx-python-utilities>=3.6.4",
"libhxl>=5.1",
"pyphonetics",
]
Expand Down
46 changes: 23 additions & 23 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#
annotated-types==0.6.0
# via pydantic
attrs==23.1.0
attrs==23.2.0
# via
# frictionless
# jsonlines
# jsonschema
certifi==2023.7.22
certifi==2023.11.17
# via requests
cfgv==3.4.0
# via pre-commit
Expand All @@ -23,31 +23,31 @@ click==8.1.7
# via typer
colorama==0.4.6
# via typer
coverage[toml]==7.3.2
coverage[toml]==7.4.0
# via pytest-cov
distlib==0.3.7
distlib==0.3.8
# via virtualenv
et-xmlfile==1.1.0
# via openpyxl
filelock==3.13.1
# via virtualenv
frictionless==5.16.0
# via hdx-python-utilities
hdx-python-utilities==3.6.2
hdx-python-utilities==3.6.4
# via hdx-python-country (pyproject.toml)
humanize==4.8.0
humanize==4.9.0
# via frictionless
identify==2.5.31
identify==2.5.33
# via pre-commit
idna==3.4
idna==3.6
# via requests
ijson==3.2.3
# via hdx-python-utilities
iniconfig==2.0.0
# via pytest
isodate==0.6.1
# via frictionless
jinja2==3.1.2
jinja2==3.1.3
# via frictionless
jsonlines==4.0.0
# via hdx-python-utilities
Expand All @@ -57,13 +57,13 @@ jsonschema==4.17.3
# via
# frictionless
# tableschema-to-template
libhxl==5.1
libhxl==5.2
# via hdx-python-country (pyproject.toml)
loguru==0.7.2
# via hdx-python-utilities
markdown-it-py==3.0.0
# via rich
marko==2.0.1
marko==2.0.2
# via frictionless
markupsafe==2.1.3
# via jinja2
Expand All @@ -77,27 +77,27 @@ packaging==23.2
# via pytest
petl==1.7.14
# via frictionless
platformdirs==3.11.0
platformdirs==4.1.0
# via virtualenv
pluggy==1.3.0
# via pytest
ply==3.11
# via
# jsonpath-ng
# libhxl
pre-commit==3.5.0
pre-commit==3.6.0
# via hdx-python-country (pyproject.toml)
pydantic==2.4.2
pydantic==2.5.3
# via frictionless
pydantic-core==2.10.1
pydantic-core==2.14.6
# via pydantic
pygments==2.16.1
pygments==2.17.2
# via rich
pyphonetics==0.5.3
# via hdx-python-country (pyproject.toml)
pyrsistent==0.20.0
# via jsonschema
pytest==7.4.3
pytest==7.4.4
# via
# hdx-python-country (pyproject.toml)
# pytest-cov
Expand Down Expand Up @@ -128,7 +128,7 @@ requests-file==1.5.1
# via hdx-python-utilities
rfc3986==2.0.0
# via frictionless
rich==13.6.0
rich==13.7.0
# via typer
ruamel-yaml==0.18.5
# via hdx-python-utilities
Expand All @@ -145,7 +145,7 @@ six==1.16.0
# requests-file
stringcase==1.2.0
# via frictionless
structlog==23.2.0
structlog==24.1.0
# via libhxl
tableschema-to-template==0.0.13
# via hdx-python-utilities
Expand All @@ -155,7 +155,7 @@ text-unidecode==1.3
# via python-slugify
typer[all]==0.9.0
# via frictionless
typing-extensions==4.8.0
typing-extensions==4.9.0
# via
# frictionless
# pydantic
Expand All @@ -165,15 +165,15 @@ unidecode==1.3.7
# via
# libhxl
# pyphonetics
urllib3==2.0.7
urllib3==2.1.0
# via
# libhxl
# requests
validators==0.22.0
# via frictionless
virtualenv==20.24.6
virtualenv==20.25.0
# via pre-commit
wheel==0.41.3
wheel==0.42.0
# via libhxl
xlrd==2.0.1
# via hdx-python-utilities
Expand Down
6 changes: 2 additions & 4 deletions src/hdx/location/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import logging
import re
from string import punctuation
from typing import Dict, List, Optional, Tuple, TypeVar, Union
from typing import Dict, List, Optional, Tuple, Union

import hxl
from hxl import InputOptions

from hdx.utilities.path import script_dir_plus_file
from hdx.utilities.text import get_words_in_sentence

ExceptionUpperBound = TypeVar("T", bound="Exception")

from hdx.utilities.typehint import ExceptionUpperBound

logger = logging.getLogger(__name__)

Expand Down
18 changes: 11 additions & 7 deletions tests/hdx/location/test_adminlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def url(self):

@pytest.fixture(scope="function")
def formats_url(self):
return "https://raw.githubusercontent.com/OCHA-DAP/hdx-python-country/pcode_formats/tests/fixtures/global_pcode_lengths.csv"
return "https://raw.githubusercontent.com/OCHA-DAP/hdx-python-country/main/tests/fixtures/global_pcode_lengths.csv"

def test_adminlevel(self, config):
adminone = AdminLevel(config)
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_adminlevel_with_url(self, config, url):
adminone = AdminLevel(config)
adminone.setup_from_url()
assert adminone.get_admin_level("YEM") == 1
assert len(adminone.get_pcode_list()) == 2552
assert len(adminone.get_pcode_list()) == 2553
assert adminone.get_pcode_length("YEM") == 4
assert adminone.get_pcode("YEM", "YE30", logname="test") == (
"YE30",
Expand All @@ -216,18 +216,22 @@ def test_adminlevel_with_url(self, config, url):
True,
)
assert adminone.get_pcode("NER", "NER004", logname="test") == (
"NER004",
"NE004",
True,
)
assert adminone.get_pcode("NER", "NE04", logname="test") == (
"NER004",
"NE004",
True,
)
assert adminone.get_pcode("NER", "NE004", logname="test") == (
"NER004",
"NE004",
True,
)
assert adminone.get_pcode("ABC", "NE004", logname="test") == (
"NE004",
True,
)
assert adminone.get_pcode("ABC", "NER004", logname="test") == (
None,
True,
)
Expand All @@ -236,7 +240,7 @@ def test_adminlevel_with_url(self, config, url):
False,
)
config["countries_fuzzy_try"].append("ABC")
assert adminone.get_pcode("ABC", "NE004", logname="test") == (
assert adminone.get_pcode("ABC", "NER004", logname="test") == (
None,
True,
)
Expand Down Expand Up @@ -284,7 +288,7 @@ def test_adminlevel_with_url(self, config, url):
)
output = adminone.output_matches()
assert output == [
"test - NER: Matching (pcode length conversion) NER004 to Maradi on map",
"test - NER: Matching (pcode length conversion) NE004 to Maradi on map",
"test - NGA: Matching (pcode length conversion) NG015 to Federal Capital Territory on map",
"test - UKR: Matching (substring) Chernihiv Oblast to Chernihivska on map",
"test - YEM: Matching (substring) Ad Dal to Ad Dali' on map",
Expand Down

0 comments on commit c47d549

Please sign in to comment.