-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swap out inspect file location (#991)
Signed-off-by: Yee Hing Tong <[email protected]>
- Loading branch information
1 parent
e2f6cdf
commit c011ef7
Showing
5 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Script used for testing local execution of functool.wraps-wrapped tasks for stacked decorators""" | ||
|
||
from functools import wraps | ||
from typing import List | ||
|
||
|
||
def task_setup(function: callable = None, *, integration_requests: List = None) -> None: | ||
integration_requests = integration_requests or [] | ||
|
||
@wraps(function) | ||
def wrapper(*args, **kwargs): | ||
# Preprocessing of task | ||
print("preprocessing") | ||
|
||
# Execute function | ||
output = function(*args, **kwargs) | ||
|
||
# Postprocessing of output | ||
print("postprocessing") | ||
|
||
return output | ||
|
||
return functools.partial(task_setup, integration_requests=integration_requests) if function is None else wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from flytekit import task | ||
|
||
from .decorator_source import task_setup | ||
|
||
|
||
@task | ||
@task_setup | ||
def get_data(x: int) -> int: | ||
return x + 1 |
17 changes: 17 additions & 0 deletions
17
tests/flytekit/unit/core/functools/test_decorator_location.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import importlib | ||
|
||
from flytekit.core.tracker import extract_task_module | ||
|
||
|
||
def test_dont_use_wrapper_location(): | ||
m = importlib.import_module("tests.flytekit.unit.core.functools.decorator_usage") | ||
get_data_task = getattr(m, "get_data") | ||
assert "decorator_source" not in get_data_task.name | ||
assert "decorator_usage" in get_data_task.name | ||
|
||
a, b, c, _ = extract_task_module(get_data_task) | ||
assert (a, b, c) == ( | ||
"tests.flytekit.unit.core.functools.decorator_usage.get_data", | ||
"tests.flytekit.unit.core.functools.decorator_usage", | ||
"get_data", | ||
) |