Skip to content

Commit

Permalink
Add a deprecated UDF to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
topher-lo committed Jan 15, 2025
1 parent 19fd41e commit d527586
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/unit/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,28 @@ async def async_test_function(num: int) -> int:
)
)

# Create a file for the deprecated function
with open(os.path.join(tmp_path, "deprecated_function.py"), "w") as f:
f.write(
textwrap.dedent(
"""
from tracecat_registry import registry
@registry.register(
description="This is a deprecated function",
namespace="test",
deprecated="This function is deprecated",
)
"""
)
)

yield test_module

finally:
# Clean up
del sys.modules["test_module"]
del sys.modules["test_deprecated_module"]


def test_udf_can_be_registered(mock_package):
Expand Down Expand Up @@ -122,6 +140,18 @@ def test_udf_validate_args(mock_package):
udf.validate_args(num="not a number")


def test_deprecated_function_can_be_registered(mock_deprecated_package):
"""Test that a deprecated function can be registered."""
repo = Repository()
repo._register_udfs_from_package(mock_deprecated_package)

udf = repo.get("test.deprecated_function")
assert udf is not None

# Check descriptors
assert udf.deprecated == "This function is deprecated"


def test_registry_function_can_be_called(mock_package):
"""We need to test that the ordering of the workflow tasks is correct."""
repo = Repository()
Expand Down

0 comments on commit d527586

Please sign in to comment.