diff --git a/README.md b/README.md index f0d94b6..00dfb8e 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ pip3 install seddy Install extra packages for further functionality * Coloured logging: ``coloredlogs`` * YAML workflows specs file: ``pyyaml`` or ``ruamel.yaml`` +* TOML workflows specs file: ``toml`` ## Usage Get the CLI usage diff --git a/src/seddy/_util.py b/src/seddy/_util.py index 9c4cc09..7ba9de0 100644 --- a/src/seddy/_util.py +++ b/src/seddy/_util.py @@ -174,4 +174,10 @@ def load_workflows(workflows_file: pathlib.Path) -> t.Dict[str, t.Any]: except ImportError as er: raise e from er return yaml.safe_load(workflows_text) + elif workflows_file.suffix == ".toml": + try: + import toml + except ImportError: + raise + return toml.loads(workflows_text) raise ValueError("Unknown extension: %s" % workflows_file.suffix) diff --git a/tests/requirements.txt b/tests/requirements.txt index 8c65f14..f883602 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -3,3 +3,4 @@ pytest-cov coloredlogs moto pyyaml +toml diff --git a/tests/test_util.py b/tests/test_util.py index 19ba15e..f06c2cf 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -7,6 +7,7 @@ from seddy import _util as seddy_util import pytest import yaml +import toml def test_list_paginated(): @@ -87,6 +88,36 @@ def test_load_workflows_yaml_raises(tmp_path, workflows_spec): seddy_util.load_workflows(workflows_file) +def test_load_workflows_toml(tmp_path, workflows_spec): + """Test workflows specs loading from TOML.""" + # Build input + workflows_file = tmp_path / "workflows.yml" + workflows_file.write_text(toml.dumps(workflows_spec)) + print(workflows_file.read_text()) + + # Run function + res = seddy_util.load_workflows(workflows_file) + print(workflows_spec) + print(res) + print(json.dumps(workflows_spec, indent=4)) + print(json.dumps(res, indent=4)) + assert res == workflows_spec + + +def test_load_workflows_toml_raises(tmp_path, workflows_spec): + """Test workflows specs loading from TOML raises when unavailable.""" + # Setup environment + toml_patch = mock.patch.dict(sys.modules, {"toml": None}) + + # Build input + workflows_file = tmp_path / "workflows.toml" + workflows_file.write_text(toml.dumps(workflows_spec)) + + # Run function + with pytest.raises(ModuleNotFoundError), toml_patch: + seddy_util.load_workflows(workflows_file) + + def test_load_workflows_with_incorrect_suffix(tmp_path, workflows_spec): """Test workflows specs loading raises for incorrect suffix.""" # Build input