langchain-tests: allow test_serdes for packages outside the default valid namespaces (#30343)

**Description:**

a third party package not listed in the default valid namespaces cannot
pass test_serdes because the load() does not allow for extending the
valid_namespaces.

test_serdes will fail with -
ValueError: Invalid namespace: {'lc': 1, 'type': 'constructor', 'id':
['langchain_other', 'chat_models', 'ChatOther'], 'kwargs':
{'model_name': '...', 'api_key': '...'}, 'name': 'ChatOther'}

this change has test_serdes automatically extend valid_namespaces based
off the ChatModel under test's namespace.
This commit is contained in:
Matthew Farrellee 2025-03-22 16:27:39 -05:00 committed by GitHub
parent 699475a01d
commit e7032901c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -717,4 +717,9 @@ class ChatModelUnitTests(ChatModelTests):
with mock.patch.dict(os.environ, env_params):
ser = dumpd(model)
assert ser == snapshot(name="serialized")
assert model.dict() == load(dumpd(model)).dict()
assert (
model.dict()
== load(
dumpd(model), valid_namespaces=model.get_lc_namespace()[:1]
).dict()
)