Skip to content

Commit

Permalink
Wrote unit tests for check_package_version
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza authored Jan 31, 2024
1 parent c37ca45 commit e1b1613
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions libs/core/tests/unit_tests/utils/test_utils.py
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)

0 comments on commit e1b1613

Please sign in to comment.