Spaces:
Runtime error
Runtime error
Delete tests
Browse filesFiles changed (42)
- tests/__init__.pyDeleted
- tests/helper.pyDeleted-44
- tests/test_audio.pyDeleted-28
- tests/test_cli_age_modifier.pyDeleted-38
- tests/test_cli_background_remover.pyDeleted-39
- tests/test_cli_batch_runner.pyDeleted-45
- tests/test_cli_expression_restorer.pyDeleted-38
- tests/test_cli_face_debugger.pyDeleted-39
- tests/test_cli_face_editor.pyDeleted-39
- tests/test_cli_face_enhancer.pyDeleted-39
- tests/test_cli_face_swapper.pyDeleted-39
- tests/test_cli_frame_colorizer.pyDeleted-40
- tests/test_cli_frame_enhancer.pyDeleted-39
- tests/test_cli_job_manager.pyDeleted-209
- tests/test_cli_job_runner.pyDeleted-147
- tests/test_cli_lip_syncer.pyDeleted-40
- tests/test_cli_output_scale.pyDeleted-57
- tests/test_common_helper.pyDeleted-27
- tests/test_config.pyDeleted-85
- tests/test_curl_builder.pyDeleted-17
- tests/test_download.pyDeleted-18
- tests/test_execution.pyDeleted-24
- tests/test_face_analyser.pyDeleted-131
- tests/test_ffmpeg.pyDeleted-189
- tests/test_ffmpeg_builder.pyDeleted-110
- tests/test_filesystem.pyDeleted-135
- tests/test_inference_manager.pyDeleted-32
- tests/test_job_helper.pyDeleted-9
- tests/test_job_list.pyDeleted-24
- tests/test_job_manager.pyDeleted-386
- tests/test_job_runner.pyDeleted-276
- tests/test_json.pyDeleted-19
- tests/test_memory.pyDeleted-8
- tests/test_normalizer.pyDeleted-24
- tests/test_process_manager.pyDeleted-22
- tests/test_program_helper.pyDeleted-52
- tests/test_sanitizer.pyDeleted-8
- tests/test_state_manager.pyDeleted-35
- tests/test_temp_helper.pyDeleted-34
- tests/test_time_helper.pyDeleted-15
- tests/test_translator.pyDeleted-14
- tests/test_vision.pyDeleted-169
1234567891011121314151617181920212223242526272829303132333435363738394041424344import os
import tempfile
from facefusion.filesystem import create_directory, is_directory, is_file, remove_directory
from facefusion.types import JobStatus
def is_test_job_file(file_path : str, job_status : JobStatus) -> bool:
return is_file(get_test_job_file(file_path, job_status))
def get_test_job_file(file_path : str, job_status : JobStatus) -> str:
return os.path.join(get_test_jobs_directory(), job_status, file_path)
def get_test_jobs_directory() -> str:
return os.path.join(tempfile.gettempdir(), 'facefusion-test-jobs')
def get_test_example_file(file_path : str) -> str:
return os.path.join(get_test_examples_directory(), file_path)
def get_test_examples_directory() -> str:
return os.path.join(tempfile.gettempdir(), 'facefusion-test-examples')
def is_test_output_file(file_path : str) -> bool:
return is_file(get_test_output_file(file_path))
def get_test_output_file(file_path : str) -> str:
return os.path.join(get_test_outputs_directory(), file_path)
def get_test_outputs_directory() -> str:
return os.path.join(tempfile.gettempdir(), 'facefusion-test-outputs')
def prepare_test_output_directory() -> bool:
test_outputs_directory = get_test_outputs_directory()
remove_directory(test_outputs_directory)
create_directory(test_outputs_directory)
return is_directory(test_outputs_directory)12345678910111213141516171819202122232425262728import subprocess
import pytest
from facefusion.audio import get_audio_frame, read_static_audio
from facefusion.download import conditional_download
from .helper import get_test_example_file, get_test_examples_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.mp3'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.mp3'), get_test_example_file('source.wav') ])
def test_get_audio_frame() -> None:
assert hasattr(get_audio_frame(get_test_example_file('source.mp3'), 25), '__array_interface__')
assert hasattr(get_audio_frame(get_test_example_file('source.wav'), 25), '__array_interface__')
assert get_audio_frame('invalid', 25) is None
def test_read_static_audio() -> None:
assert len(read_static_audio(get_test_example_file('source.mp3'), 25)) == 280
assert len(read_static_audio(get_test_example_file('source.wav'), 25)) == 280
assert read_static_audio('invalid', 25) is None1234567891011121314151617181920212223242526272829303132333435363738import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_modify_age_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'age_modifier', '--age-modifier-direction', '100', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-age-face-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-age-face-to-image.jpg') is True
def test_modify_age_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'age_modifier', '--age-modifier-direction', '100', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-age-face-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-age-face-to-video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run(['ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg')])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_remove_background_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'background_remover', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-remove-background-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-remove-background-to-image.jpg') is True
def test_remove_background_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'background_remover', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-remove-background-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-remove-background-to-video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839404142434445import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p-batch-1.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '2', get_test_example_file('target-240p-batch-2.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_batch_run_targets() -> None:
commands = [ sys.executable, 'facefusion.py', 'batch-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p-batch-*.jpg'), '-o', get_test_output_file('test-batch-run-targets-{index}.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-batch-run-targets-0.jpg') is True
assert is_test_output_file('test-batch-run-targets-1.jpg') is True
assert is_test_output_file('test-batch-run-targets-2.jpg') is False
def test_batch_run_sources_to_targets() -> None:
commands = [ sys.executable, 'facefusion.py', 'batch-run', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('target-240p-batch-*.jpg'), '-t', get_test_example_file('target-240p-batch-*.jpg'), '-o', get_test_output_file('test-batch-run-sources-to-targets-{index}.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-batch-run-sources-to-targets-0.jpg') is True
assert is_test_output_file('test-batch-run-sources-to-targets-1.jpg') is True
assert is_test_output_file('test-batch-run-sources-to-targets-2.jpg') is True
assert is_test_output_file('test-batch-run-sources-to-targets-3.jpg') is True
assert is_test_output_file('test-batch-run-sources-to-targets-4.jpg') is False1234567891011121314151617181920212223242526272829303132333435363738import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_restore_expression_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'expression_restorer', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-restore-expression-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-restore-expression-to-image.jpg') is True
def test_restore_expression_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'expression_restorer', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-restore-expression-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-restore-expression-to-video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_debug_face_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-debug-face-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-debug-face-to-image.jpg') is True
def test_debug_face_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-debug-face-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-debug-face-to-video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_edit_face_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_editor', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-edit-face-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-edit-face-to-image.jpg') is True
def test_edit_face_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_editor', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-edit-face-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-edit-face-to-video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_enhance_face_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_enhancer', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-enhance-face-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-enhance-face-to-image.jpg') is True
def test_enhance_face_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_enhancer', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-enhance-face-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-enhance-face-to-video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_swap_face_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_swapper', '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-swap-face-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-swap-face-to-image.jpg') is True
def test_swap_face_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_swapper', '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-swap-face-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-swap-face-to-video.mp4') is True12345678910111213141516171819202122232425262728293031323334353637383940import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', '-vf', 'hue=s=0', get_test_example_file('target-240p-0sat.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'hue=s=0', get_test_example_file('target-240p-0sat.mp4') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_colorize_frame_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'frame_colorizer', '-t', get_test_example_file('target-240p-0sat.jpg'), '-o', get_test_output_file('test_colorize-frame-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test_colorize-frame-to-image.jpg') is True
def test_colorize_frame_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'frame_colorizer', '-t', get_test_example_file('target-240p-0sat.mp4'), '-o', get_test_output_file('test-colorize-frame-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-colorize-frame-to-video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_enhance_frame_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'frame_enhancer', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-enhance-frame-to-image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-enhance-frame-to-image.jpg') is True
def test_enhance_frame_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'frame_enhancer', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-enhance-frame-to-video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test-enhance-frame-to-video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, count_step_total, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_job_file
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
@pytest.mark.skip()
def test_job_list() -> None:
pass
def test_job_create() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-create', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 0
assert is_test_job_file('test-job-create.json', 'drafted') is True
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-create', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 1
def test_job_submit() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-submit', 'test-job-submit', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-submit', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-submit', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-submit', 'test-job-submit', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 0
assert is_test_job_file('test-job-submit.json', 'queued') is True
assert subprocess.run(commands).returncode == 1
def test_submit_all() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-submit-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-submit-all-1', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-submit-all-2', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-submit-all-1', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-submit-all-2', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-submit-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 0
assert is_test_job_file('test-job-submit-all-1.json', 'queued') is True
assert is_test_job_file('test-job-submit-all-2.json', 'queued') is True
assert subprocess.run(commands).returncode == 1
def test_job_delete() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-delete', 'test-job-delete', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-delete', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-delete', 'test-job-delete', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 0
assert is_test_job_file('test-job-delete.json', 'drafted') is False
assert subprocess.run(commands).returncode == 1
def test_job_delete_all() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-delete-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-delete-all-1', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-delete-all-2', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-delete-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 0
assert is_test_job_file('test-job-delete-all-1.json', 'drafted') is False
assert is_test_job_file('test-job-delete-all-2.json', 'drafted') is False
assert subprocess.run(commands).returncode == 1
def test_job_add_step() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-add-step', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
assert subprocess.run(commands).returncode == 1
assert count_step_total('test-job-add-step') == 0
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-add-step', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-add-step', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
assert subprocess.run(commands).returncode == 0
assert count_step_total('test-job-add-step') == 1
def test_job_remix() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-remix-step', 'test-job-remix-step', '0', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
assert subprocess.run(commands).returncode == 1
assert count_step_total('test-job-remix-step') == 0
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-remix-step', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-remix-step', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-remix-step', 'test-job-remix-step', '0', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
assert count_step_total('test-job-remix-step') == 1
assert subprocess.run(commands).returncode == 0
assert count_step_total('test-job-remix-step') == 2
commands = [ sys.executable, 'facefusion.py', 'job-remix-step', 'test-job-remix-step', '-1', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
assert subprocess.run(commands).returncode == 0
assert count_step_total('test-job-remix-step') == 3
def test_job_insert_step() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-insert-step', 'test-job-insert-step', '0', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
assert subprocess.run(commands).returncode == 1
assert count_step_total('test-job-insert-step') == 0
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-insert-step', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-insert-step', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-insert-step', 'test-job-insert-step', '0', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
assert count_step_total('test-job-insert-step') == 1
assert subprocess.run(commands).returncode == 0
assert count_step_total('test-job-insert-step') == 2
commands = [ sys.executable, 'facefusion.py', 'job-insert-step', 'test-job-insert-step', '-1', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
assert subprocess.run(commands).returncode == 0
assert count_step_total('test-job-insert-step') == 3
def test_job_remove_step() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-remove-step', 'test-job-remove-step', '0', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-remove-step', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-remove-step', '--jobs-path', get_test_jobs_directory(), '-s', get_test_example_file('source.jpg'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-remix-step.jpg') ]
subprocess.run(commands)
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-remove-step', 'test-job-remove-step', '0', '--jobs-path', get_test_jobs_directory() ]
assert count_step_total('test-job-remove-step') == 2
assert subprocess.run(commands).returncode == 0
assert count_step_total('test-job-remove-step') == 1
commands = [ sys.executable, 'facefusion.py', 'job-remove-step', 'test-job-remove-step', '-1', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 0
assert subprocess.run(commands).returncode == 1
assert count_step_total('test-job-remove-step') == 0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs, move_job_file, set_steps_status
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_job_run() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-run', 'test-job-run', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-run', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-run.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-run', 'test-job-run', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-submit', 'test-job-run', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-run', 'test-job-run', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 0
assert subprocess.run(commands).returncode == 1
assert is_test_output_file('test-job-run.jpg') is True
def test_job_run_all() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-run-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-run-all-1', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-run-all-2', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-run-all-1', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-run-all-1.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-run-all-2', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-job-run-all-2.mp4'), '--trim-frame-end', '1' ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-run-all-2', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-job-run-all-2.mp4'), '--trim-frame-start', '0', '--trim-frame-end', '1' ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-run-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-submit-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-run-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 0
assert subprocess.run(commands).returncode == 1
assert is_test_output_file('test-job-run-all-1.jpg') is True
assert is_test_output_file('test-job-run-all-2.mp4') is True
def test_job_retry() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-retry', 'test-job-retry', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-retry', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-retry', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-retry.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-retry', 'test-job-retry', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 1
set_steps_status('test-job-retry', 'failed')
move_job_file('test-job-retry', 'failed')
commands = [ sys.executable, 'facefusion.py', 'job-retry', 'test-job-retry', '--jobs-path', get_test_jobs_directory() ]
assert subprocess.run(commands).returncode == 0
assert subprocess.run(commands).returncode == 1
assert is_test_output_file('test-job-retry.jpg') is True
def test_job_retry_all() -> None:
commands = [ sys.executable, 'facefusion.py', 'job-retry-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 1
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-retry-all-1', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-create', 'test-job-retry-all-2', '--jobs-path', get_test_jobs_directory() ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-retry-all-1', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test-job-retry-all-1.jpg') ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-retry-all-2', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-job-retry-all-2.mp4'), '--trim-frame-end', '1' ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-add-step', 'test-job-retry-all-2', '--jobs-path', get_test_jobs_directory(), '--processors', 'face_debugger', '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test-job-retry-all-2.mp4'), '--trim-frame-start', '0', '--trim-frame-end', '1' ]
subprocess.run(commands)
commands = [ sys.executable, 'facefusion.py', 'job-retry-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 1
set_steps_status('test-job-retry-all-1', 'failed')
set_steps_status('test-job-retry-all-2', 'failed')
move_job_file('test-job-retry-all-1', 'failed')
move_job_file('test-job-retry-all-2', 'failed')
commands = [ sys.executable, 'facefusion.py', 'job-retry-all', '--jobs-path', get_test_jobs_directory(), '--halt-on-error' ]
assert subprocess.run(commands).returncode == 0
assert subprocess.run(commands).returncode == 1
assert is_test_output_file('test-job-retry-all-1.jpg') is True
assert is_test_output_file('test-job-retry-all-2.mp4') is True12345678910111213141516171819202122232425262728293031323334353637383940import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.mp3',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def test_sync_lip_to_image() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'lip_syncer', '-s', get_test_example_file('source.mp3'), '-t', get_test_example_file('target-240p.jpg'), '-o', get_test_output_file('test_sync_lip_to_image.jpg') ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test_sync_lip_to_image.jpg') is True
def test_sync_lip_to_video() -> None:
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'lip_syncer', '-s', get_test_example_file('source.mp3'), '-t', get_test_example_file('target-240p.mp4'), '-o', get_test_output_file('test_sync_lip_to_video.mp4'), '--trim-frame-end', '1' ]
assert subprocess.run(commands).returncode == 0
assert is_test_output_file('test_sync_lip_to_video.mp4') is True123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import subprocess
import sys
import pytest
from facefusion.download import conditional_download
from facefusion.jobs.job_manager import clear_jobs, init_jobs
from facefusion.types import Resolution, Scale
from facefusion.vision import detect_image_resolution, detect_video_resolution
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
@pytest.mark.parametrize('output_image_scale, output_image_resolution',
[
(0.5, (212, 112)),
(1.0, (426, 226)),
(2.0, (852, 452)),
(8.0, (3408, 1808))
])
def test_output_image_scale(output_image_scale : Scale, output_image_resolution : Resolution) -> None:
output_file_path = get_test_output_file('test-output-image-scale-' + str(output_image_scale) + '.jpg')
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'frame_enhancer', '-t', get_test_example_file('target-240p.jpg'), '-o', output_file_path, '--output-image-scale', str(output_image_scale) ]
assert subprocess.run(commands).returncode == 0
assert detect_image_resolution(output_file_path) == output_image_resolution
@pytest.mark.parametrize('output_video_scale, output_video_resolution',
[
(0.5, (212, 112)),
(1.0, (426, 226)),
(2.0, (852, 452)),
(8.0, (3408, 1808))
])
def test_output_video_scale(output_video_scale : Scale, output_video_resolution : Resolution) -> None:
output_file_path = get_test_output_file('test-output-video-scale-' + str(output_video_scale) + '.mp4')
commands = [ sys.executable, 'facefusion.py', 'headless-run', '--jobs-path', get_test_jobs_directory(), '--processors', 'frame_enhancer', '-t', get_test_example_file('target-240p.mp4'), '-o', output_file_path, '--trim-frame-end', '1', '--output-video-scale', str(output_video_scale) ]
assert subprocess.run(commands).returncode == 0
assert detect_video_resolution(output_file_path) == output_video_resolution123456789101112131415161718192021222324252627from facefusion.common_helper import calculate_float_step, calculate_int_step, create_float_metavar, create_float_range, create_int_metavar, create_int_range
def test_create_int_metavar() -> None:
assert create_int_metavar([ 1, 2, 3, 4, 5 ]) == '[1..5:1]'
def test_create_float_metavar() -> None:
assert create_float_metavar([ 0.1, 0.2, 0.3, 0.4, 0.5 ]) == '[0.1..0.5:0.1]'
def test_create_int_range() -> None:
assert create_int_range(0, 2, 1) == [ 0, 1, 2 ]
assert create_float_range(0, 1, 1) == [ 0, 1 ]
def test_create_float_range() -> None:
assert create_float_range(0.0, 1.0, 0.5) == [ 0.0, 0.5, 1.0 ]
assert create_float_range(0.0, 1.0, 0.05) == [ 0.0, 0.05, 0.10, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, 0.90, 0.95, 1.0 ]
def test_calc_int_step() -> None:
assert calculate_int_step([0, 1]) == 1
def test_calc_float_step() -> None:
assert calculate_float_step([0.1, 0.2]) == 0.112345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485from configparser import ConfigParser
import pytest
from facefusion import config
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
config.CONFIG_PARSER = ConfigParser()
config.CONFIG_PARSER.read_dict(
{
'str':
{
'valid': 'a',
'unset': ''
},
'int':
{
'valid': '1',
'unset': ''
},
'float':
{
'valid': '1.0',
'unset': ''
},
'bool':
{
'valid': 'True',
'unset': ''
},
'str_list':
{
'valid': 'a b c',
'unset': ''
},
'int_list':
{
'valid': '1 2 3',
'unset': ''
}
})
def test_get_str_value() -> None:
assert config.get_str_value('str', 'valid') == 'a'
assert config.get_str_value('str', 'unset', 'b') == 'b'
assert config.get_str_value('str', 'unset') is None
assert config.get_str_value('str', 'invalid') is None
def test_get_int_value() -> None:
assert config.get_int_value('int', 'valid') == 1
assert config.get_int_value('int', 'unset', '1') == 1
assert config.get_int_value('int', 'unset') is None
assert config.get_int_value('int', 'invalid') is None
def test_get_float_value() -> None:
assert config.get_float_value('float', 'valid') == 1.0
assert config.get_float_value('float', 'unset', '1.0') == 1.0
assert config.get_float_value('float', 'unset') is None
assert config.get_float_value('float', 'invalid') is None
def test_get_bool_value() -> None:
assert config.get_bool_value('bool', 'valid') is True
assert config.get_bool_value('bool', 'unset', 'False') is False
assert config.get_bool_value('bool', 'unset') is None
assert config.get_bool_value('bool', 'invalid') is None
def test_get_str_list() -> None:
assert config.get_str_list('str_list', 'valid') == [ 'a', 'b', 'c' ]
assert config.get_str_list('str_list', 'unset', 'c b a') == [ 'c', 'b', 'a' ]
assert config.get_str_list('str_list', 'unset') is None
assert config.get_str_list('str_list', 'invalid') is None
def test_get_int_list() -> None:
assert config.get_int_list('int_list', 'valid') == [ 1, 2, 3 ]
assert config.get_int_list('int_list', 'unset', '3 2 1') == [ 3, 2, 1 ]
assert config.get_int_list('int_list', 'unset') is None
assert config.get_int_list('int_list', 'invalid') is None1234567891011121314151617from shutil import which
from facefusion import metadata
from facefusion.curl_builder import chain, ping, run, set_timeout
def test_run() -> None:
user_agent = metadata.get('name') + '/' + metadata.get('version')
assert run([]) == [ which('curl'), '--user-agent', user_agent, '--insecure', '--location', '--silent' ]
def test_chain() -> None:
assert chain(
ping(metadata.get('url')),
set_timeout(5)
) == [ '-I', metadata.get('url'), '--connect-timeout', '5' ]123456789101112131415161718from facefusion.download import get_static_download_size, ping_static_url, resolve_download_url_by_provider
def test_get_static_download_size() -> None:
assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.onnx') == 85170772
assert get_static_download_size('https://huggingface.co/facefusion/models-3.0.0/resolve/main/fairface.onnx') == 85170772
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_resolve_download_url_by_provider() -> None:
assert resolve_download_url_by_provider('github', 'models-3.0.0', 'fairface.onnx') == 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.onnx'
assert resolve_download_url_by_provider('huggingface', 'models-3.0.0', 'fairface.onnx') == 'https://huggingface.co/facefusion/models-3.0.0/resolve/main/fairface.onnx'123456789101112131415161718192021222324from facefusion.execution import create_inference_session_providers, get_available_execution_providers, has_execution_provider
def test_has_execution_provider() -> None:
assert has_execution_provider('cpu') is True
assert has_execution_provider('openvino') is False
def test_get_available_execution_providers() -> None:
assert 'cpu' in get_available_execution_providers()
def test_create_inference_session_providers() -> None:
inference_session_providers =\
[
('CUDAExecutionProvider',
{
'device_id': 1,
'cudnn_conv_algo_search': 'EXHAUSTIVE'
}),
'CPUExecutionProvider'
]
assert create_inference_session_providers(1, [ 'cpu', 'cuda' ]) == inference_session_providers123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131import subprocess
import pytest
from facefusion import face_classifier, face_detector, face_landmarker, face_recognizer, state_manager
from facefusion.download import conditional_download
from facefusion.face_analyser import get_many_faces
from facefusion.vision import read_static_image
from .helper import get_test_example_file, get_test_examples_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.8:ih*0.8', get_test_example_file('source-80crop.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.7:ih*0.7', get_test_example_file('source-70crop.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.6:ih*0.6', get_test_example_file('source-60crop.jpg') ])
state_manager.init_item('execution_device_ids', [ 0 ])
state_manager.init_item('execution_providers', [ 'cpu' ])
state_manager.init_item('download_providers', [ 'github' ])
state_manager.init_item('face_detector_angles', [ 0 ])
state_manager.init_item('face_detector_model', 'many')
state_manager.init_item('face_detector_score', 0.5)
state_manager.init_item('face_landmarker_model', 'many')
state_manager.init_item('face_landmarker_score', 0.5)
face_classifier.pre_check()
face_landmarker.pre_check()
face_recognizer.pre_check()
@pytest.fixture(autouse = True)
def before_each() -> None:
face_classifier.clear_inference_pool()
face_detector.clear_inference_pool()
face_landmarker.clear_inference_pool()
face_recognizer.clear_inference_pool()
def test_get_one_face_with_retinaface() -> None:
state_manager.init_item('face_detector_model', 'retinaface')
state_manager.init_item('face_detector_size', '320x320')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
source_paths =\
[
get_test_example_file('source.jpg'),
get_test_example_file('source-80crop.jpg'),
get_test_example_file('source-70crop.jpg'),
get_test_example_file('source-60crop.jpg')
]
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
assert len(many_faces) == 1
def test_get_one_face_with_scrfd() -> None:
state_manager.init_item('face_detector_model', 'scrfd')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
source_paths =\
[
get_test_example_file('source.jpg'),
get_test_example_file('source-80crop.jpg'),
get_test_example_file('source-70crop.jpg'),
get_test_example_file('source-60crop.jpg')
]
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
assert len(many_faces) == 1
def test_get_one_face_with_yoloface() -> None:
state_manager.init_item('face_detector_model', 'yoloface')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
source_paths =\
[
get_test_example_file('source.jpg'),
get_test_example_file('source-80crop.jpg'),
get_test_example_file('source-70crop.jpg'),
get_test_example_file('source-60crop.jpg')
]
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
assert len(many_faces) == 1
def test_get_one_face_with_yunet() -> None:
state_manager.init_item('face_detector_model', 'yunet')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
source_paths =\
[
get_test_example_file('source.jpg'),
get_test_example_file('source-80crop.jpg'),
get_test_example_file('source-70crop.jpg'),
get_test_example_file('source-60crop.jpg')
]
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
assert len(many_faces) == 1
def test_get_many_faces() -> None:
source_path = get_test_example_file('source.jpg')
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame, source_frame, source_frame ])
assert len(many_faces) == 3123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189import os
import subprocess
import tempfile
import pytest
import facefusion.ffmpeg
from facefusion import process_manager, state_manager
from facefusion.download import conditional_download
from facefusion.ffmpeg import concat_video, extract_frames, merge_video, read_audio_buffer, replace_audio, restore_audio
from facefusion.filesystem import copy_file
from facefusion.temp_helper import clear_temp_directory, create_temp_directory, get_temp_file_path, resolve_temp_frame_paths
from facefusion.types import EncoderSet
from .helper import get_test_example_file, get_test_examples_directory, get_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
process_manager.start()
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.mp3',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.mp3'), get_test_example_file('source.wav') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=25', get_test_example_file('target-240p-25fps.mp4') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=30', get_test_example_file('target-240p-30fps.mp4') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=60', get_test_example_file('target-240p-60fps.mp4') ])
for output_video_format in [ 'avi', 'm4v', 'mkv', 'mov', 'mp4', 'webm', 'wmv' ]:
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.mp3'), '-i', get_test_example_file('target-240p.mp4'), '-ar', '16000', get_test_example_file('target-240p-16khz.' + output_video_format) ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.mp3'), '-i', get_test_example_file('target-240p.mp4'), '-ar', '48000', get_test_example_file('target-240p-48khz.mp4') ])
state_manager.init_item('temp_path', tempfile.gettempdir())
state_manager.init_item('temp_frame_format', 'png')
state_manager.init_item('output_audio_encoder', 'aac')
state_manager.init_item('output_audio_quality', 100)
state_manager.init_item('output_audio_volume', 100)
state_manager.init_item('output_video_encoder', 'libx264')
state_manager.init_item('output_video_quality', 100)
state_manager.init_item('output_video_preset', 'ultrafast')
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
prepare_test_output_directory()
def get_available_encoder_set() -> EncoderSet:
if os.getenv('CI'):
return\
{
'audio': [ 'aac' ],
'video': [ 'libx264' ]
}
return facefusion.ffmpeg.get_available_encoder_set()
def test_get_available_encoder_set() -> None:
available_encoder_set = get_available_encoder_set()
assert 'aac' in available_encoder_set.get('audio')
assert 'libx264' in available_encoder_set.get('video')
def test_extract_frames() -> None:
test_set =\
[
(get_test_example_file('target-240p-25fps.mp4'), 0, 270, 324),
(get_test_example_file('target-240p-25fps.mp4'), 224, 270, 55),
(get_test_example_file('target-240p-25fps.mp4'), 124, 224, 120),
(get_test_example_file('target-240p-25fps.mp4'), 0, 100, 120),
(get_test_example_file('target-240p-30fps.mp4'), 0, 324, 324),
(get_test_example_file('target-240p-30fps.mp4'), 224, 324, 100),
(get_test_example_file('target-240p-30fps.mp4'), 124, 224, 100),
(get_test_example_file('target-240p-30fps.mp4'), 0, 100, 100),
(get_test_example_file('target-240p-60fps.mp4'), 0, 648, 324),
(get_test_example_file('target-240p-60fps.mp4'), 224, 648, 212),
(get_test_example_file('target-240p-60fps.mp4'), 124, 224, 50),
(get_test_example_file('target-240p-60fps.mp4'), 0, 100, 50)
]
for target_path, trim_frame_start, trim_frame_end, frame_total in test_set:
create_temp_directory(target_path)
assert extract_frames(target_path, (452, 240), 30.0, trim_frame_start, trim_frame_end) is True
assert len(resolve_temp_frame_paths(target_path)) == frame_total
clear_temp_directory(target_path)
def test_merge_video() -> None:
target_paths =\
[
get_test_example_file('target-240p-16khz.avi'),
get_test_example_file('target-240p-16khz.m4v'),
get_test_example_file('target-240p-16khz.mkv'),
get_test_example_file('target-240p-16khz.mp4'),
get_test_example_file('target-240p-16khz.mov'),
get_test_example_file('target-240p-16khz.webm'),
get_test_example_file('target-240p-16khz.wmv')
]
output_video_encoders = get_available_encoder_set().get('video')
for target_path in target_paths:
for output_video_encoder in output_video_encoders:
state_manager.init_item('output_video_encoder', output_video_encoder)
create_temp_directory(target_path)
extract_frames(target_path, (452, 240), 25.0, 0, 1)
assert merge_video(target_path, 25.0, (452, 240), 25.0, 0, 1) is True
clear_temp_directory(target_path)
state_manager.init_item('output_video_encoder', 'libx264')
def test_concat_video() -> None:
output_path = get_test_output_file('test-concat-video.mp4')
temp_output_paths =\
[
get_test_example_file('target-240p-16khz.mp4'),
get_test_example_file('target-240p-16khz.mp4')
]
assert concat_video(output_path, temp_output_paths) is True
def test_read_audio_buffer() -> None:
assert isinstance(read_audio_buffer(get_test_example_file('source.mp3'), 1, 16, 1), bytes)
assert isinstance(read_audio_buffer(get_test_example_file('source.wav'), 1, 16, 1), bytes)
assert read_audio_buffer(get_test_example_file('invalid.mp3'), 1, 16, 1) is None
def test_restore_audio() -> None:
test_set =\
[
(get_test_example_file('target-240p-16khz.avi'), get_test_output_file('target-240p-16khz.avi')),
(get_test_example_file('target-240p-16khz.m4v'), get_test_output_file('target-240p-16khz.m4v')),
(get_test_example_file('target-240p-16khz.mkv'), get_test_output_file('target-240p-16khz.mkv')),
(get_test_example_file('target-240p-16khz.mov'), get_test_output_file('target-240p-16khz.mov')),
(get_test_example_file('target-240p-16khz.mp4'), get_test_output_file('target-240p-16khz.mp4')),
(get_test_example_file('target-240p-48khz.mp4'), get_test_output_file('target-240p-48khz.mp4')),
(get_test_example_file('target-240p-16khz.webm'), get_test_output_file('target-240p-16khz.webm')),
(get_test_example_file('target-240p-16khz.wmv'), get_test_output_file('target-240p-16khz.wmv'))
]
output_audio_encoders = get_available_encoder_set().get('audio')
for target_path, output_path in test_set:
create_temp_directory(target_path)
for output_audio_encoder in output_audio_encoders:
state_manager.init_item('output_audio_encoder', output_audio_encoder)
copy_file(target_path, get_temp_file_path(target_path))
assert restore_audio(target_path, output_path, 0, 270) is True
clear_temp_directory(target_path)
state_manager.init_item('output_audio_encoder', 'aac')
def test_replace_audio() -> None:
test_set =\
[
(get_test_example_file('target-240p-16khz.avi'), get_test_output_file('target-240p-16khz.avi')),
(get_test_example_file('target-240p-16khz.m4v'), get_test_output_file('target-240p-16khz.m4v')),
(get_test_example_file('target-240p-16khz.mkv'), get_test_output_file('target-240p-16khz.mkv')),
(get_test_example_file('target-240p-16khz.mov'), get_test_output_file('target-240p-16khz.mov')),
(get_test_example_file('target-240p-16khz.mp4'), get_test_output_file('target-240p-16khz.mp4')),
(get_test_example_file('target-240p-48khz.mp4'), get_test_output_file('target-240p-48khz.mp4')),
(get_test_example_file('target-240p-16khz.webm'), get_test_output_file('target-240p-16khz.webm'))
]
output_audio_encoders = get_available_encoder_set().get('audio')
for target_path, output_path in test_set:
create_temp_directory(target_path)
for output_audio_encoder in output_audio_encoders:
state_manager.init_item('output_audio_encoder', output_audio_encoder)
copy_file(target_path, get_temp_file_path(target_path))
assert replace_audio(target_path, get_test_example_file('source.mp3'), output_path) is True
assert replace_audio(target_path, get_test_example_file('source.wav'), output_path) is True
clear_temp_directory(target_path)
state_manager.init_item('output_audio_encoder', 'aac')123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110from shutil import which
from facefusion import ffmpeg_builder
from facefusion.ffmpeg_builder import chain, concat, keep_video_alpha, run, select_frame_range, set_audio_quality, set_audio_sample_size, set_stream_mode, set_video_encoder, set_video_fps, set_video_quality
def test_run() -> None:
assert run([]) == [ which('ffmpeg'), '-loglevel', 'error' ]
def test_chain() -> None:
assert chain(
ffmpeg_builder.set_input('input.mp4'),
ffmpeg_builder.set_output('output.mp4')
) == [ '-i', 'input.mp4', 'output.mp4' ]
assert chain(
ffmpeg_builder.set_video_encoder('libx264'),
ffmpeg_builder.set_video_fps(30),
ffmpeg_builder.set_audio_encoder('aac')
) == [ '-c:v', 'libx264', '-vf', 'fps=30', '-c:a', 'aac' ]
def test_concat() -> None:
assert concat(
set_video_encoder('libvpx-vp9'),
set_video_fps(30)
) == [ '-c:v', 'libvpx-vp9', '-vf', 'fps=30' ]
assert concat(
set_video_encoder('libvpx-vp9'),
set_video_fps(30),
keep_video_alpha('libvpx-vp9')
) == [ '-c:v', 'libvpx-vp9', '-vf', 'fps=30,format=yuva420p' ]
assert concat(
select_frame_range(0, 100, 30),
keep_video_alpha('libvpx-vp9')
) == [ '-vf', 'trim=start_frame=0:end_frame=100,fps=30,format=yuva420p' ]
def test_set_stream_mode() -> None:
assert set_stream_mode('udp') == [ '-f', 'mpegts' ]
assert set_stream_mode('v4l2') == [ '-f', 'v4l2' ]
def test_select_frame_range() -> None:
assert select_frame_range(0, None, 30) == [ '-vf', 'trim=start_frame=0,fps=30' ]
assert select_frame_range(None, 100, 30) == [ '-vf', 'trim=end_frame=100,fps=30' ]
assert select_frame_range(0, 100, 30) == [ '-vf', 'trim=start_frame=0:end_frame=100,fps=30' ]
assert select_frame_range(None, None, 30) == [ '-vf', 'fps=30' ]
def test_set_audio_sample_size() -> None:
assert set_audio_sample_size(16) == [ '-f', 's16le' ]
assert set_audio_sample_size(32) == [ '-f', 's32le' ]
def test_set_audio_quality() -> None:
assert set_audio_quality('aac', 0) == [ '-q:a', '0.1' ]
assert set_audio_quality('aac', 50) == [ '-q:a', '1.0' ]
assert set_audio_quality('aac', 100) == [ '-q:a', '2.0' ]
assert set_audio_quality('libmp3lame', 0) == [ '-q:a', '9' ]
assert set_audio_quality('libmp3lame', 50) == [ '-q:a', '4' ]
assert set_audio_quality('libmp3lame', 100) == [ '-q:a', '0' ]
assert set_audio_quality('libopus', 0) == [ '-b:a', '64k' ]
assert set_audio_quality('libopus', 50) == [ '-b:a', '160k' ]
assert set_audio_quality('libopus', 100) == [ '-b:a', '256k' ]
assert set_audio_quality('libvorbis', 0) == [ '-q:a', '-1.0' ]
assert set_audio_quality('libvorbis', 50) == [ '-q:a', '4.5' ]
assert set_audio_quality('libvorbis', 100) == [ '-q:a', '10.0' ]
assert set_audio_quality('flac', 0) == []
assert set_audio_quality('flac', 50) == []
assert set_audio_quality('flac', 100) == []
def test_set_video_quality() -> None:
assert set_video_quality('libx264', 0) == [ '-crf', '51' ]
assert set_video_quality('libx264', 50) == [ '-crf', '26' ]
assert set_video_quality('libx264', 100) == [ '-crf', '0' ]
assert set_video_quality('libx264rgb', 0) == [ '-crf', '51' ]
assert set_video_quality('libx264rgb', 50) == [ '-crf', '26' ]
assert set_video_quality('libx264rgb', 100) == [ '-crf', '0' ]
assert set_video_quality('libx265', 0) == [ '-crf', '51' ]
assert set_video_quality('libx265', 50) == [ '-crf', '26' ]
assert set_video_quality('libx265', 100) == [ '-crf', '0' ]
assert set_video_quality('libvpx-vp9', 0) == [ '-crf', '63' ]
assert set_video_quality('libvpx-vp9', 50) == [ '-crf', '32' ]
assert set_video_quality('libvpx-vp9', 100) == [ '-crf', '0' ]
assert set_video_quality('h264_nvenc', 0) == [ '-cq' , '51' ]
assert set_video_quality('h264_nvenc', 50) == [ '-cq' , '26' ]
assert set_video_quality('h264_nvenc', 100) == [ '-cq' , '0' ]
assert set_video_quality('hevc_nvenc', 0) == [ '-cq' , '51' ]
assert set_video_quality('hevc_nvenc', 50) == [ '-cq' , '26' ]
assert set_video_quality('hevc_nvenc', 100) == [ '-cq' , '0' ]
assert set_video_quality('h264_amf', 0) == [ '-qp_i', '51', '-qp_p', '51', '-qp_b', '51' ]
assert set_video_quality('h264_amf', 50) == [ '-qp_i', '26', '-qp_p', '26', '-qp_b', '26' ]
assert set_video_quality('h264_amf', 100) == [ '-qp_i', '0', '-qp_p', '0', '-qp_b', '0' ]
assert set_video_quality('hevc_amf', 0) == [ '-qp_i', '51', '-qp_p', '51', '-qp_b', '51' ]
assert set_video_quality('hevc_amf', 50) == [ '-qp_i', '26', '-qp_p', '26', '-qp_b', '26' ]
assert set_video_quality('hevc_amf', 100) == [ '-qp_i', '0', '-qp_p', '0', '-qp_b', '0' ]
assert set_video_quality('h264_qsv', 0) == [ '-qp', '51' ]
assert set_video_quality('h264_qsv', 50) == [ '-qp', '26' ]
assert set_video_quality('h264_qsv', 100) == [ '-qp', '0' ]
assert set_video_quality('hevc_qsv', 0) == [ '-qp', '51' ]
assert set_video_quality('hevc_qsv', 50) == [ '-qp', '26' ]
assert set_video_quality('hevc_qsv', 100) == [ '-qp', '0' ]
assert set_video_quality('h264_videotoolbox', 0) == [ '-b:v', '1024k' ]
assert set_video_quality('h264_videotoolbox', 50) == [ '-b:v', '25768k' ]
assert set_video_quality('h264_videotoolbox', 100) == [ '-b:v', '50512k' ]
assert set_video_quality('hevc_videotoolbox', 0) == [ '-b:v', '1024k' ]
assert set_video_quality('hevc_videotoolbox', 50) == [ '-b:v', '25768k' ]
assert set_video_quality('hevc_videotoolbox', 100) == [ '-b:v', '50512k' ]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135import os.path
import pytest
from facefusion.download import conditional_download
from facefusion.filesystem import create_directory, filter_audio_paths, filter_image_paths, get_file_extension, get_file_format, get_file_size, has_audio, has_image, has_video, in_directory, is_audio, is_directory, is_file, is_image, is_video, remove_directory, resolve_file_paths, same_file_extension
from .helper import get_test_example_file, get_test_examples_directory, get_test_outputs_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.mp3',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
def test_get_file_size() -> None:
assert get_file_size(get_test_example_file('source.jpg')) == 549458
assert get_file_size('invalid') == 0
def test_get_file_extension() -> None:
assert get_file_extension('source.jpg') == '.jpg'
assert get_file_extension('source.mp3') == '.mp3'
assert get_file_extension('invalid') is None
def test_get_file_format() -> None:
assert get_file_format('source.jpg') == 'jpeg'
assert get_file_format('source.jpeg') == 'jpeg'
assert get_file_format('source.mp3') == 'mp3'
assert get_file_format('invalid') is None
def test_same_file_extension() -> None:
assert same_file_extension('source.jpg', 'source.jpg') is True
assert same_file_extension('source.jpg', 'source.mp3') is False
assert same_file_extension('invalid', 'invalid') is False
def test_is_file() -> None:
assert is_file(get_test_example_file('source.jpg')) is True
assert is_file(get_test_examples_directory()) is False
assert is_file('invalid') is False
def test_is_audio() -> None:
assert is_audio(get_test_example_file('source.mp3')) is True
assert is_audio(get_test_example_file('source.jpg')) is False
assert is_audio('invalid') is False
def test_has_audio() -> None:
assert has_audio([ get_test_example_file('source.mp3') ]) is True
assert has_audio([ get_test_example_file('source.mp3'), get_test_example_file('source.jpg') ]) is True
assert has_audio([ get_test_example_file('source.jpg'), get_test_example_file('source.jpg') ]) is False
assert has_audio([ 'invalid' ]) is False
def test_is_image() -> None:
assert is_image(get_test_example_file('source.jpg')) is True
assert is_image(get_test_example_file('target-240p.mp4')) is False
assert is_image('invalid') is False
def test_has_image() -> None:
assert has_image([ get_test_example_file('source.jpg') ]) is True
assert has_image([ get_test_example_file('source.jpg'), get_test_example_file('source.mp3') ]) is True
assert has_image([ get_test_example_file('source.mp3'), get_test_example_file('source.mp3') ]) is False
assert has_image([ 'invalid' ]) is False
def test_is_video() -> None:
assert is_video(get_test_example_file('target-240p.mp4')) is True
assert is_video(get_test_example_file('source.jpg')) is False
assert is_video('invalid') is False
def test_has_video() -> None:
assert has_video([ get_test_example_file('target-240p.mp4') ]) is True
assert has_video([ get_test_example_file('target-240p.mp4'), get_test_example_file('source.mp3') ]) is True
assert has_video([ get_test_example_file('source.mp3'), get_test_example_file('source.mp3') ]) is False
assert has_video([ 'invalid' ]) is False
def test_filter_audio_paths() -> None:
assert filter_audio_paths([ get_test_example_file('source.jpg'), get_test_example_file('source.mp3') ]) == [ get_test_example_file('source.mp3') ]
assert filter_audio_paths([ get_test_example_file('source.jpg'), get_test_example_file('source.jpg') ]) == []
assert filter_audio_paths([ 'invalid' ]) == []
def test_filter_image_paths() -> None:
assert filter_image_paths([ get_test_example_file('source.jpg'), get_test_example_file('source.mp3') ]) == [ get_test_example_file('source.jpg') ]
assert filter_image_paths([ get_test_example_file('source.mp3'), get_test_example_file('source.mp3') ]) == []
assert filter_audio_paths([ 'invalid' ]) == []
def test_resolve_file_paths() -> None:
file_paths = resolve_file_paths(get_test_examples_directory())
for file_path in file_paths:
assert file_path == get_test_example_file(file_path)
assert resolve_file_paths('invalid') == []
def test_create_directory() -> None:
create_directory_path = os.path.join(get_test_outputs_directory(), 'create_directory')
assert create_directory(create_directory_path) is True
assert create_directory(get_test_example_file('source.jpg')) is False
def test_remove_directory() -> None:
remove_directory_path = os.path.join(get_test_outputs_directory(), 'remove_directory')
create_directory(remove_directory_path)
assert remove_directory(remove_directory_path) is True
assert remove_directory(get_test_example_file('source.jpg')) is False
assert remove_directory('invalid') is False
def test_is_directory() -> None:
assert is_directory(get_test_examples_directory()) is True
assert is_directory(get_test_example_file('source.jpg')) is False
assert is_directory('invalid') is False
def test_in_directory() -> None:
assert in_directory(get_test_example_file('source.jpg')) is True
assert in_directory('source.jpg') is False
assert in_directory('invalid') is False1234567891011121314151617181920212223242526272829303132from unittest.mock import patch
import pytest
from onnxruntime import InferenceSession
from facefusion import content_analyser, state_manager
from facefusion.inference_manager import INFERENCE_POOL_SET, get_inference_pool
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
state_manager.init_item('execution_device_ids', [ 0 ])
state_manager.init_item('execution_providers', [ 'cpu' ])
state_manager.init_item('download_providers', [ 'github' ])
content_analyser.pre_check()
def test_get_inference_pool() -> None:
model_names = [ 'nsfw_1', 'nsfw_2', 'nsfw_3' ]
_, model_source_set = content_analyser.collect_model_downloads()
with patch('facefusion.inference_manager.detect_app_context', return_value = 'cli'):
get_inference_pool('facefusion.content_analyser', model_names, model_source_set)
assert isinstance(INFERENCE_POOL_SET.get('cli').get('facefusion.content_analyser.nsfw_1.nsfw_2.nsfw_3.0.cpu').get('nsfw_1'), InferenceSession)
with patch('facefusion.inference_manager.detect_app_context', return_value = 'ui'):
get_inference_pool('facefusion.content_analyser', model_names, model_source_set)
assert isinstance(INFERENCE_POOL_SET.get('cli').get('facefusion.content_analyser.nsfw_1.nsfw_2.nsfw_3.0.cpu').get('nsfw_1'), InferenceSession)
assert INFERENCE_POOL_SET.get('cli').get('facefusion.content_analyser.nsfw_1.nsfw_2.nsfw_3.0.cpu').get('nsfw_1') == INFERENCE_POOL_SET.get('ui').get('facefusion.content_analyser.nsfw_1.nsfw_2.nsfw_3.0.cpu').get('nsfw_1')123456789import os
from facefusion.jobs.job_helper import get_step_output_path
def test_get_step_output_path() -> None:
assert get_step_output_path('test-job', 0, 'test.mp4') == 'test-test-job-0.mp4'
assert get_step_output_path('test-job', 0, 'test/test.mp4') == os.path.join('test', 'test-test-job-0.mp4')
assert get_step_output_path('test-job', 0, 'invalid') is None123456789101112131415161718192021222324from time import sleep
import pytest
from facefusion.jobs.job_list import compose_job_list
from facefusion.jobs.job_manager import clear_jobs, create_job, init_jobs
from .helper import get_test_jobs_directory
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
def test_compose_job_list() -> None:
create_job('job-test-compose-job-list-1')
sleep(0.5)
create_job('job-test-compose-job-list-2')
job_headers, job_contents = compose_job_list('drafted')
assert job_headers == [ 'job id', 'steps', 'date created', 'date updated', 'job status' ]
assert job_contents[0] == [ 'job-test-compose-job-list-1', 0, 'just now', None, 'drafted' ]
assert job_contents[1] == [ 'job-test-compose-job-list-2', 0, 'just now', None, 'drafted' ]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386from time import sleep
import pytest
from facefusion.jobs.job_helper import get_step_output_path
from facefusion.jobs.job_manager import add_step, clear_jobs, count_step_total, create_job, delete_job, delete_jobs, find_job_ids, find_jobs, get_steps, init_jobs, insert_step, move_job_file, remix_step, remove_step, set_step_status, set_steps_status, submit_job, submit_jobs
from .helper import get_test_jobs_directory
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
def test_create_job() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
assert create_job('job-test-create-job') is True
assert create_job('job-test-create-job') is False
add_step('job-test-submit-job', args_1)
submit_job('job-test-create-job')
assert create_job('job-test-create-job') is False
def test_submit_job() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
assert submit_job('job-invalid') is False
create_job('job-test-submit-job')
assert submit_job('job-test-submit-job') is False
add_step('job-test-submit-job', args_1)
assert submit_job('job-test-submit-job') is True
assert submit_job('job-test-submit-job') is False
def test_submit_jobs() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
args_2 =\
{
'source_path': 'source-2.jpg',
'target_path': 'target-2.jpg',
'output_path': 'output-2.jpg'
}
halt_on_error = True
assert submit_jobs(halt_on_error) is False
create_job('job-test-submit-jobs-1')
create_job('job-test-submit-jobs-2')
assert submit_jobs(halt_on_error) is False
add_step('job-test-submit-jobs-1', args_1)
add_step('job-test-submit-jobs-2', args_2)
assert submit_jobs(halt_on_error) is True
assert submit_jobs(halt_on_error) is False
def test_delete_job() -> None:
assert delete_job('job-invalid') is False
create_job('job-test-delete-job')
assert delete_job('job-test-delete-job') is True
assert delete_job('job-test-delete-job') is False
def test_delete_jobs() -> None:
halt_on_error = True
assert delete_jobs(halt_on_error) is False
create_job('job-test-delete-jobs-1')
create_job('job-test-delete-jobs-2')
assert delete_jobs(halt_on_error) is True
def test_find_jobs() -> None:
create_job('job-test-find-jobs-1')
sleep(0.5)
create_job('job-test-find-jobs-2')
assert 'job-test-find-jobs-1' in find_jobs('drafted')
assert 'job-test-find-jobs-2' in find_jobs('drafted')
assert not find_jobs('queued')
move_job_file('job-test-find-jobs-1', 'queued')
assert 'job-test-find-jobs-2' in find_jobs('drafted')
assert 'job-test-find-jobs-1' in find_jobs('queued')
def test_find_job_ids() -> None:
create_job('job-test-find-job-ids-1')
sleep(0.5)
create_job('job-test-find-job-ids-2')
sleep(0.5)
create_job('job-test-find-job-ids-3')
assert find_job_ids('drafted') == [ 'job-test-find-job-ids-1', 'job-test-find-job-ids-2', 'job-test-find-job-ids-3' ]
assert find_job_ids('queued') == []
assert find_job_ids('completed') == []
assert find_job_ids('failed') == []
move_job_file('job-test-find-job-ids-1', 'queued')
move_job_file('job-test-find-job-ids-2', 'queued')
move_job_file('job-test-find-job-ids-3', 'queued')
assert find_job_ids('drafted') == []
assert find_job_ids('queued') == [ 'job-test-find-job-ids-1', 'job-test-find-job-ids-2', 'job-test-find-job-ids-3' ]
assert find_job_ids('completed') == []
assert find_job_ids('failed') == []
move_job_file('job-test-find-job-ids-1', 'completed')
assert find_job_ids('drafted') == []
assert find_job_ids('queued') == [ 'job-test-find-job-ids-2', 'job-test-find-job-ids-3' ]
assert find_job_ids('completed') == [ 'job-test-find-job-ids-1' ]
assert find_job_ids('failed') == []
move_job_file('job-test-find-job-ids-2', 'failed')
assert find_job_ids('drafted') == []
assert find_job_ids('queued') == [ 'job-test-find-job-ids-3' ]
assert find_job_ids('completed') == [ 'job-test-find-job-ids-1' ]
assert find_job_ids('failed') == [ 'job-test-find-job-ids-2' ]
move_job_file('job-test-find-job-ids-3', 'completed')
assert find_job_ids('drafted') == []
assert find_job_ids('queued') == []
assert find_job_ids('completed') == [ 'job-test-find-job-ids-1', 'job-test-find-job-ids-3' ]
assert find_job_ids('failed') == [ 'job-test-find-job-ids-2' ]
def test_add_step() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
args_2 =\
{
'source_path': 'source-2.jpg',
'target_path': 'target-2.jpg',
'output_path': 'output-2.jpg'
}
assert add_step('job-invalid', args_1) is False
create_job('job-test-add-step')
assert add_step('job-test-add-step', args_1) is True
assert add_step('job-test-add-step', args_2) is True
steps = get_steps('job-test-add-step')
assert steps[0].get('args') == args_1
assert steps[1].get('args') == args_2
assert count_step_total('job-test-add-step') == 2
def test_remix_step() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
args_2 =\
{
'source_path': 'source-2.jpg',
'target_path': 'target-2.jpg',
'output_path': 'output-2.jpg'
}
assert remix_step('job-invalid', 0, args_1) is False
create_job('job-test-remix-step')
add_step('job-test-remix-step', args_1)
add_step('job-test-remix-step', args_2)
assert remix_step('job-test-remix-step', 99, args_1) is False
assert remix_step('job-test-remix-step', 0, args_2) is True
assert remix_step('job-test-remix-step', -1, args_2) is True
steps = get_steps('job-test-remix-step')
assert steps[0].get('args') == args_1
assert steps[1].get('args') == args_2
assert steps[2].get('args').get('source_path') == args_2.get('source_path')
assert steps[2].get('args').get('target_path') == get_step_output_path('job-test-remix-step', 0, args_1.get('output_path'))
assert steps[2].get('args').get('output_path') == args_2.get('output_path')
assert steps[3].get('args').get('source_path') == args_2.get('source_path')
assert steps[3].get('args').get('target_path') == get_step_output_path('job-test-remix-step', 2, args_2.get('output_path'))
assert steps[3].get('args').get('output_path') == args_2.get('output_path')
assert count_step_total('job-test-remix-step') == 4
def test_insert_step() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
args_2 =\
{
'source_path': 'source-2.jpg',
'target_path': 'target-2.jpg',
'output_path': 'output-2.jpg'
}
args_3 =\
{
'source_path': 'source-3.jpg',
'target_path': 'target-3.jpg',
'output_path': 'output-3.jpg'
}
assert insert_step('job-invalid', 0, args_1) is False
create_job('job-test-insert-step')
add_step('job-test-insert-step', args_1)
add_step('job-test-insert-step', args_1)
assert insert_step('job-test-insert-step', 99, args_1) is False
assert insert_step('job-test-insert-step', 0, args_2) is True
assert insert_step('job-test-insert-step', -1, args_3) is True
steps = get_steps('job-test-insert-step')
assert steps[0].get('args') == args_2
assert steps[1].get('args') == args_1
assert steps[2].get('args') == args_3
assert steps[3].get('args') == args_1
assert count_step_total('job-test-insert-step') == 4
def test_remove_step() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
args_2 =\
{
'source_path': 'source-2.jpg',
'target_path': 'target-2.jpg',
'output_path': 'output-2.jpg'
}
args_3 =\
{
'source_path': 'source-3.jpg',
'target_path': 'target-3.jpg',
'output_path': 'output-3.jpg'
}
assert remove_step('job-invalid', 0) is False
create_job('job-test-remove-step')
add_step('job-test-remove-step', args_1)
add_step('job-test-remove-step', args_2)
add_step('job-test-remove-step', args_1)
add_step('job-test-remove-step', args_3)
assert remove_step('job-test-remove-step', 99) is False
assert remove_step('job-test-remove-step', 0) is True
assert remove_step('job-test-remove-step', -1) is True
steps = get_steps('job-test-remove-step')
assert steps[0].get('args') == args_2
assert steps[1].get('args') == args_1
assert count_step_total('job-test-remove-step') == 2
def test_get_steps() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
args_2 =\
{
'source_path': 'source-2.jpg',
'target_path': 'target-2.jpg',
'output_path': 'output-2.jpg'
}
assert get_steps('job-invalid') == []
create_job('job-test-get-steps')
add_step('job-test-get-steps', args_1)
add_step('job-test-get-steps', args_2)
steps = get_steps('job-test-get-steps')
assert steps[0].get('args') == args_1
assert steps[1].get('args') == args_2
assert count_step_total('job-test-get-steps') == 2
def test_set_step_status() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
args_2 =\
{
'source_path': 'source-2.jpg',
'target_path': 'target-2.jpg',
'output_path': 'output-2.jpg'
}
assert set_step_status('job-invalid', 0, 'completed') is False
create_job('job-test-set-step-status')
add_step('job-test-set-step-status', args_1)
add_step('job-test-set-step-status', args_2)
assert set_step_status('job-test-set-step-status', 99, 'completed') is False
assert set_step_status('job-test-set-step-status', 0, 'completed') is True
assert set_step_status('job-test-set-step-status', 1, 'failed') is True
steps = get_steps('job-test-set-step-status')
assert steps[0].get('status') == 'completed'
assert steps[1].get('status') == 'failed'
assert count_step_total('job-test-set-step-status') == 2
def test_set_steps_status() -> None:
args_1 =\
{
'source_path': 'source-1.jpg',
'target_path': 'target-1.jpg',
'output_path': 'output-1.jpg'
}
args_2 =\
{
'source_path': 'source-2.jpg',
'target_path': 'target-2.jpg',
'output_path': 'output-2.jpg'
}
assert set_steps_status('job-invalid', 'queued') is False
create_job('job-test-set-steps-status')
add_step('job-test-set-steps-status', args_1)
add_step('job-test-set-steps-status', args_2)
assert set_steps_status('job-test-set-steps-status', 'queued') is True
steps = get_steps('job-test-set-steps-status')
assert steps[0].get('status') == 'queued'
assert steps[1].get('status') == 'queued'
assert count_step_total('job-test-set-steps-status') == 2123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276import subprocess
import pytest
from facefusion.download import conditional_download
from facefusion.filesystem import copy_file
from facefusion.jobs.job_manager import add_step, clear_jobs, create_job, init_jobs, move_job_file, submit_job, submit_jobs
from facefusion.jobs.job_runner import collect_output_set, finalize_steps, retry_job, retry_jobs, run_job, run_jobs, run_steps
from facefusion.types import Args
from .helper import get_test_example_file, get_test_examples_directory, get_test_jobs_directory, get_test_output_file, is_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_jobs(get_test_jobs_directory())
init_jobs(get_test_jobs_directory())
prepare_test_output_directory()
def process_step(job_id : str, step_index : int, step_args : Args) -> bool:
return copy_file(step_args.get('target_path'), step_args.get('output_path'))
def test_run_job() -> None:
args_1 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-1.mp4')
}
args_2 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-2.mp4')
}
args_3 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.jpg'),
'output_path': get_test_output_file('output-3.jpg')
}
assert run_job('job-invalid', process_step) is False
create_job('job-test-run-job')
add_step('job-test-run-job', args_1)
add_step('job-test-run-job', args_2)
add_step('job-test-run-job', args_2)
add_step('job-test-run-job', args_3)
assert run_job('job-test-run-job', process_step) is False
submit_job('job-test-run-job')
assert run_job('job-test-run-job', process_step) is True
def test_run_jobs() -> None:
args_1 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-1.mp4')
}
args_2 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-2.mp4')
}
args_3 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.jpg'),
'output_path': get_test_output_file('output-3.jpg')
}
halt_on_error = True
assert run_jobs(process_step, halt_on_error) is False
create_job('job-test-run-jobs-1')
create_job('job-test-run-jobs-2')
add_step('job-test-run-jobs-1', args_1)
add_step('job-test-run-jobs-1', args_1)
add_step('job-test-run-jobs-2', args_2)
add_step('job-test-run-jobs-3', args_3)
assert run_jobs(process_step, halt_on_error) is False
submit_jobs(halt_on_error)
assert run_jobs(process_step, halt_on_error) is True
def test_retry_job() -> None:
args_1 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-1.mp4')
}
assert retry_job('job-invalid', process_step) is False
create_job('job-test-retry-job')
add_step('job-test-retry-job', args_1)
submit_job('job-test-retry-job')
assert retry_job('job-test-retry-job', process_step) is False
move_job_file('job-test-retry-job', 'failed')
assert retry_job('job-test-retry-job', process_step) is True
def test_retry_jobs() -> None:
args_1 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-1.mp4')
}
args_2 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-2.mp4')
}
args_3 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.jpg'),
'output_path': get_test_output_file('output-3.jpg')
}
halt_on_error = True
assert retry_jobs(process_step, halt_on_error) is False
create_job('job-test-retry-jobs-1')
create_job('job-test-retry-jobs-2')
add_step('job-test-retry-jobs-1', args_1)
add_step('job-test-retry-jobs-1', args_1)
add_step('job-test-retry-jobs-2', args_2)
add_step('job-test-retry-jobs-3', args_3)
assert retry_jobs(process_step, halt_on_error) is False
move_job_file('job-test-retry-jobs-1', 'failed')
move_job_file('job-test-retry-jobs-2', 'failed')
assert retry_jobs(process_step, halt_on_error) is True
def test_run_steps() -> None:
args_1 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-1.mp4')
}
args_2 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-2.mp4')
}
args_3 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.jpg'),
'output_path': get_test_output_file('output-3.jpg')
}
assert run_steps('job-invalid', process_step) is False
create_job('job-test-run-steps')
add_step('job-test-run-steps', args_1)
add_step('job-test-run-steps', args_1)
add_step('job-test-run-steps', args_2)
add_step('job-test-run-steps', args_3)
assert run_steps('job-test-run-steps', process_step) is True
def test_finalize_steps() -> None:
args_1 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-1.mp4')
}
args_2 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-2.mp4')
}
args_3 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.jpg'),
'output_path': get_test_output_file('output-3.jpg')
}
create_job('job-test-finalize-steps')
add_step('job-test-finalize-steps', args_1)
add_step('job-test-finalize-steps', args_1)
add_step('job-test-finalize-steps', args_2)
add_step('job-test-finalize-steps', args_3)
copy_file(args_1.get('target_path'), get_test_output_file('output-1-job-test-finalize-steps-0.mp4'))
copy_file(args_1.get('target_path'), get_test_output_file('output-1-job-test-finalize-steps-1.mp4'))
copy_file(args_2.get('target_path'), get_test_output_file('output-2-job-test-finalize-steps-2.mp4'))
copy_file(args_3.get('target_path'), get_test_output_file('output-3-job-test-finalize-steps-3.jpg'))
assert finalize_steps('job-test-finalize-steps') is True
assert is_test_output_file('output-1.mp4') is True
assert is_test_output_file('output-2.mp4') is True
assert is_test_output_file('output-3.jpg') is True
def test_collect_output_set() -> None:
args_1 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-1.mp4')
}
args_2 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.mp4'),
'output_path': get_test_output_file('output-2.mp4')
}
args_3 =\
{
'source_path': get_test_example_file('source.jpg'),
'target_path': get_test_example_file('target-240p.jpg'),
'output_path': get_test_output_file('output-3.jpg')
}
create_job('job-test-collect-output-set')
add_step('job-test-collect-output-set', args_1)
add_step('job-test-collect-output-set', args_1)
add_step('job-test-collect-output-set', args_2)
add_step('job-test-collect-output-set', args_3)
output_set =\
{
get_test_output_file('output-1.mp4'):
[
get_test_output_file('output-1-job-test-collect-output-set-0.mp4'),
get_test_output_file('output-1-job-test-collect-output-set-1.mp4')
],
get_test_output_file('output-2.mp4'):
[
get_test_output_file('output-2-job-test-collect-output-set-2.mp4')
],
get_test_output_file('output-3.jpg'):
[
get_test_output_file('output-3-job-test-collect-output-set-3.jpg')
]
}
assert collect_output_set('job-test-collect-output-set') == output_set12345678910111213141516171819import tempfile
from facefusion.json import read_json, write_json
def test_read_json() -> None:
_, json_path = tempfile.mkstemp(suffix = '.json')
assert not read_json(json_path)
write_json(json_path, {})
assert read_json(json_path) == {}
def test_write_json() -> None:
_, json_path = tempfile.mkstemp(suffix = '.json')
assert write_json(json_path, {})12345678from facefusion.common_helper import is_linux, is_macos
from facefusion.memory import limit_system_memory
def test_limit_system_memory() -> None:
assert limit_system_memory(4) is True
if is_linux() or is_macos():
assert limit_system_memory(1024) is False123456789101112131415161718192021222324from facefusion.normalizer import normalize_color, normalize_fps, normalize_space
def test_normalize_color() -> None:
assert normalize_color([ 0 ]) == (0, 0, 0, 255)
assert normalize_color([ 0, 128 ]) == (0, 128, 0, 255)
assert normalize_color([ 0, 128, 255 ]) == (0, 128, 255, 255)
assert normalize_color([ 0, 128, 255, 0 ]) == (0, 128, 255, 0)
assert normalize_color(None) is None
def test_normalize_space() -> None:
assert normalize_space([ 0, 0, 0, 0 ]) == (0, 0, 0, 0)
assert normalize_space([ 1 ]) == (1, 1, 1, 1)
assert normalize_space([ 1, 2 ]) == (1, 2, 1, 2)
assert normalize_space([ 1, 2, 3 ]) == (1, 2, 3, 2)
assert normalize_space(None) is None
def test_normalize_fps() -> None:
assert normalize_fps(0.0) == 1.0
assert normalize_fps(25.0) == 25.0
assert normalize_fps(61.0) == 60.0
assert normalize_fps(None) is None12345678910111213141516171819202122from facefusion.process_manager import end, is_pending, is_processing, is_stopping, set_process_state, start, stop
def test_start() -> None:
set_process_state('pending')
start()
assert is_processing()
def test_stop() -> None:
set_process_state('processing')
stop()
assert is_stopping()
def test_end() -> None:
set_process_state('processing')
end()
assert is_pending()12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152from argparse import ArgumentParser
from facefusion.program_helper import find_argument_group, validate_actions, validate_args
def test_find_argument_group() -> None:
program = ArgumentParser()
program.add_argument_group('test-1')
program.add_argument_group('test-2')
assert find_argument_group(program, 'test-1')
assert find_argument_group(program, 'test-2')
assert find_argument_group(program, 'test-3') is None
def test_validate_args() -> None:
program = ArgumentParser()
program.add_argument('--test-1', default = 'test_1', choices = [ 'test_1', 'test_2' ])
assert validate_args(program) is True
subparsers = program.add_subparsers()
sub_program = subparsers.add_parser('sub-command')
sub_program.add_argument('--test-2', default = 'test_2', choices = [ 'test_1', 'test_2' ])
assert validate_args(program) is True
for action in sub_program._actions:
if action.dest == 'test_2':
action.default = 'test_3'
assert validate_args(program) is False
def test_validate_actions() -> None:
program = ArgumentParser()
program.add_argument('--test-1', default = 'test_1', choices = [ 'test_1', 'test_2' ])
program.add_argument('--test-2', default = 'test_2', choices= [ 'test_1', 'test_2' ], nargs = '+')
assert validate_actions(program) is True
args =\
{
'test_1': 'test_2',
'test_2': [ 'test_1', 'test_3' ]
}
for action in program._actions:
if action.dest in args:
action.default = args[action.dest]
assert validate_actions(program) is False12345678from facefusion.sanitizer import sanitize_int_range
def test_sanitize_int_range() -> None:
assert sanitize_int_range(0, [ 0, 1, 2 ]) == 0
assert sanitize_int_range(2, [0, 1, 2]) == 2
assert sanitize_int_range(-1, [ 0, 1 ]) == 0
assert sanitize_int_range(3, [ 0, 1 ]) == 01234567891011121314151617181920212223242526272829303132333435from typing import Union
import pytest
from facefusion.processors.types import ProcessorState
from facefusion.state_manager import STATE_SET, get_item, init_item, set_item
from facefusion.types import AppContext, State
def get_state(app_context : AppContext) -> Union[State, ProcessorState]:
return STATE_SET.get(app_context)
def clear_state(app_context : AppContext) -> None:
STATE_SET[app_context] = {} #type:ignore[typeddict-item]
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
clear_state('cli')
clear_state('ui')
def test_init_item() -> None:
init_item('video_memory_strategy', 'tolerant')
assert get_state('cli').get('video_memory_strategy') == 'tolerant'
assert get_state('ui').get('video_memory_strategy') == 'tolerant'
def test_get_item_and_set_item() -> None:
set_item('video_memory_strategy', 'tolerant')
assert get_item('video_memory_strategy') == 'tolerant'
assert get_state('ui').get('video_memory_strategy') is None12345678910111213141516171819202122232425262728293031323334import os.path
import tempfile
import pytest
from facefusion import state_manager
from facefusion.download import conditional_download
from facefusion.temp_helper import get_temp_directory_path, get_temp_file_path, get_temp_frames_pattern
from .helper import get_test_example_file, get_test_examples_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
state_manager.init_item('temp_path', tempfile.gettempdir())
state_manager.init_item('temp_frame_format', 'png')
def test_get_temp_file_path() -> None:
temp_directory = tempfile.gettempdir()
assert get_temp_file_path(get_test_example_file('target-240p.mp4')) == os.path.join(temp_directory, 'facefusion', 'target-240p', 'temp.mp4')
def test_get_temp_directory_path() -> None:
temp_directory = tempfile.gettempdir()
assert get_temp_directory_path(get_test_example_file('target-240p.mp4')) == os.path.join(temp_directory, 'facefusion', 'target-240p')
def test_get_temp_frames_pattern() -> None:
temp_directory = tempfile.gettempdir()
assert get_temp_frames_pattern(get_test_example_file('target-240p.mp4'), '%04d') == os.path.join(temp_directory, 'facefusion', 'target-240p', '%04d.png')123456789101112131415from datetime import datetime, timedelta
from facefusion.time_helper import describe_time_ago
def get_time_ago(days : int, hours : int, minutes : int) -> datetime:
previous_time = datetime.now() - timedelta(days = days, hours = hours, minutes = minutes)
return previous_time.astimezone()
def test_describe_time_ago() -> None:
assert describe_time_ago(get_time_ago(0, 0, 0)) == 'just now'
assert describe_time_ago(get_time_ago(0, 0, 10)) == '10 minutes ago'
assert describe_time_ago(get_time_ago(0, 5, 10)) == '5 hours and 10 minutes ago'
assert describe_time_ago(get_time_ago(1, 5, 10)) == '1 days, 5 hours and 10 minutes ago'1234567891011121314from facefusion import translator
from facefusion.locales import LOCALES
def test_load() -> None:
translator.load(LOCALES, __name__)
assert __name__ in translator.LOCALE_POOL_SET
def test_get() -> None:
assert translator.get('conda_not_activated') == 'conda is not activated'
assert translator.get('help.skip_conda') == 'skip the conda environment check'
assert translator.get('invalid') is None123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169import subprocess
import pytest
from facefusion.download import conditional_download
from facefusion.vision import calculate_histogram_difference, count_trim_frame_total, count_video_frame_total, detect_image_resolution, detect_video_duration, detect_video_fps, detect_video_resolution, match_frame_color, normalize_resolution, pack_resolution, predict_video_frame_total, read_image, read_video_frame, restrict_image_resolution, restrict_trim_frame, restrict_video_fps, restrict_video_resolution, scale_resolution, unpack_resolution, write_image
from .helper import get_test_example_file, get_test_examples_directory, get_test_output_file, prepare_test_output_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4',
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-1080p.mp4'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('target-240p.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', get_test_example_file('目标-240p.webp') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-1080p.mp4'), '-vframes', '1', get_test_example_file('target-1080p.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', '-vf', 'hue=s=0', get_test_example_file('target-240p-0sat.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vframes', '1', '-vf', 'transpose=0', get_test_example_file('target-240p-90deg.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-1080p.mp4'), '-vframes', '1', '-vf', 'transpose=0', get_test_example_file('target-1080p-90deg.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=25', get_test_example_file('target-240p-25fps.mp4') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=30', get_test_example_file('target-240p-30fps.mp4') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=60', get_test_example_file('target-240p-60fps.mp4') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'transpose=0', get_test_example_file('target-240p-90deg.mp4') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-1080p.mp4'), '-vf', 'transpose=0', get_test_example_file('target-1080p-90deg.mp4') ])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
prepare_test_output_directory()
def test_read_image() -> None:
assert read_image(get_test_example_file('target-240p.jpg')).shape == (226, 426, 3)
assert read_image(get_test_example_file('目标-240p.webp')).shape == (226, 426, 3)
assert read_image('invalid') is None
def test_write_image() -> None:
vision_frame = read_image(get_test_example_file('target-240p.jpg'))
assert write_image(get_test_output_file('target-240p.jpg'), vision_frame) is True
assert write_image(get_test_output_file('目标-240p.webp'), vision_frame) is True
def test_detect_image_resolution() -> None:
assert detect_image_resolution(get_test_example_file('target-240p.jpg')) == (426, 226)
assert detect_image_resolution(get_test_example_file('target-240p-90deg.jpg')) == (226, 426)
assert detect_image_resolution(get_test_example_file('target-1080p.jpg')) == (2048, 1080)
assert detect_image_resolution(get_test_example_file('target-1080p-90deg.jpg')) == (1080, 2048)
assert detect_image_resolution('invalid') is None
def test_restrict_image_resolution() -> None:
assert restrict_image_resolution(get_test_example_file('target-1080p.jpg'), (426, 226)) == (426, 226)
assert restrict_image_resolution(get_test_example_file('target-1080p.jpg'), (2048, 1080)) == (2048, 1080)
assert restrict_image_resolution(get_test_example_file('target-1080p.jpg'), (4096, 2160)) == (2048, 1080)
def test_read_video_frame() -> None:
assert hasattr(read_video_frame(get_test_example_file('target-240p-25fps.mp4')), '__array_interface__')
assert read_video_frame('invalid') is None
def test_count_video_frame_total() -> None:
assert count_video_frame_total(get_test_example_file('target-240p-25fps.mp4')) == 270
assert count_video_frame_total(get_test_example_file('target-240p-30fps.mp4')) == 324
assert count_video_frame_total(get_test_example_file('target-240p-60fps.mp4')) == 648
assert count_video_frame_total('invalid') == 0
def test_predict_video_frame_total() -> None:
assert predict_video_frame_total(get_test_example_file('target-240p-25fps.mp4'), 12.5, 0, 100) == 50
assert predict_video_frame_total(get_test_example_file('target-240p-25fps.mp4'), 25, 0, 100) == 100
assert predict_video_frame_total(get_test_example_file('target-240p-25fps.mp4'), 25, 0, 200) == 200
assert predict_video_frame_total('invalid', 25, 0, 100) == 0
def test_detect_video_fps() -> None:
assert detect_video_fps(get_test_example_file('target-240p-25fps.mp4')) == 25.0
assert detect_video_fps(get_test_example_file('target-240p-30fps.mp4')) == 30.0
assert detect_video_fps(get_test_example_file('target-240p-60fps.mp4')) == 60.0
assert detect_video_fps('invalid') is None
def test_restrict_video_fps() -> None:
assert restrict_video_fps(get_test_example_file('target-1080p.mp4'), 20.0) == 20.0
assert restrict_video_fps(get_test_example_file('target-1080p.mp4'), 25.0) == 25.0
assert restrict_video_fps(get_test_example_file('target-1080p.mp4'), 60.0) == 25.0
def test_detect_video_duration() -> None:
assert detect_video_duration(get_test_example_file('target-240p.mp4')) == 10.8
assert detect_video_duration('invalid') == 0
def test_count_trim_frame_total() -> None:
assert count_trim_frame_total(get_test_example_file('target-240p.mp4'), 0, 200) == 200
assert count_trim_frame_total(get_test_example_file('target-240p.mp4'), 70, 270) == 200
assert count_trim_frame_total(get_test_example_file('target-240p.mp4'), -10, None) == 270
assert count_trim_frame_total(get_test_example_file('target-240p.mp4'), None, -10) == 0
assert count_trim_frame_total(get_test_example_file('target-240p.mp4'), 280, None) == 0
assert count_trim_frame_total(get_test_example_file('target-240p.mp4'), None, 280) == 270
assert count_trim_frame_total(get_test_example_file('target-240p.mp4'), None, None) == 270
def test_restrict_trim_frame() -> None:
assert restrict_trim_frame(get_test_example_file('target-240p.mp4'), 0, 200) == (0, 200)
assert restrict_trim_frame(get_test_example_file('target-240p.mp4'), 70, 270) == (70, 270)
assert restrict_trim_frame(get_test_example_file('target-240p.mp4'), -10, None) == (0, 270)
assert restrict_trim_frame(get_test_example_file('target-240p.mp4'), None, -10) == (0, 0)
assert restrict_trim_frame(get_test_example_file('target-240p.mp4'), 280, None) == (270, 270)
assert restrict_trim_frame(get_test_example_file('target-240p.mp4'), None, 280) == (0, 270)
assert restrict_trim_frame(get_test_example_file('target-240p.mp4'), None, None) == (0, 270)
def test_detect_video_resolution() -> None:
assert detect_video_resolution(get_test_example_file('target-240p.mp4')) == (426, 226)
assert detect_video_resolution(get_test_example_file('target-240p-90deg.mp4')) == (226, 426)
assert detect_video_resolution(get_test_example_file('target-1080p.mp4')) == (2048, 1080)
assert detect_video_resolution(get_test_example_file('target-1080p-90deg.mp4')) == (1080, 2048)
assert detect_video_resolution('invalid') is None
def test_restrict_video_resolution() -> None:
assert restrict_video_resolution(get_test_example_file('target-1080p.mp4'), (426, 226)) == (426, 226)
assert restrict_video_resolution(get_test_example_file('target-1080p.mp4'), (2048, 1080)) == (2048, 1080)
assert restrict_video_resolution(get_test_example_file('target-1080p.mp4'), (4096, 2160)) == (2048, 1080)
def test_scale_resolution() -> None:
assert scale_resolution((426, 226), 0.5) == (212, 112)
assert scale_resolution((2048, 1080), 1.0) == (2048, 1080)
assert scale_resolution((4096, 2160), 2.0) == (8192, 4320)
def test_normalize_resolution() -> None:
assert normalize_resolution((2.5, 2.5)) == (2, 2)
assert normalize_resolution((3.0, 3.0)) == (4, 4)
assert normalize_resolution((6.5, 6.5)) == (6, 6)
def test_pack_resolution() -> None:
assert pack_resolution((1, 1)) == '0x0'
assert pack_resolution((2, 2)) == '2x2'
def test_unpack_resolution() -> None:
assert unpack_resolution('0x0') == (0, 0)
assert unpack_resolution('2x2') == (2, 2)
def test_calc_histogram_difference() -> None:
source_vision_frame = read_image(get_test_example_file('target-240p.jpg'))
target_vision_frame = read_image(get_test_example_file('target-240p-0sat.jpg'))
assert calculate_histogram_difference(source_vision_frame, source_vision_frame) == 1.0
assert calculate_histogram_difference(source_vision_frame, target_vision_frame) < 0.5
def test_match_frame_color() -> None:
source_vision_frame = read_image(get_test_example_file('target-240p.jpg'))
target_vision_frame = read_image(get_test_example_file('target-240p-0sat.jpg'))
output_vision_frame = match_frame_color(source_vision_frame, target_vision_frame)
assert calculate_histogram_difference(source_vision_frame, output_vision_frame) > 0.5tests/__init__.pyDeleted
tests/helper.pyDeleted-44
tests/test_audio.pyDeleted-28
tests/test_cli_age_modifier.pyDeleted-38
tests/test_cli_background_remover.pyDeleted-39
tests/test_cli_batch_runner.pyDeleted-45
tests/test_cli_expression_restorer.pyDeleted-38
tests/test_cli_face_debugger.pyDeleted-39
tests/test_cli_face_editor.pyDeleted-39
tests/test_cli_face_enhancer.pyDeleted-39
tests/test_cli_face_swapper.pyDeleted-39
tests/test_cli_frame_colorizer.pyDeleted-40
tests/test_cli_frame_enhancer.pyDeleted-39
tests/test_cli_job_manager.pyDeleted-209
tests/test_cli_job_runner.pyDeleted-147
tests/test_cli_lip_syncer.pyDeleted-40
tests/test_cli_output_scale.pyDeleted-57
tests/test_common_helper.pyDeleted-27
tests/test_config.pyDeleted-85
tests/test_curl_builder.pyDeleted-17
tests/test_download.pyDeleted-18
tests/test_execution.pyDeleted-24
tests/test_face_analyser.pyDeleted-131
tests/test_ffmpeg.pyDeleted-189
tests/test_ffmpeg_builder.pyDeleted-110
tests/test_filesystem.pyDeleted-135
tests/test_inference_manager.pyDeleted-32
tests/test_job_helper.pyDeleted-9
tests/test_job_list.pyDeleted-24
tests/test_job_manager.pyDeleted-386
tests/test_job_runner.pyDeleted-276
tests/test_json.pyDeleted-19
tests/test_memory.pyDeleted-8
tests/test_normalizer.pyDeleted-24
tests/test_process_manager.pyDeleted-22
tests/test_program_helper.pyDeleted-52
tests/test_sanitizer.pyDeleted-8
tests/test_state_manager.pyDeleted-35
tests/test_temp_helper.pyDeleted-34
tests/test_time_helper.pyDeleted-15
tests/test_translator.pyDeleted-14
tests/test_vision.pyDeleted-169