-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for require_dependencies decorator
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`." | ||
) |