Skip to content

Commit

Permalink
fix path unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pudo committed Dec 4, 2023
1 parent efd77a9 commit 4543b54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
15 changes: 6 additions & 9 deletions tests/unit/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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():
Expand Down
5 changes: 4 additions & 1 deletion yente/data/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 4543b54

Please sign in to comment.