Skip to content
Snippets Groups Projects
Commit feab0166 authored by Jacob Wahlman's avatar Jacob Wahlman :ok_hand:
Browse files

added test files and utils module

parent a1eeb37b
No related branches found
No related tags found
2 merge requests!33Resolve "Load/Save SFG to file",!27Resolve "Load/Save SFG to file"
Pipeline #13728 failed
......@@ -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
"""@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
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
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