mirror of
https://github.com/facefusion/facefusion.git
synced 2026-04-24 10:26:05 +02:00
Add testing for audio handlers
This commit is contained in:
+22
-22
@@ -62,6 +62,12 @@ def is_directory(directory_path : str) -> bool:
|
||||
return bool(directory_path and os.path.isdir(directory_path))
|
||||
|
||||
|
||||
def is_audio(audio_path : str) -> bool:
|
||||
if is_file(audio_path):
|
||||
return filetype.helpers.is_audio(audio_path)
|
||||
return False
|
||||
|
||||
|
||||
def is_image(image_path : str) -> bool:
|
||||
if is_file(image_path):
|
||||
return filetype.helpers.is_image(image_path)
|
||||
@@ -80,21 +86,13 @@ def is_video(video_path : str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def is_audio(audio_path : str) -> bool:
|
||||
if is_file(audio_path):
|
||||
return filetype.helpers.is_audio(audio_path)
|
||||
return False
|
||||
|
||||
|
||||
def resolve_relative_path(path : str) -> str:
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), path))
|
||||
|
||||
|
||||
def list_directory(directory_path : str) -> Optional[List[str]]:
|
||||
if is_directory(directory_path):
|
||||
files = os.listdir(directory_path)
|
||||
return [ Path(file).stem for file in files if not Path(file).stem.startswith(('.', '__')) ]
|
||||
return None
|
||||
def filter_audio_paths(paths : List[str]) -> List[Optional[str]]:
|
||||
audio_paths = []
|
||||
if paths:
|
||||
for path in paths:
|
||||
if is_audio(path):
|
||||
audio_paths.append(path)
|
||||
return audio_paths
|
||||
|
||||
|
||||
def filter_image_paths(paths : List[str]) -> List[Optional[str]]:
|
||||
@@ -106,10 +104,12 @@ def filter_image_paths(paths : List[str]) -> List[Optional[str]]:
|
||||
return image_paths
|
||||
|
||||
|
||||
def filter_audio_paths(paths : List[str]) -> List[Optional[str]]:
|
||||
audio_paths = []
|
||||
if paths:
|
||||
for path in paths:
|
||||
if is_audio(path):
|
||||
audio_paths.append(path)
|
||||
return audio_paths
|
||||
def resolve_relative_path(path : str) -> str:
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), path))
|
||||
|
||||
|
||||
def list_directory(directory_path : str) -> Optional[List[str]]:
|
||||
if is_directory(directory_path):
|
||||
files = os.listdir(directory_path)
|
||||
return [ Path(file).stem for file in files if not Path(file).stem.startswith(('.', '__')) ]
|
||||
return None
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import pytest
|
||||
|
||||
from facefusion.download import conditional_download
|
||||
from facefusion.filesystem import is_file, is_directory, is_image, are_images, is_video, list_directory
|
||||
from facefusion.filesystem import is_file, is_directory, is_audio, is_image, are_images, is_video, filter_audio_paths, filter_image_paths, list_directory
|
||||
|
||||
|
||||
@pytest.fixture(scope = 'module', autouse = True)
|
||||
def before_all() -> None:
|
||||
conditional_download('.assets/examples',
|
||||
[
|
||||
'https://github.com/facefusion/facefusion-assets/releases/download/examples/source.jpg'
|
||||
'https://github.com/facefusion/facefusion-assets/releases/download/examples/source.jpg',
|
||||
'https://github.com/facefusion/facefusion-assets/releases/download/examples/source.mp3',
|
||||
'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-240p.mp4'
|
||||
])
|
||||
|
||||
|
||||
@@ -24,6 +26,12 @@ def test_is_directory() -> None:
|
||||
assert is_directory('invalid') is False
|
||||
|
||||
|
||||
def test_is_audio() -> None:
|
||||
assert is_audio('.assets/examples/source.mp3') is True
|
||||
assert is_audio('.assets/examples/source.jpg') is False
|
||||
assert is_audio('invalid') is False
|
||||
|
||||
|
||||
def test_is_image() -> None:
|
||||
assert is_image('.assets/examples/source.jpg') is True
|
||||
assert is_image('.assets/examples/target-240p.mp4') is False
|
||||
@@ -42,6 +50,18 @@ def test_is_video() -> None:
|
||||
assert is_video('invalid') is False
|
||||
|
||||
|
||||
def test_filter_audio_paths() -> None:
|
||||
assert filter_audio_paths([ '.assets/examples/source.jpg', '.assets/examples/source.mp3' ]) == [ '.assets/examples/source.mp3' ]
|
||||
assert filter_audio_paths([ '.assets/examples/source.jpg', '.assets/examples/source.jpg' ]) == []
|
||||
assert filter_audio_paths([ 'invalid' ]) == []
|
||||
|
||||
|
||||
def test_filter_image_paths() -> None:
|
||||
assert filter_image_paths([ '.assets/examples/source.jpg', '.assets/examples/source.mp3' ]) == [ '.assets/examples/source.jpg' ]
|
||||
assert filter_image_paths([ '.assets/examples/source.mp3', '.assets/examples/source.mp3' ]) == []
|
||||
assert filter_audio_paths([ 'invalid' ]) == []
|
||||
|
||||
|
||||
def test_list_directory() -> None:
|
||||
assert list_directory('.assets/examples')
|
||||
assert list_directory('.assets/examples/source.jpg') is None
|
||||
|
||||
Reference in New Issue
Block a user