Skip to content

Commit 659cda7

Browse files
timsaucerclaude
andcommitted
test: pin that every function-kind row names something real
`_FUNCTION_KINDS` holds the `user_defined` wrapper, factory, and `register_*` method as strings, looked up during `with_extensions` so the import stays out of this module's cycle. The cost is that a typo in a row surfaces as an `AttributeError` part-way through an install rather than at import, and `test_every_component_field_has_an_installer` does not catch it -- that one compares field names, which a bad `wrapper` or `factory` leaves untouched. The three rows that exist today are each covered end to end by a registration test, so this is for the fourth, which may well be added before its own behaviour test is. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent e688948 commit 659cda7

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎python/tests/test_context.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,26 @@ def test_every_component_field_has_an_installer():
16741674
}
16751675

16761676

1677+
def test_every_function_kind_names_something_real():
1678+
"""The names on a ``_FunctionKind`` row resolve to what it says they do.
1679+
1680+
They are held as strings and looked up during ``with_extensions``, to keep
1681+
the ``user_defined`` import out of this module's import cycle. The cost is
1682+
that a typo in a row surfaces as an ``AttributeError`` part-way through an
1683+
install rather than at import. Every row that exists today is covered by a
1684+
behaviour test above; this is what covers the next one, which may be added
1685+
before its own test is.
1686+
"""
1687+
from datafusion import user_defined
1688+
from datafusion.context import _FUNCTION_KINDS
1689+
1690+
for kind in _FUNCTION_KINDS:
1691+
assert isinstance(getattr(user_defined, kind.wrapper), type)
1692+
assert callable(getattr(user_defined, kind.factory))
1693+
assert callable(getattr(SessionContext, kind.register))
1694+
assert kind.field in {spec.name for spec in fields(SessionExtensionComponents)}
1695+
1696+
16771697
def test_table_provider(ctx):
16781698
batch = pa.RecordBatch.from_pydict({"x": [10, 20, 30]})
16791699
ctx.register_record_batches("provider_test", [[batch]])

0 commit comments

Comments
 (0)