Skip to content

Commit

Permalink
Merge pull request #48 from SebastianScherer88/recursive-non-null-dic…
Browse files Browse the repository at this point in the history
…t-func

Recursive non null dict func
  • Loading branch information
SebastianScherer88 authored Nov 28, 2024
2 parents 3a5f52e + bdec300 commit b75bf91
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 50 deletions.
14 changes: 14 additions & 0 deletions sdk/bettmensch_ai/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@


def copy_non_null_dict(original_dict: Dict) -> Dict:
"""Utility function that copies a dictionary without any of its None type
values (however deep they might be nested).
Args:
original_dict (Dict): The dictionary to copy
Returns:
Dict: The copied dictionary without any None type values.
"""
non_null_dict = original_dict.copy()

for k, v in original_dict.items():
if v is None:
del non_null_dict[k]
elif isinstance(v, dict):
non_null_dict[k] = copy_non_null_dict(v)
else:
pass

return non_null_dict
3 changes: 2 additions & 1 deletion sdk/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ UNINSTALL?=true
REMOVE_BUILD?=true
EXTRAS?=pipelines# see sdk's setup.py for all options
SUITE?=unit# unit,integration,k8s
PYTEST_SUBPATH?=
PYTEST_FLAGS?= # e.g. "-m standard", "-m ddp" for k8s suite appended to the `addopts` setting of the pytest.ini
sdk.install:
@echo "::group::Installing sdk with $(EXTRAS) extras"
Expand All @@ -22,7 +23,7 @@ sdk.install:
sdk.test:
@echo "::group::Running sdk $(SUITE) test suite"
@echo "::group:: Commit: $(COMMIT)"
pytest ./sdk/test/$(SUITE)/ $(PYTEST_FLAGS) # > ./sdk/test/$(SUITE)/outputs/pytest.out
pytest ./sdk/test/$(SUITE)/$(PYTEST_SUBPATH) $(PYTEST_FLAGS) # > ./sdk/test/$(SUITE)/outputs/pytest.out
@echo "::endgroup::"

sdk.uninstall:
Expand Down
Empty file.
48 changes: 48 additions & 0 deletions sdk/test/unit/server/test_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os

from bettmensch_ai.server import RegisteredFlow


def test_flow_from_hera_artifact_workflow_model(
test_output_dir,
test_hera_artifact_workflow_model,
):

test_artifact_flow = RegisteredFlow.from_hera_workflow_model(
test_hera_artifact_workflow_model
)

with open(
os.path.join(test_output_dir, "test-artifact-server-flow.json"), "w"
) as file:
file.write(test_artifact_flow.model_dump_json())


def test_flow_from_hera_parameter_workflow_model(
test_output_dir,
test_hera_parameter_workflow_model,
):

test_parameter_flow = RegisteredFlow.from_hera_workflow_model(
test_hera_parameter_workflow_model
)

with open(
os.path.join(test_output_dir, "test-parameter-server-flow.json"), "w"
) as file:
file.write(test_parameter_flow.model_dump_json())


def test_flow_from_hera_torch_gpu_workflow_model(
test_output_dir,
test_hera_torch_gpu_workflow_model,
):

test_torch_gpu_flow = RegisteredFlow.from_hera_workflow_model(
test_hera_torch_gpu_workflow_model
)

with open(
os.path.join(test_output_dir, "test-torch-gpu-server-flow.json"), "w"
) as file:
file.write(test_torch_gpu_flow.model_dump_json())
57 changes: 57 additions & 0 deletions sdk/test/unit/server/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os

from bettmensch_ai.server import RegisteredPipeline


def test_pipeline_from_hera_artifact_workflow_template_model(
test_output_dir,
test_hera_artifact_workflow_template_model,
):

test_artifact_pipeline = (
RegisteredPipeline.from_hera_workflow_template_model(
test_hera_artifact_workflow_template_model
)
)

with open(
os.path.join(test_output_dir, "test-artifact-server-pipeline.json"),
"w",
) as file:
file.write(test_artifact_pipeline.model_dump_json())


def test_pipeline_from_hera_parameter_workflow_template_model(
test_output_dir,
test_hera_parameter_workflow_template_model,
):

test_parameter_pipeline = (
RegisteredPipeline.from_hera_workflow_template_model(
test_hera_parameter_workflow_template_model
)
)

with open(
os.path.join(test_output_dir, "test-parameter-server-pipeline.json"),
"w",
) as file:
file.write(test_parameter_pipeline.model_dump_json())


def test_pipeline_from_hera_torch_gpu_workflow_template_model(
test_output_dir,
test_hera_torch_gpu_workflow_template_model,
):

test_torch_gpu_pipeline = (
RegisteredPipeline.from_hera_workflow_template_model(
test_hera_torch_gpu_workflow_template_model
)
)

with open(
os.path.join(test_output_dir, "test-torch-gpu-server-pipeline.json"),
"w",
) as file:
file.write(test_torch_gpu_pipeline.model_dump_json())
49 changes: 0 additions & 49 deletions sdk/test/unit/server/test_server.py

This file was deleted.

14 changes: 14 additions & 0 deletions sdk/test/unit/server/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from bettmensch_ai.server.utils import copy_non_null_dict


def test_copy_non_null_dict():

test_dict = {
"a": None,
"b": 2,
"c": {"d": None, "e": 5, "f": {"g": None, "h": 8}},
}

non_null_dict = copy_non_null_dict(test_dict)

assert non_null_dict == {"b": 2, "c": {"e": 5, "f": {"h": 8}}}

0 comments on commit b75bf91

Please sign in to comment.