Skip to content

Commit

Permalink
add tests for require_dependencies decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
micpst committed Oct 17, 2024
1 parent afd1867 commit 9f7704e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/ragbits-core/tests/unit/utils/test_decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pytest

from ragbits.core.utils.decorators import requires_dependencies


def test_single_dependency_installed() -> None:
@requires_dependencies("pytest")
def some_function() -> str:
return "success"

assert some_function() == "success"


def test_single_dependency_missing() -> None:
@requires_dependencies("nonexistent_dependency")
def some_function() -> str:
return "success"

with pytest.raises(ImportError) as exc:
some_function()

assert (
str(exc.value)
== "Following dependencies are missing: nonexistent_dependency. Please install them using `pip install nonexistent_dependency`."
)


def test_multiple_dependencies_installed() -> None:
@requires_dependencies(["pytest", "asyncio"])
def some_function() -> str:
return "success"

assert some_function() == "success"


def test_multiple_dependencies_some_missing() -> None:
@requires_dependencies(["pytest", "nonexistent_dependency"])
def some_function() -> str:
return "success"

with pytest.raises(ImportError) as exc:
some_function()

assert (
str(exc.value)
== "Following dependencies are missing: nonexistent_dependency. Please install them using `pip install nonexistent_dependency`."
)

0 comments on commit 9f7704e

Please sign in to comment.