Skip to content

Commit

Permalink
Add Python Dependency Deck (flyteorg#2264)
Browse files Browse the repository at this point in the history
* feat: refactor source code rendering in `SourceCodeDeck` class

- Add a new class `SourceCodeDeck` to render the source code of a task
- Implement the `html` property in the `SourceCodeDeck` class

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor deck rendering for Python dependencies

- Change the class name from `SourceCodeDeck` to `PythonDependencyDeck`
- Update the deck description to reflect python dependencies instead of source code
- Remove the source code rendering functionality and replace it with a table renderer for python dependencies
- Add subprocess logic to fetch installed python packages and render them in an HTML table

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor class properties and initialization

- Add a property method for `pythondependency_deck`
- Initialize `python_dependency_deck` if it is None
- Remove a property method for `timeline_deck`

Signed-off-by: jason.lai <[email protected]>

* - feat: consolidate Python dependencies in `flytekit/__init__.py`

- Add `PythonDependencyDeck` to `flytekit/__init__.py`

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor `flytekit/deck/deck.py` for `pandas` compatibility

- Add `pandas` import to `flytekit/deck/deck.py`
- Change the input of `TableRenderer().to_html` to a `pd.DataFrame` in `flytekit/deck/deck.py`

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor return types across multiple files

- Update the return type annotation for `pythondependency_deck` in `context_manager.py`

Signed-off-by: jason.lai <[email protected]>

* feat: consolidate Python dependency management in FlyteContext

- Add `PythonDependencyDeck` to the TYPE_CHECKING import
- Add a method `add_deck` to `FlyteContext` class

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor code to use DataFrame for package handling

- Refactor the code to use a DataFrame for installed packages handling

Signed-off-by: jason.lai <[email protected]>

* chore: refactor code for improved naming conventions

- Update the name of the PythonDependencyDeck instance from "PythonDependencyDeck" to "Python Dependency"

Signed-off-by: jason.lai <[email protected]>

* style: improve table alignment styling in CSS

- Add CSS style to center align the table content

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor method and variable names across files

- Rename method `pythondependency_deck` to `python_dependency_deck`
- Update variable names in method `python_dependency_deck`
- Update method comments in class `FlyteContext`
- Update method comments in class `PythonDependencyDeck`

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor imports in flytekit package

- Remove import of `PythonDependencyDeck` from `flytekit/__init__.py`

Signed-off-by: jason.lai <[email protected]>

* refactor: consolidate import statements in core/context_manager.py

- Remove the import of `PythonDependencyDeck` from `flytekit/core/context_manager.py`
- Add an import of `Deck` to `flytekit/core/context_manager.py`

Signed-off-by: jason.lai <[email protected]>

* style: improve code consistency and error checking

- Add a condition to check for deck existence before appending
- Change single quotes to double quotes for consistency
- Update package split delimiter to double quotes

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor Python dependency handling in classes

- Remove the `python_dependency_deck` property from the `ExecutionParameters` class in `context_manager.py`
- Update the `__init__` method signature in the `PythonDependencyDeck` class in `deck.py`

Signed-off-by: jason.lai <[email protected]>

* chore: optimize imports in deck.py files

- Remove unnecessary import of `pandas` in `flytekit/deck/deck.py`
- Add import of `pandas` in `flytekit/deck/deck.py`

Signed-off-by: jason.lai <[email protected]>

* test: improve test coverage for PythonDependencyDeck class

- Add a new test for the PythonDependencyDeck class in test_deck.py
- Add assertions for specific strings in the HTML content in the test_python_dependency_deck() function

Signed-off-by: jason.lai <[email protected]>

* feat: enhance user space deck management

- Clear user space decks before adding a new deck
- Ensure only one deck is added to user space params

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor deck module and unit tests

- Import json and TableRenderer in `flytekit/deck/deck.py`
- Change how installed packages are fetched in `flytekit/deck/deck.py`
- Remove unused code in `flytekit/deck/deck.py`
- Remove assertions for "Library" and "Version" in `tests/flytekit/unit/deck/test_deck.py`

Signed-off-by: jason.lai <[email protected]>

* fix: update subprocess calls to use `sys.executable`

- Import `sys` to fix an issue with subprocess execution
- Update the subprocess call to use `sys.executable` instead of `pip`

Signed-off-by: jason.lai <[email protected]>

* feat: refactor HTML generation logic and improve user experience

- Update the HTML generation logic to include a button for copying the table as requirements.txt.

Signed-off-by: jason.lai <[email protected]>

* feat: enhance table content copying functionality

- Add functionality to copy table content as requirements.txt
- Improve error handling when copying table content
- Display table content as hidden div for copying

Signed-off-by: jason.lai <[email protected]>

* refactor: improve table content copying functionality

- Remove unnecessary code for table content copying
- Update table content copying functionality to use innerText of requirements_txt element

Signed-off-by: jason.lai <[email protected]>

* refactor: improve package management and error handling

- Add logic to generate a `requirements.txt` file from installed packages
- Update error logging message in case of subprocess error
- Update console log message when accessing clipboard
- Update `requirements_txt` div content with actual `requirements_txt` variable

Signed-off-by: jason.lai <[email protected]>

* chore: standardize whitespace in requirements_txt handling

- Remove trailing whitespace from `requirements_txt` string
- Add a whitespace to the end of the `requirements_txt` variable
- Log an error message when fetching installed packages fails

Signed-off-by: jason.lai <[email protected]>

* style: standardize quotation marks for package_info keys

- Corrected quotation marks in package_info keys
- Changed single quotes to double quotes for consistency

Signed-off-by: jason.lai <[email protected]>

* refactor: simplify requirements_txt generation

- Refactor code to simplify the generation of `requirements_txt`
- Add the output of `pip freeze` to `requirements_txt`

Signed-off-by: jason.lai <[email protected]>

* docs: fix typos and improve code consistency across files

- Fix a typo in the usage of the `pip freeze` command in the PythonDependencyDeck class

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor dependency handling in PythonDependencyDeck class

- Update the way `requirements_txt` is populated in the `PythonDependencyDeck` class

Signed-off-by: jason.lai <[email protected]>

* refactor: update default name and test assertion in PythonDependencyDeck

- Update the default name in the PythonDependencyDeck constructor from "Python Dependency" to "Python Dependencies"
- Update the assertion in the test_python_dependency_deck function to check for the new default name "Python Dependencies"

Signed-off-by: jason.lai <[email protected]>

* refactor: update rendering of Pandas DataFrame using MarkdownRenderer

- Import `MarkdownRenderer` from `flytekit.deck` instead of `TableRenderer`
- Render the Pandas DataFrame as markdown using `MarkdownRenderer` instead of `TableRenderer`

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor PythonDependencyDeck and related classes

- Remove the `add_deck` method from `FlyteContext`
- Add imports for `PythonDependencyRenderer` and `PythonDependencyDeck` in `PythonFunctionTask`
- Remove the `PythonDependencyDeck` class and related methods from the `deck.py` file
- Add the `PythonDependencyRenderer` class in `renderer.py`

Signed-off-by: jason.lai <[email protected]>

* feat: use `TableRenderer` for rendering DataFrames

- Import `TableRenderer` from a different module
- Replace the `MarkdownRenderer` with `TableRenderer` to render a DataFrame as a table

Signed-off-by: jason.lai <[email protected]>

* test: refactor codebase for improved performance

- Remove unused import statements in `flytekit/deck/renderer.py`
- Add a new test for `PythonDependencyRenderer` in `tests/flytekit/unit/deck/test_deck.py`

Signed-off-by: jason.lai <[email protected]>

* test: update test_deck.py for python dependency deck testing

- Update test_deck.py to include python dependency deck in various test cases
- Adjust expected deck counts in test cases to reflect the changes
- Add test cases for scenarios involving python dependency deck and input and output decks

Signed-off-by: jason.lai <[email protected]>

* style: standardize import statements for pandas in project files

- Remove `import pandas as pd` and replace it with `import pandas as pandas`

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor import statements for `TableRenderer` usage

- Import `TableRenderer` from a different location in `flytekit/deck/renderer.py`
- Remove `TableRenderer` from the imports in `flytekit-deck-standard/flytekitplugins/deck/__init__.py`

Signed-off-by: jason.lai <[email protected]>

* refactor: update PythonDependencyRenderer description

- Update the description of PythonDependencyDeck in PythonDependencyRenderer

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor type hints and assertions across files

- Change the type hint for `df` parameter to `pandas.DataFrame`
- Add an assertion to check the type of `df` is `pandas.DataFrame`

Signed-off-by: jason.lai <[email protected]>

* feat: refactor rendering classes in deck and plugins

- Add TableRenderer to TimeLineDeck class in deck.py
- Remove TableRenderer from deck/renderer.py
- Add TableRenderer to PythonDependencyRenderer in deck/renderer.py
- Add TableRenderer to flytekit-deck-standard plugin
- Remove TableRenderer from test_renderer.py

Signed-off-by: jason.lai <[email protected]>

* docs: standardize markdown formatting across files

- Update the markdown table format in PythonDependencyRenderer class

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor markdown table rendering in PythonDependencyRenderer

- Update the markdown table format in the PythonDependencyRenderer class to use HTML table tags
- Modify the markdown_table variable concatenation for installed packages entries in the PythonDependencyRenderer class

Signed-off-by: jason.lai <[email protected]>

* style: improve code consistency in PythonDependencyRenderer

- Add a line break after the button element in PythonDependencyRenderer

Signed-off-by: jason.lai <[email protected]>

* style: standardize formatting for better readability

- Modify the table headers to have left-aligned text
- Add extra line breaks after the button element

Signed-off-by: jason.lai <[email protected]>

* fix: update assertion to check for `Name` and `Version` consistency

- Change the assertion to check for `Name` and `Version` instead of `name` and `version` in the result

Signed-off-by: jason.lai <[email protected]>

* test: extend test deadlines across various tests

- Increase the test deadlines from 2 to 20 seconds in test_type_conversion_errors.py
- Update test deadlines from 2 to 40 seconds in test_type_conversion_errors.py
- Adjust test deadlines in test_eager_workflows.py for various tests

Signed-off-by: jason.lai <[email protected]>

* Revert "test: extend test deadlines across various tests"

This reverts commit 1885662.

Signed-off-by: Eduardo Apolinario <[email protected]>

* Only run generate decks in python_function_task if decks are enabled

Signed-off-by: Eduardo Apolinario <[email protected]>

* Remove breakpoint

Signed-off-by: Eduardo Apolinario <[email protected]>

* Fix test_deck.py tests to account for the number of expected decks (now that we're no longer writing decks unnecessarily)

Signed-off-by: Eduardo Apolinario <[email protected]>

* Increase deadline of eager tests

Signed-off-by: Eduardo Apolinario <[email protected]>

* Fix lint error

Signed-off-by: Eduardo Apolinario <[email protected]>

* test: update test assertions in test_deck.py

- Add a patch to the `test_python_dependency_renderer` function
- Include assertions for `numpy` and `1.21.0` in the test result
- Update the `test_deck.py` file in the `tests/flytekit/unit/deck` directory

Signed-off-by: jason.lai <[email protected]>

* refactor: refactor Python code organization

- Import `PythonDependencyRenderer` and `SourceCodeRenderer` in `PythonFunctionTask` from separate files
- Modify the way `requirements_txt` is generated in `PythonDependencyRenderer`
- Refactor the creation of the `table` variable in `PythonDependencyRenderer` to improve readability

Signed-off-by: jason.lai <[email protected]>

* docs: refactor project structure and improve user experience

- Change the title of the deck from `Python Dependencies` to `Dependencies`
- Update the error message in case of a subprocess error in fetching installed packages
- Add a heading `Python Dependencies` above the table output in the HTML

Signed-off-by: jason.lai <[email protected]>

* Separate out tests that require hypothesis

Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: jason.lai <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
2 people authored and ChungYujoyce committed Apr 5, 2024
1 parent e6ad98c commit 60c57d1
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 30 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/pythonbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,41 @@ jobs:
fail_ci_if_error: false
files: coverage.xml

test-hypothesis:
needs:
- detect-python-versions
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ${{fromJson(needs.detect-python-versions.outputs.python-versions)}}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v3
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements files
key: ${{ format('{0}-pip-{1}', runner.os, hashFiles('dev-requirements.in', 'requirements.in')) }}
- name: Install dependencies
run: make setup && pip freeze
- name: Test with coverage
env:
FLYTEKIT_HYPOTHESIS_PROFILE: ci
run: |
make unit_test_hypothesis
- name: Codecov
uses: codecov/[email protected]
with:
fail_ci_if_error: false
files: coverage.xml

test-serialization:
needs:
- detect-python-versions
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ unit_test_extras_codecov:
unit_test:
# Skip all extra tests and run them with the necessary env var set so that a working (albeit slower)
# library is used to serialize/deserialize protobufs is used.
$(PYTEST_AND_OPTS) -m "not (serial or sandbox_test)" tests/flytekit/unit/ --ignore=tests/flytekit/unit/extras/ --ignore=tests/flytekit/unit/models --ignore=tests/flytekit/unit/extend ${CODECOV_OPTS}
$(PYTEST_AND_OPTS) -m "not (serial or sandbox_test or hypothesis)" tests/flytekit/unit/ --ignore=tests/flytekit/unit/extras/ --ignore=tests/flytekit/unit/models --ignore=tests/flytekit/unit/extend ${CODECOV_OPTS}
# Run serial tests without any parallelism
$(PYTEST) -m "serial" tests/flytekit/unit/ --ignore=tests/flytekit/unit/extras/ --ignore=tests/flytekit/unit/models --ignore=tests/flytekit/unit/extend ${CODECOV_OPTS}

.PHONY: unit_test_hypothesis
unit_test_hypothesis:
$(PYTEST_AND_OPTS) -m "hypothesis" tests/flytekit/unit/experimental ${CODECOV_OPTS}

.PHONY: unit_test_extras
unit_test_extras:
Expand Down
22 changes: 14 additions & 8 deletions flytekit/core/python_function_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,21 @@ def dynamic_execute(self, task_function: Callable, **kwargs) -> Any:
raise ValueError(f"Invalid execution provided, execution state: {ctx.execution_state}")

def _write_decks(self, native_inputs, native_outputs_as_map, ctx, new_user_params):
# These errors are raised if the source code can not be retrieved
with suppress(OSError, TypeError):
source_code = inspect.getsource(self._task_function)

if self._disable_deck is False:
from flytekit.deck import Deck
from flytekit.deck.renderer import SourceCodeRenderer
from flytekit.deck.renderer import PythonDependencyRenderer

# These errors are raised if the source code can not be retrieved
with suppress(OSError, TypeError):
source_code = inspect.getsource(self._task_function)
from flytekit.deck.renderer import SourceCodeRenderer

source_code_deck = Deck("Source Code")
renderer = SourceCodeRenderer()
source_code_deck.append(renderer.to_html(source_code))

source_code_deck = Deck("Source Code")
renderer = SourceCodeRenderer()
source_code_deck.append(renderer.to_html(source_code))
python_dependencies_deck = Deck("Dependencies")
renderer = PythonDependencyRenderer()
python_dependencies_deck.append(renderer.to_html())

return super()._write_decks(native_inputs, native_outputs_as_map, ctx, new_user_params)
74 changes: 74 additions & 0 deletions flytekit/deck/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,77 @@ def to_html(self, source_code: str) -> str:
css = formatter.get_style_defs(".highlight").replace("#fff0f0", "#ffffff")
html = highlight(source_code, PythonLexer(), formatter)
return f"<style>{css}</style>{html}"


class PythonDependencyRenderer:
"""
PythonDependencyDeck is a deck that contains information about packages installed via pip.
"""

def __init__(self, title: str = "Dependencies"):
self._title = title

def to_html(self) -> str:
import json
import subprocess
import sys

from flytekit.loggers import logger

try:
installed_packages = json.loads(
subprocess.check_output([sys.executable, "-m", "pip", "list", "--format", "json"])
)
requirements_txt = (
subprocess.check_output([sys.executable, "-m", "pip", "freeze"])
.decode("utf-8")
.replace("\\n", "\n")
.rstrip()
)
except subprocess.CalledProcessError as e:
logger.error(f"Error occurred while fetching installed packages: {e}")
return "Error occurred while fetching installed packages."

table = (
"<table>\n<tr>\n<th style='text-align:left;'>Name</th>\n<th style='text-align:left;'>Version</th>\n</tr>\n"
)

for entry in installed_packages:
table += f"<tr>\n<td>{entry['name']}</td>\n<td>{entry['version']}</td>\n</tr>\n"

table += "</table>"

html = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flyte Dependencies</title>
<script>
async function copyTable() {{
var requirements_txt = document.getElementById('requirements_txt');
try {{
await navigator.clipboard.writeText(requirements_txt.innerText);
}} catch (err) {{
console.log('Error accessing the clipboard: ' + err);
}}
}}
</script>
</head>
<body>
<button onclick="copyTable()">
<span>Copy table as requirements.txt</span>
</button>
<h3>Python Dependencies</h3>
{table}
<div id="requirements_txt" style="display:none">{requirements_txt}</div>
</body>
</html>
"""
return html
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ log_cli_level = 20
markers = [
"sandbox_test: fake integration tests", # unit tests that are really integration tests that run on a sandbox environment
"serial: tests to avoid using with pytest-xdist",
"hypothesis: tests that use they hypothesis library",
]

[tool.coverage.report]
Expand Down
9 changes: 9 additions & 0 deletions tests/flytekit/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os

import pytest
from hypothesis import settings

from flytekit.image_spec.image_spec import ImageSpecBuilder

Expand All @@ -11,3 +14,9 @@ def build_image(self, img):
@pytest.fixture()
def mock_image_spec_builder():
return MockImageSpecBuilder()


settings.register_profile("ci", max_examples=5, deadline=100_000)
settings.register_profile("dev", max_examples=10, deadline=10_000)

settings.load_profile(os.getenv("FLYTEKIT_HYPOTHESIS_PROFILE", "dev"))
45 changes: 36 additions & 9 deletions tests/flytekit/unit/deck/test_deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import pytest
from markdown_it import MarkdownIt
from mock import mock
from mock import mock, patch

import flytekit
from flytekit import Deck, FlyteContextManager, task
from flytekit.deck import MarkdownRenderer, SourceCodeRenderer, TopFrameRenderer
from flytekit.deck.deck import _output_deck
from flytekit.deck.renderer import PythonDependencyRenderer


@pytest.mark.skipif("pandas" not in sys.modules, reason="Pandas is not installed.")
Expand Down Expand Up @@ -50,9 +51,9 @@ def test_timeline_deck():
@pytest.mark.parametrize(
"disable_deck,expected_decks",
[
(None, 2), # time line deck + source code deck
(False, 4), # time line deck + source code deck + input and output decks
(True, 2), # time line deck + source code deck
(None, 1), # time line deck
(False, 5), # time line deck + source code deck + python dependency deck + input and output decks
(True, 1), # time line deck
],
)
def test_deck_for_task(disable_deck, expected_decks):
Expand All @@ -75,11 +76,21 @@ def t1(a: int) -> str:
@pytest.mark.parametrize(
"enable_deck,disable_deck, expected_decks, expect_error",
[
(None, None, 3, False), # default deck and time line deck + source code deck
(None, False, 5, False), # default deck and time line deck + source code deck + input and output decks
(None, True, 3, False), # default deck and time line deck + source code deck
(True, None, 5, False), # default deck and time line deck + source code deck + input and output decks
(False, None, 3, False), # default deck and time line deck + source code deck
(None, None, 2, False), # default deck and time line deck
(
None,
False,
6,
False,
), # default deck and time line deck + source code deck + python dependency deck + input and output decks
(None, True, 2, False), # default deck and time line deck
(
True,
None,
6,
False,
), # default deck and time line deck + source code deck + python dependency deck + input and output decks
(False, None, 2, False), # default deck and time line deck
(True, True, -1, True), # Set both disable_deck and enable_deck to True and confirm that it fails
(False, False, -1, True), # Set both disable_deck and enable_deck to False and confirm that it fails
],
Expand Down Expand Up @@ -176,3 +187,19 @@ def test_source_code_renderer():
# Assert that the color #ffffff is used instead of #fff0f0
assert "#ffffff" in result
assert "#fff0f0" not in result


def test_python_dependency_renderer():
with patch("subprocess.check_output") as mock_check_output:
mock_check_output.return_value = '[{"name": "numpy", "version": "1.21.0"}]'.encode()
renderer = PythonDependencyRenderer()
result = renderer.to_html()
assert "numpy" in result
assert "1.21.0" in result

# Assert that the result includes parts of the python dependency
assert "Name" in result
assert "Version" in result

# Assert that the button of copy
assert 'button onclick="copyTable()"' in result
24 changes: 12 additions & 12 deletions tests/flytekit/unit/experimental/test_eager_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import hypothesis.strategies as st
import pytest
from hypothesis import given, settings
from hypothesis import given

from flytekit import dynamic, task, workflow
from flytekit.exceptions.user import FlyteValidationException
Expand All @@ -15,7 +15,6 @@
from flytekit.types.file import FlyteFile
from flytekit.types.structured import StructuredDataset

DEADLINE = 2000
INTEGER_ST = st.integers(min_value=-10_000_000, max_value=10_000_000)


Expand Down Expand Up @@ -48,7 +47,7 @@ def dynamic_wf(x: int) -> int:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_simple_eager_workflow(x_input: int):
"""Testing simple eager workflow with just tasks."""

Expand All @@ -62,7 +61,7 @@ async def eager_wf(x: int) -> int:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_conditional_eager_workflow(x_input: int):
"""Test eager workflow with conditional logic."""

Expand All @@ -80,7 +79,7 @@ async def eager_wf(x: int) -> int:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_try_except_eager_workflow(x_input: int):
"""Test eager workflow with try/except logic."""

Expand All @@ -99,7 +98,7 @@ async def eager_wf(x: int) -> int:


@given(x_input=INTEGER_ST, n_input=st.integers(min_value=1, max_value=20))
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_gather_eager_workflow(x_input: int, n_input: int):
"""Test eager workflow with asyncio gather."""

Expand All @@ -113,7 +112,7 @@ async def eager_wf(x: int, n: int) -> typing.List[int]:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_eager_workflow_with_dynamic_exception(x_input: int):
"""Test eager workflow with dynamic workflow is not supported."""

Expand All @@ -131,7 +130,7 @@ async def nested_eager_wf(x: int) -> int:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_nested_eager_workflow(x_input: int):
"""Testing running nested eager workflows."""

Expand All @@ -145,7 +144,7 @@ async def eager_wf(x: int) -> int:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_eager_workflow_within_workflow(x_input: int):
"""Testing running eager workflow within a static workflow."""

Expand All @@ -168,7 +167,7 @@ def subworkflow(x: int) -> int:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_workflow_within_eager_workflow(x_input: int):
"""Testing running a static workflow within an eager workflow."""

Expand All @@ -182,7 +181,7 @@ async def eager_wf(x: int) -> int:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.hypothesis
def test_local_task_eager_workflow_exception(x_input: int):
"""Testing simple eager workflow with a local function task doesn't work."""

Expand All @@ -199,8 +198,8 @@ async def eager_wf_with_local(x: int) -> int:


@given(x_input=INTEGER_ST)
@settings(deadline=DEADLINE, max_examples=5)
@pytest.mark.filterwarnings("ignore:coroutine 'AsyncEntity.__call__' was never awaited")
@pytest.mark.hypothesis
def test_local_workflow_within_eager_workflow_exception(x_input: int):
"""Cannot call a locally-defined workflow within an eager workflow"""

Expand Down Expand Up @@ -243,6 +242,7 @@ def create_directory() -> FlyteDirectory:


@pytest.mark.skipif("pandas" not in sys.modules, reason="Pandas is not installed.")
@pytest.mark.hypothesis
def test_eager_workflow_with_offloaded_types():
"""Test eager workflow that eager workflows work with offloaded types."""
import pandas as pd
Expand Down

0 comments on commit 60c57d1

Please sign in to comment.