From feab0166c5af888236719fd0af4191f8fecc198e Mon Sep 17 00:00:00 2001
From: Jacob Wahlman <jacwa448@student.liu.se>
Date: Wed, 22 Apr 2020 12:02:34 +0200
Subject: [PATCH] added test files and utils module

---
 b_asic/__init__.py               |  1 +
 b_asic/utils.py                  | 31 ++++++++++++++++++++++++
 test/test_load_save_structure.py | 41 ++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+)
 create mode 100644 b_asic/utils.py
 create mode 100644 test/test_load_save_structure.py

diff --git a/b_asic/__init__.py b/b_asic/__init__.py
index bd3574ba..cdbe8a13 100644
--- a/b_asic/__init__.py
+++ b/b_asic/__init__.py
@@ -12,3 +12,4 @@ from b_asic.signal_flow_graph import *
 from b_asic.signal import *
 from b_asic.simulation import *
 from b_asic.special_operations import *
+from b_asic.utils import *
\ No newline at end of file
diff --git a/b_asic/utils.py b/b_asic/utils.py
new file mode 100644
index 00000000..d8df7767
--- /dev/null
+++ b/b_asic/utils.py
@@ -0,0 +1,31 @@
+"""@package docstring
+B-ASIC Utils Module.
+This module contains functions that are used as utilities by other modules or by the user.
+"""
+
+from typing import Optional
+import pickle
+
+from b_asic import AbstractOperation
+
+
+def save_structure(struct: AbstractOperation, path: Optional[str] = None) -> str: 
+    """Saves the structure to a specific path using the pickle module.
+    Returns the path to the struct if save succeeds.
+    
+    Arguments:
+    struct: The structure to save.
+
+    Keyword Arguments:
+    path: The path to which the structure will be saved.
+    """
+    pass
+
+def load_structure(path: str) -> AbstractOperation:
+    """Saves the structure to a specific path using the pickle module.
+    Returns the struct that was loaded from the path.
+
+    Keyword Arguments:
+    path: The path to which the structure will be loaded from.
+    """
+    pass
\ No newline at end of file
diff --git a/test/test_load_save_structure.py b/test/test_load_save_structure.py
new file mode 100644
index 00000000..d1515820
--- /dev/null
+++ b/test/test_load_save_structure.py
@@ -0,0 +1,41 @@
+from os.path import isfile
+
+import pytest
+
+from b_asic import SFG, Output, load_structure, save_structure
+
+
+class TestSaveStructures:
+
+    def test_save_sfg(self, large_operation_tree):
+        sfg = SFG(outputs=[Output(large_operation_tree)])
+        path = save_structure(sfg)
+        
+        assert path is not None
+        assert isfile(path)
+
+    def test_load_sfg(self, large_operation_tree):
+        sfg = SFG(outputs=[Output(large_operation_tree)])
+        path = save_structure(sfg)
+        _sfg = load_structure(path)
+        
+        assert isinstance(_sfg, SFG)
+        assert sfg.components == _sfg.components
+
+    def test_save_sfg_custom_path(self, large_operation_tree):
+        sfg = SFG(outputs=[Output(large_operation_tree)])
+        path = save_structure(sfg, path="structures/test")
+        
+        assert path is not None
+        assert isfile(path)
+
+    def test_load_sfg_custom_path(self, large_operation_tree):
+        sfg = SFG(outputs=[Output(large_operation_tree)])
+        path = save_structure(sfg, path="structures/test")
+        _sfg = load_structure(path)
+
+        assert isinstance(_sfg, SFG)
+        assert sfg.components == _sfg.components   
+
+
+
-- 
GitLab