diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_case.py b/test/test_case.py new file mode 100644 index 0000000..efbf7ef --- /dev/null +++ b/test/test_case.py @@ -0,0 +1,48 @@ +import os +from pathlib import Path +import shutil +import tempfile +import typing as T +import warnings +import unittest + + +class TestCase(unittest.TestCase): + """ + Base class for tests. + """ + + # Where checked-in test data is stored + TEST_DATA_PATH = Path(__file__).resolve().parent / "test_data" + + # Whether to run tests in debug mode (e.g. don't clean up temporary directories, show plots) + DEBUG = bool(os.environ.get("RIFFUSION_TEST_DEBUG")) + + # Which torch device to use for tests + DEVICE = os.environ.get("RIFFUSION_TEST_DEVICE", "cuda") + + @staticmethod + def main(*args: T.Any, **kwargs: T.Any) -> None: + """ + Run the tests. + """ + unittest.main(*args, **kwargs) + + @classmethod + def setUpClass(cls): + warnings.filterwarnings("ignore", category=ResourceWarning) + + def get_tmp_dir(self, prefix: str) -> Path: + """ + Create a temporary directory. + """ + tmp_dir = tempfile.mkdtemp(prefix=prefix) + + # Clean up the temporary directory if not debugging + if not self.DEBUG: + self.addCleanup(lambda: shutil.rmtree(tmp_dir, ignore_errors=True)) + + dir_path = Path(tmp_dir) + assert dir_path.is_dir() + + return dir_path diff --git a/test/test_data/README.md b/test/test_data/README.md new file mode 100644 index 0000000..78ee70c --- /dev/null +++ b/test/test_data/README.md @@ -0,0 +1,7 @@ +# Test Data + +### tired_traveler + +* Song: Tired traveler on the way to home +* Artist: Andrew Codeman +* Source: https://freemusicarchive.org/ diff --git a/test/test_data/tired_traveler/clips/clip_0_start_15795_ms_duration_5678_ms.wav b/test/test_data/tired_traveler/clips/clip_0_start_15795_ms_duration_5678_ms.wav new file mode 100644 index 0000000..28d21a9 Binary files /dev/null and b/test/test_data/tired_traveler/clips/clip_0_start_15795_ms_duration_5678_ms.wav differ diff --git a/test/test_data/tired_traveler/clips/clip_1_start_860_ms_duration_5678_ms.wav b/test/test_data/tired_traveler/clips/clip_1_start_860_ms_duration_5678_ms.wav new file mode 100644 index 0000000..846b363 Binary files /dev/null and b/test/test_data/tired_traveler/clips/clip_1_start_860_ms_duration_5678_ms.wav differ diff --git a/test/test_data/tired_traveler/clips/clip_2_start_103694_ms_duration_5678_ms.wav b/test/test_data/tired_traveler/clips/clip_2_start_103694_ms_duration_5678_ms.wav new file mode 100644 index 0000000..94d0cc8 Binary files /dev/null and b/test/test_data/tired_traveler/clips/clip_2_start_103694_ms_duration_5678_ms.wav differ diff --git a/test/test_data/tired_traveler/images/clip_2_start_103694_ms_duration_5678_ms.png b/test/test_data/tired_traveler/images/clip_2_start_103694_ms_duration_5678_ms.png new file mode 100644 index 0000000..8c0ce47 Binary files /dev/null and b/test/test_data/tired_traveler/images/clip_2_start_103694_ms_duration_5678_ms.png differ diff --git a/test/test_data/tired_traveler/images/clip_2_start_103694_ms_duration_5678_ms_stereo.png b/test/test_data/tired_traveler/images/clip_2_start_103694_ms_duration_5678_ms_stereo.png new file mode 100644 index 0000000..2039edd Binary files /dev/null and b/test/test_data/tired_traveler/images/clip_2_start_103694_ms_duration_5678_ms_stereo.png differ diff --git a/test/test_data/tired_traveler/tired_traveler.mp3 b/test/test_data/tired_traveler/tired_traveler.mp3 new file mode 100644 index 0000000..686cc6c Binary files /dev/null and b/test/test_data/tired_traveler/tired_traveler.mp3 differ