diff --git a/tests/unit/test_data.py b/tests/unit/test_data.py index efdc19f4..75a59103 100644 --- a/tests/unit/test_data.py +++ b/tests/unit/test_data.py @@ -3,7 +3,7 @@ from yente.data import get_catalog from yente.data.loader import load_json_lines -from yente.data.util import resolve_url_type +from yente.data.util import get_url_local_path from yente.data.util import phonetic_names @@ -25,17 +25,14 @@ async def test_local_dataset(): assert len(lines) > 10, lines -def test_resolve_url_type(): - out = resolve_url_type("http://banana.com/bla.txt") - assert isinstance(out, str) - out = resolve_url_type(__file__) +def test_get_url_local_path(): + out = get_url_local_path("http://banana.com/bla.txt") + assert out is None + out = get_url_local_path(__file__) assert isinstance(out, Path) with pytest.raises(RuntimeError): - resolve_url_type("ftp://banana.com/bla.txt") - - with pytest.raises(RuntimeError): - resolve_url_type("/no/such/path.csv") + get_url_local_path("/no/such/path.csv") def test_phonetic_names(): diff --git a/yente/data/util.py b/yente/data/util.py index 906bfe95..d0db759e 100644 --- a/yente/data/util.py +++ b/yente/data/util.py @@ -118,7 +118,10 @@ def get_url_local_path(url: str) -> Optional[Path]: parsed = urlparse(url) scheme = parsed.scheme.lower() if scheme in ("file", "") and parsed.path != "": - return Path(parsed.path).resolve() + path = Path(parsed.path).resolve() + if not path.exists(): + raise RuntimeError("File not found: %s" % path) + return path return None