mirror of
https://github.com/macaodha/batdetect2.git
synced 2026-05-22 22:32:18 +02:00
fix: normalize shared relative output paths
This commit is contained in:
parent
c4f759e9a3
commit
d35866439b
@ -27,6 +27,10 @@ def make_path_relative(path: PathLike, audio_dir: PathLike) -> Path:
|
|||||||
|
|
||||||
return path.relative_to(audio_dir)
|
return path.relative_to(audio_dir)
|
||||||
|
|
||||||
|
audio_parts = audio_dir.parts
|
||||||
|
if audio_parts and path.parts[: len(audio_parts)] == audio_parts:
|
||||||
|
return Path(*path.parts[len(audio_parts) :])
|
||||||
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
tests/test_outputs/test_base.py
Normal file
21
tests/test_outputs/test_base.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from batdetect2.outputs.formats.base import make_path_relative
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_path_relative_strips_shared_relative_prefix() -> None:
|
||||||
|
audio_dir = Path("example_data/audio")
|
||||||
|
path = Path("example_data/audio/subdir/clip.wav")
|
||||||
|
|
||||||
|
relative = make_path_relative(path, audio_dir)
|
||||||
|
|
||||||
|
assert relative == Path("subdir/clip.wav")
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_path_relative_returns_dot_for_matching_relative_dir() -> None:
|
||||||
|
audio_dir = Path("example_data/audio")
|
||||||
|
path = Path("example_data/audio")
|
||||||
|
|
||||||
|
relative = make_path_relative(path, audio_dir)
|
||||||
|
|
||||||
|
assert relative == Path(".")
|
||||||
Loading…
Reference in New Issue
Block a user