From 0d945ec3c7503789fb0c7ca0ccfc2df6585fa92c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <alan.munoz@ed.ac.uk>
Date: Sat, 24 Sep 2022 15:51:18 +0100
Subject: [PATCH] tests(agora): fix tests

---
 tests/agora/base_test.py | 51 +++++++++++++++++++++-------------------
 tests/agora/conftest.py  | 27 +++++++++++++++++++++
 2 files changed, 54 insertions(+), 24 deletions(-)
 create mode 100644 tests/agora/conftest.py

diff --git a/tests/agora/base_test.py b/tests/agora/base_test.py
index c25a294e..8e05d0bd 100644
--- a/tests/agora/base_test.py
+++ b/tests/agora/base_test.py
@@ -8,38 +8,41 @@ from agora.abc import ParametersABC
 
 
 class DummyParameters(ParametersABC):
-    # TODO add default data folder and load for all tests
-    yaml_file = "tests/agora/data/parameters.yaml"
-
-    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
+    def __init__(self, **kwargs):
+        super().__init__(**kwargs)
 
     @classmethod
     def default(cls):
+        # Necessary empty builder
         return cls.from_dict({})
 
 
-def test_to_yaml():
-    DummyParameters.default().to_yaml()
+def test_from_yaml(yaml_file):
+    # From yaml
+    params = DummyParameters.from_yaml(yaml_file)
 
 
-def test_from_yaml():
-    DummyParameters.default().test_yaml()
+def test_from_stdin(yaml_file):
+    # 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():
diff --git a/tests/agora/conftest.py b/tests/agora/conftest.py
new file mode 100644
index 00000000..6804b892
--- /dev/null
+++ b/tests/agora/conftest.py
@@ -0,0 +1,27 @@
+#!/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,
+        ),
+    )
-- 
GitLab