diff --git a/b_asic/__init__.py b/b_asic/__init__.py index bd3574ba07b2556fae03ff8fa22deecfd2656705..cdbe8a133310900f5404f9e6b8c7aa552bb7ff77 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 0000000000000000000000000000000000000000..d8df7767f9d3d612550f5a0e39654093c19561ef --- /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 0000000000000000000000000000000000000000..d1515820a8aef1e05b9efe9970d8d636fd12859f --- /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 + + +