skrawcz commented on code in PR #1524:
URL: https://github.com/apache/hamilton/pull/1524#discussion_r3035071722
##########
tests/function_modifiers/test_delayed.py:
##########
@@ -155,5 +170,104 @@ def test_delayed_without_power_mode_fails():
with pytest.raises(base.InvalidDecoratorException):
decorator.resolve(
{"cols_to_extract": ["a", "b"], **CONFIG_WITH_POWER_MODE_DISABLED},
- fn=test_delayed_with_optional,
+ fn=fn,
)
+
+
+def test_dynamic_resolve_with_extract_fields():
+ """Test that @resolve with @extract_fields calls validate() correctly."""
+
+ def fn() -> dict[str, int]:
+ return {"a": 1, "b": 2}
+
+ decorator = resolve(
+ when=ResolveAt.CONFIG_AVAILABLE,
+ decorate_with=lambda fields: extract_fields(fields),
+ )
+ decorator_resolved = decorator.resolve(
+ {"fields": {"a": int, "b": int}, **CONFIG_WITH_POWER_MODE_ENABLED},
+ fn=fn,
+ )
+ assert hasattr(decorator_resolved, "resolved_fields")
+ assert decorator_resolved.resolved_fields == {"a": int, "b": int}
+
+
+def test_resolve_with_parameterize_sources():
+ """Test that @resolve with @parameterize_sources calls validate()
correctly."""
+
+ def fn(x: int, y: int) -> int:
+ return x + y
+
+ decorator = resolve(
+ when=ResolveAt.CONFIG_AVAILABLE,
+ decorate_with=lambda: parameterize_sources(result_1={"x": "source_x",
"y": "source_y"}),
+ )
+ decorator_resolved = decorator.resolve(
+ {**CONFIG_WITH_POWER_MODE_ENABLED},
+ fn=fn,
+ )
+ assert "result_1" in decorator_resolved.parameterization
+ mapping = decorator_resolved.parameterization["result_1"]
+ assert mapping["x"].source == "source_x"
+ assert mapping["y"].source == "source_y"
+
+
+def test_resolve_from_config_with_extract_fields():
+ """Test @resolve_from_config with @extract_fields calls validate()
correctly."""
+
+ def fn() -> dict[str, int]:
+ return {"a": 1, "b": 2}
+
+ decorator = resolve_from_config(
+ decorate_with=lambda fields: extract_fields(fields),
+ )
+ decorator_resolved = decorator.resolve(
+ {"fields": {"a": int, "b": int}, **CONFIG_WITH_POWER_MODE_ENABLED},
+ fn=fn,
+ )
+ assert hasattr(decorator_resolved, "resolved_fields")
+ assert decorator_resolved.resolved_fields == {"a": int, "b": int}
+
+
+def test_resolve_propagates_validate_failure():
+ """Test that validate() failures are propagated through resolve."""
+
+ def fn() -> str:
+ return "not what you were expecting..."
+
+ decorator = resolve(
+ when=ResolveAt.CONFIG_AVAILABLE,
+ decorate_with=lambda fields: extract_fields(fields),
+ )
+ with pytest.raises(base.InvalidDecoratorException):
+ decorator.resolve(
+ {"fields": {"a": int, "b": int}, **CONFIG_WITH_POWER_MODE_ENABLED},
+ fn=fn,
+ )
+
+
+def test_resolve_with_arbitrary_decorator():
+ """Test behavior when decorate_with returns something that is not a
NodeTransformLifecycle."""
+
+ # NOTE: do we actually want this test to pass?
Review Comment:
```suggestion
# NOTE: we want to ensure we don't interfere with other decorators on
functions.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]