mirror of
https://github.com/facefusion/facefusion.git
synced 2026-11-12 05:19:57 +01:00
Claude-Session: https://claude.ai/code/session_01Cd6JuxiVXYNPCDii9go2eh Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
3.4 KiB
Python
106 lines
3.4 KiB
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from facefusion import process_manager
|
|
from facefusion.download import conditional_download_files, conditional_validate_files, get_static_download_size, ping_static_url, resolve_download_url_by_provider, validate_file
|
|
from facefusion.types import DownloadSet
|
|
|
|
|
|
@pytest.fixture(scope = 'module', autouse = True)
|
|
def before_all() -> None:
|
|
process_manager.clear()
|
|
|
|
|
|
def test_get_static_download_size() -> None:
|
|
assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.onnx') == 232475
|
|
assert get_static_download_size('https://huggingface.co/facefusion/models-3.4.0/resolve/main/yunet_2023_mar.onnx') == 232475
|
|
assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/invalid.onnx') == 0
|
|
assert get_static_download_size('invalid') == 0
|
|
|
|
|
|
def test_static_ping_url() -> None:
|
|
assert ping_static_url('https://github.com') is True
|
|
assert ping_static_url('https://huggingface.co') is True
|
|
assert ping_static_url('invalid') is False
|
|
|
|
|
|
def test_conditional_download_files() -> None:
|
|
hash_set : DownloadSet =\
|
|
{
|
|
'yunet':
|
|
{
|
|
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.hash',
|
|
'path': '.assets/models/yunet_2023_mar.hash'
|
|
}
|
|
}
|
|
source_set : DownloadSet =\
|
|
{
|
|
'yunet':
|
|
{
|
|
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.onnx',
|
|
'path': '.assets/models/yunet_2023_mar.onnx'
|
|
}
|
|
}
|
|
invalid_set : DownloadSet =\
|
|
{
|
|
'invalid':
|
|
{
|
|
'url': 'invalid',
|
|
'path': 'invalid'
|
|
}
|
|
}
|
|
|
|
assert conditional_download_files(hash_set) is True
|
|
assert process_manager.is_pending() is True
|
|
assert conditional_download_files(source_set) is True
|
|
assert process_manager.is_pending() is True
|
|
assert conditional_download_files(invalid_set) is False
|
|
assert process_manager.is_pending() is True
|
|
|
|
process_manager.start()
|
|
|
|
assert conditional_download_files(hash_set) is True
|
|
assert process_manager.get_state() == 'processing'
|
|
|
|
with patch('facefusion.process_manager.check', side_effect = process_manager.stop):
|
|
assert conditional_download_files(hash_set) is True
|
|
|
|
assert process_manager.get_state() == 'stopping'
|
|
|
|
process_manager.end()
|
|
|
|
|
|
def test_conditional_validate_files() -> None:
|
|
file_set : DownloadSet =\
|
|
{
|
|
'yunet':
|
|
{
|
|
'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.onnx',
|
|
'path': '.assets/models/yunet_2023_mar.onnx'
|
|
}
|
|
}
|
|
invalid_set : DownloadSet =\
|
|
{
|
|
'invalid':
|
|
{
|
|
'url': 'invalid',
|
|
'path': 'invalid'
|
|
}
|
|
}
|
|
|
|
assert conditional_validate_files(file_set) is True
|
|
assert conditional_validate_files(invalid_set) is False
|
|
|
|
|
|
def test_validate_file() -> None:
|
|
assert validate_file('.assets/models/yunet_2023_mar.hash') is True
|
|
assert validate_file('.assets/models/yunet_2023_mar.onnx') is True
|
|
assert validate_file('invalid.hash') is False
|
|
assert validate_file('invalid') is False
|
|
|
|
|
|
def test_resolve_download_url_by_provider() -> None:
|
|
assert resolve_download_url_by_provider('github', 'models-3.4.0', 'yunet_2023_mar.onnx') == 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.onnx'
|
|
assert resolve_download_url_by_provider('huggingface', 'models-3.4.0', 'yunet_2023_mar.onnx') == 'https://huggingface.co/facefusion/models-3.4.0/resolve/main/yunet_2023_mar.onnx'
|