Skip to content
Snippets Groups Projects
Commit 0d945ec3 authored by Alán Muñoz's avatar Alán Muñoz
Browse files

tests(agora): fix tests

parent be7f6480
No related branches found
No related tags found
No related merge requests found
...@@ -8,38 +8,41 @@ from agora.abc import ParametersABC ...@@ -8,38 +8,41 @@ from agora.abc import ParametersABC
class DummyParameters(ParametersABC): class DummyParameters(ParametersABC):
# TODO add default data folder and load for all tests def __init__(self, **kwargs):
yaml_file = "tests/agora/data/parameters.yaml" super().__init__(**kwargs)
def __init__(self):
super().__init__()
def test_dict(self):
param_dict = dict(a="a", b="b", c=dict(d="d", e="e"))
params = self.from_dict(param_dict)
assert params.to_dict() == param_dict
# Remove
params.to_yaml(self.yaml_file)
def test_yaml(self):
# From yaml
params = self.from_yaml(self.yaml_file)
# To yaml
with open(self.yaml_file, "r") as fd:
yaml_data = fd.read()
assert params.to_yaml() == yaml_data
@classmethod @classmethod
def default(cls): def default(cls):
# Necessary empty builder
return cls.from_dict({}) return cls.from_dict({})
def test_to_yaml(): def test_from_yaml(yaml_file):
DummyParameters.default().to_yaml() # From yaml
params = DummyParameters.from_yaml(yaml_file)
def test_from_yaml(): def test_from_stdin(yaml_file):
DummyParameters.default().test_yaml() # From yaml
params = DummyParameters.from_yaml(yaml_file)
# To yaml
assert isinstance(params, ParametersABC)
def test_to_yaml(yaml_file):
with open(yaml_file, "r") as fd:
yaml_data = fd.read()
params = DummyParameters.from_yaml(yaml_file)
assert params.to_yaml() == yaml_data
def test_dict(example_dict):
params = DummyParameters(**example_dict)
assert params.to_dict() == param_dict
# Remove
params.to_yaml("outfile.yml")
def test_to_dict(): def test_to_dict():
......
#!/usr/bin/env jupyter
"""
Load data necessary to test agora.
"""
import typing as t
from pathlib import Path
import pytest
@pytest.fixture(scope="module")
def yaml_file():
return Path(__file__).parent / "data/parameters.yaml"
@pytest.fixture(scope="module", autouse=True)
def parameters_example() -> t.Dict:
return dict(
string="abc",
number=1,
boolean=True,
dictionary=dict(
empty_dict=dict(),
string="def",
number=2,
),
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment