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 3407e2c commit bd8997d
Show file tree
Hide file tree
Showing 4 changed files with 39 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
6 changes: 6 additions & 0 deletions src/seddy/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
31 changes: 31 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from seddy import _util as seddy_util
import pytest
import yaml
import toml


def test_list_paginated():
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bd8997d

Please sign in to comment.