Skip to content

Commit

Permalink
make import_optional_dependency private
Browse files Browse the repository at this point in the history
  • Loading branch information
mscheltienne committed Mar 3, 2023
1 parent 806777b commit 1511cbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion template/utils/_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}


def import_optional_dependency(
def _import_optional_dependency(
name: str,
extra: str = "",
raise_error: bool = True,
Expand Down
10 changes: 5 additions & 5 deletions template/utils/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

import pytest

from .._imports import import_optional_dependency
from .._imports import _import_optional_dependency


def test_import_optional_dependency():
"""Test the import of optional dependencies."""
# Test import of present package
numpy = import_optional_dependency("numpy")
numpy = _import_optional_dependency("numpy")
assert isinstance(numpy.__version__, str)

# Test import of absent package
with pytest.raises(ImportError, match="Missing optional dependency"):
import_optional_dependency("non_existing_pkg", raise_error=True)
_import_optional_dependency("non_existing_pkg", raise_error=True)

# Test import of absent package without raise
pkg = import_optional_dependency("non_existing_pkg", raise_error=False)
pkg = _import_optional_dependency("non_existing_pkg", raise_error=False)
assert pkg is None

# Test extra
with pytest.raises(ImportError, match="blabla"):
import_optional_dependency("non_existing_pkg", extra="blabla")
_import_optional_dependency("non_existing_pkg", extra="blabla")

0 comments on commit 1511cbc

Please sign in to comment.