Add unit test for overridden lc_namespace (#16093)

This commit is contained in:
Nuno Campos 2024-01-16 09:22:52 -08:00 committed by GitHub
parent 52114bdfac
commit 770f57196e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -30,10 +30,9 @@
"lc": 1, "lc": 1,
"type": "constructor", "type": "constructor",
"id": [ "id": [
"tests", "my",
"unit_tests", "special",
"load", "namespace",
"test_dump",
"SpecialPerson" "SpecialPerson"
], ],
"kwargs": { "kwargs": {

View File

@ -1,6 +1,6 @@
"""Test for Serializable base class""" """Test for Serializable base class"""
from typing import Any, Dict from typing import Any, Dict, List
import pytest import pytest
from langchain_community.chat_models.openai import ChatOpenAI from langchain_community.chat_models.openai import ChatOpenAI
@ -37,6 +37,10 @@ class SpecialPerson(Person):
another_visible: str = "bye" another_visible: str = "bye"
@classmethod
def get_lc_namespace(cls) -> List[str]:
return ["my", "special", "namespace"]
# Gets merged with parent class's secrets # Gets merged with parent class's secrets
@property @property
def lc_secrets(self) -> Dict[str, str]: def lc_secrets(self) -> Dict[str, str]:
@ -58,6 +62,7 @@ def test_person(snapshot: Any) -> None:
sp = SpecialPerson(another_secret="Wooo", secret="Hmm") sp = SpecialPerson(another_secret="Wooo", secret="Hmm")
assert dumps(sp, pretty=True) == snapshot assert dumps(sp, pretty=True) == snapshot
assert Person.lc_id() == ["tests", "unit_tests", "load", "test_dump", "Person"] assert Person.lc_id() == ["tests", "unit_tests", "load", "test_dump", "Person"]
assert SpecialPerson.lc_id() == ["my", "special", "namespace", "SpecialPerson"]
def test_typeerror() -> None: def test_typeerror() -> None: