Skip to content

Commit

Permalink
add ProviderMetaclass test
Browse files Browse the repository at this point in the history
  • Loading branch information
dlqqq committed Jan 10, 2024
1 parent ec96746 commit ade840a
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import ClassVar, Optional
from ..providers import ProviderMetaclass
from langchain.pydantic_v1 import BaseModel


def test_provider_metaclass():
"""
Asserts that the metaclass prevents class attributes from being omitted due
to parent classes defining an instance field of the same name.
You can reproduce the original issue by removing the
`metaclass=ProviderMetaclass` argument from the definition of `Child`.
"""

class Parent(BaseModel):
test: Optional[str]

class Base(BaseModel):
test: ClassVar[str]

class Child(Base, Parent, metaclass=ProviderMetaclass):
test: ClassVar[str] = "expected"

assert Child.test == "expected"

0 comments on commit ade840a

Please sign in to comment.