From 5d4aadac503db772795b74f83b909a58b9dc3a9e Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Mon, 1 Jul 2024 16:06:21 -0700 Subject: [PATCH] add tests for the new conditions, use the coverage-based tests in cI --- .github/workflows/python-ci.yml | 2 +- python/reactivedataflow/pyproject.toml | 2 +- .../reactivedataflow/conditions.py | 4 +-- .../tests/unit/test_conditions.py | 29 +++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 python/reactivedataflow/tests/unit/test_conditions.py diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 36b566c6..9ec18b1c 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -45,4 +45,4 @@ jobs: - name: ${{ matrix.project }} - Test working-directory: ./python/${{ matrix.project }} run: | - poetry run poe test + poetry run poe test_coverage diff --git a/python/reactivedataflow/pyproject.toml b/python/reactivedataflow/pyproject.toml index 059390a9..a9c64700 100644 --- a/python/reactivedataflow/pyproject.toml +++ b/python/reactivedataflow/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "reactivedataflow" -version = "0.1.8" +version = "0.1.9" description = "Reactive Dataflow Graphs" license = "MIT" authors = ["Chris Trevino "] diff --git a/python/reactivedataflow/reactivedataflow/conditions.py b/python/reactivedataflow/reactivedataflow/conditions.py index ec77fd9d..8114e7a8 100644 --- a/python/reactivedataflow/reactivedataflow/conditions.py +++ b/python/reactivedataflow/reactivedataflow/conditions.py @@ -62,11 +62,11 @@ def array_input_values_are_defined() -> FireCondition: T = TypeVar("T") -def array_result_non_empty(name: str = default_output) -> EmitCondition: +def array_result_not_empty(name: str = default_output) -> EmitCondition: """Create an emit condition to emit when the given array output is non-empty.""" def check_array_results_non_empty(_inputs: VerbInput, outputs: VerbOutput) -> bool: - return ( + return bool( name in outputs.outputs and outputs.outputs[name] and isinstance(outputs.outputs[name], list) diff --git a/python/reactivedataflow/tests/unit/test_conditions.py b/python/reactivedataflow/tests/unit/test_conditions.py new file mode 100644 index 00000000..dcf31109 --- /dev/null +++ b/python/reactivedataflow/tests/unit/test_conditions.py @@ -0,0 +1,29 @@ +# Copyright (c) 2024 Microsoft Corporation. +"""reactivedataflow Conditions Tests.""" + +from reactivedataflow import VerbInput, VerbOutput +from reactivedataflow.conditions import ( + array_result_not_empty, + output_is_not_none, +) +from reactivedataflow.constants import default_output + + +def test_array_results_not_empty(): + check = array_result_not_empty() + inputs = VerbInput() + outputs = VerbOutput({default_output: []}) + assert check(inputs, outputs) is False + + outputs = VerbOutput({default_output: [1]}) + assert check(inputs, outputs) is True + + +def test_output_is_not_none(): + check = output_is_not_none(default_output) + inputs = VerbInput() + outputs = VerbOutput({default_output: None}) + assert check(inputs, outputs) is False + + outputs = VerbOutput({default_output: 1}) + assert check(inputs, outputs) is True