lib package
Subpackages
sysinfo module
Unit tests for sysinfo
module
Module
Pytest unit tests for lib.sysinfo
- tests.lib.sysinfo_test.configs_fixture()
Pytest fixture for
_Configs
- Returns:
The class instance for testing
- Return type:
_Configs
- tests.lib.sysinfo_test.state_fixture()
Pytest fixture for
_State
- Returns:
The class instance for testing
- Return type:
_State
- tests.lib.sysinfo_test.sys_info_fixture() _SysInfo
Single :class:~`lib.utils._SysInfo` object for tests
- Returns:
The class instance for testing
- Return type:
_SysInfo
- tests.lib.sysinfo_test.test__configs__format_text(configs_instance: _Configs) None
Test _format_text function for
_Configs
- Parameters:
configs_instance (
_Configs
) – The class instance to test
- tests.lib.sysinfo_test.test__configs__get_configs(configs_instance: _Configs) None
Test __init__ and attributes for
_Configs
- Parameters:
configs_instance (
_Configs
) – The class instance to test
- tests.lib.sysinfo_test.test__configs__init__(configs_instance: _Configs) None
Test __init__ and attributes for
_Configs
- Parameters:
configs_instance (
_Configs
) – The class instance to test
- tests.lib.sysinfo_test.test__configs__parse_configs(configs_instance: _Configs, mocker: MockerFixture) None
Test _parse_configs function for
_Configs
- Parameters:
configs_instance (
_Configs
) – The class instance to testmocker (
pytest_mock.MockerFixture
) – Mocker for dummying in function calls
- tests.lib.sysinfo_test.test__configs__parse_ini(configs_instance: _Configs, monkeypatch: MonkeyPatch) None
Test _parse_ini function for
_Configs
- Parameters:
configs_instance (
_Configs
) – The class instance to testmonkeypatch (
pytest.MonkeyPatch
) – Monkey patchingbuiltins.open()
to dummy in ini file
- tests.lib.sysinfo_test.test__configs__parse_json(configs_instance: _Configs, monkeypatch: MonkeyPatch) None
Test _parse_json function for
_Configs
- Parameters:
configs_instance (
_Configs
) – The class instance to testmonkeypatch (
pytest.MonkeyPatch
) – Monkey patchingbuiltins.open()
to dummy in json file
- tests.lib.sysinfo_test.test__format_ram(sys_info_instance: _SysInfo, monkeypatch: MonkeyPatch) None
Test the _format_ram method of
_SysInfo
returns as expected- Parameters:
sys_info_instance (
_SysInfo
) – The class instance to testmonkeypatch (
pytest.MonkeyPatch
) – Monkey patching psutil.virtual_memory to be consistent
- tests.lib.sysinfo_test.test__state__get_arg(state_instance: _State, monkeypatch: MonkeyPatch) None
Test _get_arg function for
_State
- Parameters:
state_instance (
_State
) – The class instance to testmonkeypatch (
pytest.MonkeyPatch
) – Monkey patchingsys.argv()
to dummy in commandline argsbuiltins.input()
- tests.lib.sysinfo_test.test__state__get_state_file(state_instance: _State, mocker: MockerFixture, monkeypatch: MonkeyPatch) None
Test _get_state_file function for
_State
- state_instance:
_State
The class instance to test
- mocker:
pytest_mock.MockerFixture
Mocker for dummying in function calls
- monkeypatch:
pytest.MonkeyPatch
Monkey patching
sys.argv()
to dummy in commandline argsbuiltins.input()
- state_instance:
- tests.lib.sysinfo_test.test__state__init__(state_instance: _State) None
Test __init__ and attributes for
_State
- Parameters:
state_instance (
_State
) – The class instance to test
- tests.lib.sysinfo_test.test__state__is_training(state_instance: _State, monkeypatch: MonkeyPatch) None
Test _is_training function for
_State
- Parameters:
state_instance (
_State
) – The class instance to testmonkeypatch (
pytest.MonkeyPatch
) – Monkey patchingsys.argv()
to dummy in commandline args
- tests.lib.sysinfo_test.test_full_info(sys_info_instance: _SysInfo) None
Test the sys_info method of
_SysInfo
returns as expected- Parameters:
sys_info_instance (
_SysInfo
) – The class instance to test
- tests.lib.sysinfo_test.test_get_sys_info(mocker: MockerFixture) None
Thest that the
get_sysinfo()
function executes correctly- Parameters:
mocker (
pytest_mock.MockerFixture
) – Mocker for checking full_info called from _SysInfo
- tests.lib.sysinfo_test.test_init(sys_info_instance: _SysInfo) None
Test
_SysInfo
__init__ and attributes- Parameters:
sys_info_instance (
_SysInfo
) – The class instance to test
- tests.lib.sysinfo_test.test_properties(sys_info_instance: _SysInfo) None
Test
_SysInfo
properties- Parameters:
sys_info_instance (
_SysInfo
) – The class instance to test
utils_test module
Unit tests for utils
module
Module
Pytest unit tests for lib.utils
- tests.lib.utils_test.fixture_get_model_instance(monkeypatch: MonkeyPatch, tmp_path: TempdirFactory, request: FixtureRequest) GetModel
Create a fixture of the
GetModel
object, prevent _get() from running at __init__ and point the cache_dir at our local test folder
- tests.lib.utils_test.test__backend(monkeypatch: MonkeyPatch) None
Test the
_Backend
class- Parameters:
monkeypatch (
pytest.MonkeyPatch
) – Monkey patchingos.environ()
,os.path.isfile()
,builtins.open()
andbuiltins.input()
- tests.lib.utils_test.test_camel_case_split(text: str, result: list[str]) None
Test the
camel_case_spli()
function works correctly- Parameters:
text (str) – The camel case text to test
result (list) – The expected result from the path
- tests.lib.utils_test.test_convert_to_secs(args: tuple[int, ...], result: int) None
Test the
convert_to_secs()
function works correctly- Parameters:
args (tuple) – Tuple of 1, 2 or 3 integers to pass to the function
result (int) – The expected results for the args tuple
- tests.lib.utils_test.test_debug_times()
Test
DebugTimes
executes its logic correctly
- tests.lib.utils_test.test_deprecation_warning(caplog: LogCaptureFixture, additional_info: str) None
Test the
deprecation_warning()
function works correctly- Parameters:
caplog (
pytest.LogCaptureFixture
) – Pytest’s log capturing fixtureadditional_info (str) – Additional information to pass to the warning function
- tests.lib.utils_test.test_faceswap_error()
Test the
FaceswapError
raises correctly
- tests.lib.utils_test.test_full_path_split(path: str, result: list[str]) None
Test the
full_path_split()
function works correctly- Parameters:
path (str) – The path to test
result (list) – The expected result from the path
- tests.lib.utils_test.test_get_backend(monkeypatch: MonkeyPatch) None
Test the
get_backend()
function- Parameters:
monkeypatch (
pytest.MonkeyPatch
) – Monkey patching _FS_BACKEND
- tests.lib.utils_test.test_get_dpi() None
Test the
get_dpi()
function version returns correctly in a sane range
- tests.lib.utils_test.test_get_folder(tmp_path: str) None
Unit test for
get_folder()
- Parameters:
tmp_path (str) – pytest temporary path to generate folders
- tests.lib.utils_test.test_get_image_paths(tmp_path: str) None
Unit test for
test_get_image_paths()
- Parameters:
tmp_path (str) – pytest temporary path to generate folders
- tests.lib.utils_test.test_get_model__download_model(mocker: MockerFixture, get_model_instance: GetModel, error_type: Any, error_args: tuple[str | int, ...]) None
Test
_download_model()
executes its logic correctly- Parameters:
mocker (
pytest_mock.MockerFixture
) – Mocker for dummying in function callsget_model_instance (~lib.utils.GetModel) – The patched instance of the class
error_type (connection error type or
None
) – Connection error type to mock, orNone
for succesful downloaderror_args (tuple) – The arguments to be passed to the exception to be raised
- tests.lib.utils_test.test_get_model__get(mocker: MockerFixture, get_model_instance: GetModel, model_exists: bool) None
Test
_get()
executes logic correctly- Parameters:
mocker (
pytest_mock.MockerFixture
) – Mocker for dummying in function callsget_model_instance (~lib.utils.GetModel) – The patched instance of the class
model_exists (bool) – For testing the function when a model exists and when it does not
- tests.lib.utils_test.test_get_model__unzip_model(mocker: MockerFixture, get_model_instance: GetModel) None
Test
_unzip_model()
executes its logic correctly- Parameters:
mocker (
pytest_mock.MockerFixture
) – Mocker for dummying in function callsget_model_instance (~lib.utils.GetModel) – The patched instance of the class
- tests.lib.utils_test.test_get_model__write_model(mocker: MockerFixture, get_model_instance: GetModel) None
Test
_write_model()
executes its logic correctly- Parameters:
mocker (
pytest_mock.MockerFixture
) – Mocker for dummying in function callsget_model_instance (~lib.utils.GetModel) – The patched instance of the class
- tests.lib.utils_test.test_get_model__write_zipfile(mocker: MockerFixture, get_model_instance: GetModel, dl_type: str) None
Test
_write_zipfile()
executes its logic correctly- Parameters:
mocker (
pytest_mock.MockerFixture
) – Mocker for dummying in function callsget_model_instance (~lib.utils.GetModel) – The patched instance of the class
dl_type (str) – The type of read to attemp
- tests.lib.utils_test.test_get_model_attributes(get_model_instance: GetModel) None
Test
GetModel
private attributes set correctly- Parameters:
get_model_instance (~lib.utils.GetModel) – The patched instance of the class
- tests.lib.utils_test.test_get_model_model_filename_input(get_model_instance: GetModel, filename: str | list[str], results: str | list[str]) None
Test
GetModel
filename parsing works- Parameters:
get_model_instance (~lib.utils.GetModel) – The patched instance of the class
filename (list or str) – The test filenames
results (tuple) –
- The expected results for
_model_filename
,_model_full_name
, _model_name
,_model_version
respectively
- The expected results for
- tests.lib.utils_test.test_get_model_properties(get_model_instance: GetModel) None
Test
GetModel
calculated attributes return correctly- Parameters:
get_model_instance (~lib.utils.GetModel) – The patched instance of the class
- tests.lib.utils_test.test_get_tf_version() None
Test the
get_tf_version()
function version returns correctly in range
- tests.lib.utils_test.test_safe_shutdown(caplog: LogCaptureFixture, got_error: bool) None
Test the
safe_shutdown()
function works correctly- Parameters:
caplog (
pytest.LogCaptureFixture
) – Pytest’s log capturing fixturegot_error (bool) – The got_error parameter to pass to safe_shutdown
- tests.lib.utils_test.test_set_backend(monkeypatch: MonkeyPatch) None
Test the
set_backend()
function- Parameters:
monkeypatch (
pytest.MonkeyPatch
) – Monkey patching _FS_BACKEND
- tests.lib.utils_test.test_set_system_verbosity(log_level: str) None
Test the
set_system_verbosity()
function works correctly- Parameters:
log_level (str) – The logging loglevel in upper text format