Skip to content

Commit

Permalink
WIP: support TOML workflows specs file
Browse files Browse the repository at this point in the history
Closes #21

Took 26 minutes
  • Loading branch information
EpicWink committed Feb 26, 2020
1 parent 50a6582 commit e5abf0c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/seddy/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from ruamel import yaml
except ImportError:
yaml = e
try:
import toml
except ImportError as e: # pragma: no cover
toml = e

from . import decisions as seddy_decisions

Expand Down Expand Up @@ -172,4 +176,8 @@ def load_workflows(workflows_file: pathlib.Path) -> t.Dict[str, t.Any]:
if isinstance(yaml, Exception):
raise yaml
return yaml.safe_load(workflows_text)
elif workflows_file.suffix == ".toml":
if isinstance(toml, Exception):
raise toml
return toml.loads(workflows_text)
raise ValueError("Unknown extension: %s" % workflows_file.suffix)
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pytest-cov
coloredlogs
moto
pyyaml
toml
33 changes: 33 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from seddy import _util as seddy_util
import pytest
import yaml
import toml


def test_list_paginated():
Expand Down Expand Up @@ -88,6 +89,38 @@ def test_load_workflows_yaml_raises(tmp_path, workflows_spec):
assert e.value == yaml_exc


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_exc = ModuleNotFoundError("toml")
toml_patch = mock.patch.object(seddy_util, "toml", toml_exc)

# Build input
workflows_file = tmp_path / "workflows.toml"
workflows_file.write_text(toml.dumps(workflows_spec))

# Run function
with pytest.raises(ModuleNotFoundError) as e, toml_patch:
seddy_util.load_workflows(workflows_file)
assert e.value == toml_exc


def test_load_workflows_with_incorrect_suffix(tmp_path, workflows_spec):
"""Test workflows specs loading raises for incorrect suffix."""
# Build input
Expand Down

0 comments on commit e5abf0c

Please sign in to comment.