from types import SimpleNamespace from da3_compat import resolve_da3_class def test_da3_resolver_prefers_api_module(): marker = object() modules = {"depth_anything_3.api": SimpleNamespace(DepthAnything3=marker)} def importer(location): if location not in modules: raise ModuleNotFoundError(location) return modules[location] cls, location = resolve_da3_class(importer) assert cls is marker assert location == "depth_anything_3.api" def test_da3_resolver_supports_package_root_and_reports_failures(): marker = object() modules = {"depth_anything_3": SimpleNamespace(DepthAnything3=marker)} def importer(location): if location not in modules: raise ModuleNotFoundError(location) return modules[location] cls, location = resolve_da3_class(importer) assert cls is marker assert location == "depth_anything_3" try: resolve_da3_class(lambda location: (_ for _ in ()).throw(ModuleNotFoundError(location))) except ImportError as exc: assert "depth_anything_3.api" in str(exc) assert "depth_anything_3" in str(exc) else: raise AssertionError("missing DA3 modules should raise ImportError")