From c18bdde706c4553ee6c01886196b2995ead9da21 Mon Sep 17 00:00:00 2001 From: Caitlyn O'Hanna Date: Wed, 11 Jun 2025 11:12:37 -0700 Subject: [PATCH] Add tests for require_module --- tests/test_optional_dependencies.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/test_optional_dependencies.py diff --git a/tests/test_optional_dependencies.py b/tests/test_optional_dependencies.py new file mode 100644 index 0000000..554ac3d --- /dev/null +++ b/tests/test_optional_dependencies.py @@ -0,0 +1,15 @@ +import types +import pytest + +from layerforge.utils.optional_dependencies import require_module + + +def test_require_module_success(): + mod = require_module("math", "Test") + assert isinstance(mod, types.ModuleType) + + +def test_require_module_missing(): + with pytest.raises(ImportError) as exc: + require_module("nonexistent_package_xyz", "MyFeature") + assert str(exc.value) == "MyFeature requires the 'nonexistent_package_xyz' package. Install it via 'pip install nonexistent_package_xyz'."