From 4f5df39571851ce624862b071159c8affbecf0ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <alan.munoz@ed.ac.uk>
Date: Thu, 22 Sep 2022 13:40:29 +0100
Subject: [PATCH] tests(agora): migrate tests

---
 tests/agora/base_test.py    | 45 +++++++++++++++++++++++++++++++++++++
 tests/agora/example_test.py | 25 +++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100644 tests/agora/base_test.py
 create mode 100644 tests/agora/example_test.py

diff --git a/tests/agora/base_test.py b/tests/agora/base_test.py
new file mode 100644
index 00000000..11bdbed5
--- /dev/null
+++ b/tests/agora/base_test.py
@@ -0,0 +1,45 @@
+"""
+Basic ParametersIO tests
+"""
+
+import pytest
+
+from agora.abc import ParametersABC
+
+
+class DummyParameters(ParametersABC):
+    yaml_file = "tests/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
+
+    @classmethod
+    def default(cls):
+        return cls.from_dict({})
+
+
+def test_to_yaml():
+    DummyParameters.default().to_yaml()
+
+
+def test_from_yaml():
+    DummyParameters.default().test_yaml()
+
+
+def test_to_dict():
+    DummyParameters.default().to_dict()
diff --git a/tests/agora/example_test.py b/tests/agora/example_test.py
new file mode 100644
index 00000000..539b410a
--- /dev/null
+++ b/tests/agora/example_test.py
@@ -0,0 +1,25 @@
+"""This is an example test file to show the structure."""
+import pytest
+
+from agora.utils.example import ExampleClass, example_function
+
+
+class TestExampleClass:
+    x = ExampleClass(1)
+
+    def test_add_one(self):
+        assert self.x.add_one() == 2
+
+    def test_add_n(self):
+        assert self.x.add_n(10) == 11
+
+
+def test_example_function():
+    x = example_function(1)
+    assert isinstance(x, ExampleClass)
+    assert x.parameter == 1
+
+
+def test_example_function_fail():
+    with pytest.raises(ValueError):
+        example_function("hello")
-- 
GitLab