Skip to content

Commit

Permalink
test: add test test_import_annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday authored and ksystem-mychoi committed Jun 13, 2024
1 parent 5baa23d commit 3a4739b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/providers/docker/decorators/_with_annotations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import TYPE_CHECKING

from airflow.decorators import task

if TYPE_CHECKING:
from airflow.decorators.base import Task

__all__ = []


def create_task_factory(image: str, **kwargs: "Any") -> "Task[..., Any]": # type: ignore # noqa: F821
kwargs.setdefault("multiple_outputs", False)

@task.docker(image=image, auto_remove="force", **kwargs)
def func(value: "dict[str, Any]") -> "Any": # type: ignore # noqa: F821
assert isinstance(value, dict)

return func
22 changes: 22 additions & 0 deletions tests/providers/docker/decorators/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,25 @@ def f():
ret = f()

assert ret.operator.docker_url == "unix://var/run/docker.sock"

def test_import_annotations(self, dag_maker):
from typing import Any

from airflow.models.dagrun import DagRun # noqa: TCH001
from airflow.utils.state import DagRunState

from ._with_annotations import create_task_factory # noqa: TID252

task_factory = create_task_factory("python:3.9-slim")

with dag_maker():

@task.python(multiple_outputs=False)
def create_dummy_value() -> dict[str, Any]:
return {}

value = create_dummy_value()
_ = task_factory(value)

dagrun: DagRun = dag_maker.create_dagrun()
assert DagRunState(dagrun.state) == DagRunState.SUCCESS

0 comments on commit 3a4739b

Please sign in to comment.