2019-04-24 11:58:55 +02:00
|
|
|
import os
|
|
|
|
|
|
2021-07-12 18:26:25 +02:00
|
|
|
from TTS.config import BaseDatasetConfig
|
2021-05-10 15:24:34 +02:00
|
|
|
from TTS.utils.generic_utils import get_cuda
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_device_id():
|
|
|
|
|
use_cuda, _ = get_cuda()
|
|
|
|
|
if use_cuda:
|
2021-09-10 08:28:10 +00:00
|
|
|
if "CUDA_VISIBLE_DEVICES" in os.environ and os.environ["CUDA_VISIBLE_DEVICES"] != "":
|
|
|
|
|
GPU_ID = os.environ["CUDA_VISIBLE_DEVICES"].split(",")[0]
|
2021-09-06 14:29:22 +00:00
|
|
|
else:
|
|
|
|
|
GPU_ID = "0"
|
2021-05-10 15:24:34 +02:00
|
|
|
else:
|
|
|
|
|
GPU_ID = ""
|
|
|
|
|
return GPU_ID
|
|
|
|
|
|
2019-04-24 11:58:55 +02:00
|
|
|
|
|
|
|
|
def get_tests_path():
|
|
|
|
|
"""Returns the path to the test directory."""
|
|
|
|
|
return os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_tests_input_path():
|
|
|
|
|
"""Returns the path to the test data directory."""
|
|
|
|
|
return os.path.join(get_tests_path(), "inputs")
|
|
|
|
|
|
|
|
|
|
|
2022-01-12 11:37:02 +00:00
|
|
|
def get_tests_data_path():
|
|
|
|
|
"""Returns the path to the test data directory."""
|
|
|
|
|
return os.path.join(get_tests_path(), "data")
|
|
|
|
|
|
|
|
|
|
|
2019-04-24 11:58:55 +02:00
|
|
|
def get_tests_output_path():
|
|
|
|
|
"""Returns the path to the directory for test outputs."""
|
2022-10-10 13:32:27 +02:00
|
|
|
path = os.path.join(get_tests_path(), "outputs")
|
|
|
|
|
os.makedirs(path, exist_ok=True)
|
|
|
|
|
return path
|
2021-04-27 14:10:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_cli(command):
|
|
|
|
|
exit_status = os.system(command)
|
|
|
|
|
assert exit_status == 0, f" [!] command `{command}` failed."
|
2021-07-12 18:26:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_test_data_config():
|
2022-09-13 14:10:33 +02:00
|
|
|
return BaseDatasetConfig(formatter="ljspeech", path="tests/data/ljspeech/", meta_file_train="metadata.csv")
|
2021-12-30 12:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def assertHasAttr(test_obj, obj, intendedAttr):
|
|
|
|
|
# from https://stackoverflow.com/questions/48078636/pythons-unittest-lacks-an-asserthasattr-method-what-should-i-use-instead
|
|
|
|
|
testBool = hasattr(obj, intendedAttr)
|
|
|
|
|
test_obj.assertTrue(testBool, msg=f"obj lacking an attribute. obj: {obj}, intendedAttr: {intendedAttr}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def assertHasNotAttr(test_obj, obj, intendedAttr):
|
|
|
|
|
testBool = hasattr(obj, intendedAttr)
|
|
|
|
|
test_obj.assertFalse(testBool, msg=f"obj should not have an attribute. obj: {obj}, intendedAttr: {intendedAttr}")
|