aboutsummaryrefslogtreecommitdiff
path: root/lib/tests/test_engines.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/test_engines.py')
-rw-r--r--lib/tests/test_engines.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/tests/test_engines.py b/lib/tests/test_engines.py
index 0efccc6..781b46e 100644
--- a/lib/tests/test_engines.py
+++ b/lib/tests/test_engines.py
@@ -1,8 +1,68 @@
import os
+import sys
+import types
+import warnings
import numpy as np
import pytest
+AUDIO_META_MSG = (
+ "`torchaudio.backend.common.AudioMetaData` has been moved to "
+ "`torchaudio.AudioMetaData`. Please update the import path."
+)
+
+
+def _stub_df_modules(calls: list[str]) -> tuple[types.ModuleType, list[types.ModuleType]]:
+ pkg = types.ModuleType("df")
+ mods = []
+ for full in ("df.utils", "df.logger", "df.io"):
+ mod = types.ModuleType(full)
+
+ def probe(name: str):
+ def fn(*_args):
+ calls.append(name)
+ return "deadbeef"
+
+ return fn
+
+ for fn_name in ("get_git_root", "get_commit_hash", "get_branch_name"):
+ setattr(mod, fn_name, probe(f"{full}.{fn_name}"))
+ setattr(pkg, full.split(".")[1], mod)
+ mods.append(mod)
+ return pkg, mods
+
+
+def test_dfn_shim_neutralizes_git_probes(monkeypatch):
+ from producer.engines import denoise_dfn
+
+ calls: list[str] = []
+ pkg, mods = _stub_df_modules(calls)
+ for name, mod in zip(("df", "df.utils", "df.logger", "df.io"), (pkg, *mods), strict=True):
+ monkeypatch.setitem(sys.modules, name, mod)
+ assert pkg.logger.get_commit_hash() == "deadbeef"
+ calls.clear()
+ denoise_dfn._shim_df_git()
+ for mod in mods:
+ for fn_name in ("get_git_root", "get_commit_hash", "get_branch_name"):
+ assert mod.__dict__[fn_name]() is None
+ assert calls == []
+
+
+def test_dfn_shim_silences_torchaudio_warning():
+ from producer.engines import denoise_dfn
+
+ code = "import warnings\nwarnings.warn(MESSAGE, UserWarning)"
+ denoise_dfn._shim_torchaudio_backend()
+ with warnings.catch_warnings(record=True) as caught:
+ exec(compile(code, "df/io.py", "exec"), {"__name__": "df.io", "MESSAGE": AUDIO_META_MSG})
+ assert caught == []
+ with warnings.catch_warnings(record=True) as caught:
+ exec(
+ compile(code, "other/mod.py", "exec"),
+ {"__name__": "other.mod", "MESSAGE": AUDIO_META_MSG},
+ )
+ assert len(caught) == 1
+
def _metrics_floor(x, sr):
from producer import meters