-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrote unit tests for check_package_version
- Loading branch information
1 parent
c37ca45
commit e1b1613
Showing
1 changed file
with
30 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,30 @@ | ||
from typing import Dict, Optional, Tuple, Type | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from langchain_core.utils import check_package_version | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("package", "check_kwargs", "actual_version", "expected"), | ||
[ | ||
("stub", {"gt_version": "0.1"}, "0.1.2", None), | ||
("stub", {"gt_version": "0.1.2"}, "0.1.12", None), | ||
("stub", {"gt_version": "0.1.2"}, "0.1.2", (ValueError, "> 0.1.2")), | ||
("stub", {"gte_version": "0.1"}, "0.1.2", None), | ||
("stub", {"gte_version": "0.1.2"}, "0.1.2", None), | ||
], | ||
) | ||
def test_check_package_version( | ||
package: str, | ||
check_kwargs: Dict[str, Optional[str]], | ||
actual_version: str, | ||
expected: Optional[Tuple[Type[Exception], str]], | ||
) -> None: | ||
with patch("langchain_core.utils.utils.version", return_value=actual_version): | ||
if expected is None: | ||
check_package_version(package, **check_kwargs) | ||
else: | ||
with pytest.raises(expected[0], match=expected[1]): | ||
check_package_version(package, **check_kwargs) |