Skip to content

Commit

Permalink
add typehints for required CS attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Helveg committed Jul 25, 2023
1 parent bde9795 commit e28742b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bsb/storage/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from .._util import obj_str_insert, immutable


if typing.TYPE_CHECKING:
from ..cell_types import CellType


@config.pluggable(key="engine", plugin_name="storage engine")
class StorageNode:
root = config.slot()
Expand Down Expand Up @@ -364,6 +368,10 @@ def __init__(self, engine, cell_type):
self._type = cell_type
self._tag = cell_type.name

@abc.abstractmethod
def __len__(self):
pass

@obj_str_insert
def __repr__(self):
cell_type = self.cell_type
Expand Down Expand Up @@ -887,6 +895,15 @@ class ConnectivitySet(Interface):
connections.
"""

# The following attributes must be set on each ConnectivitySet by the engine:
tag: str
pre_type: "CellType"
post_type: "CellType"

@abc.abstractmethod
def __len__(self):
pass

@classmethod
@abc.abstractmethod
def create(cls, engine, tag):
Expand Down
12 changes: 12 additions & 0 deletions bsb/unittest/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,18 @@ def test_require(self):
"must exist after require",
)

def test_attrs(self):
ct = self.network.cell_types.add(
"new_cell", dict(spatial=dict(radius=2, density=1e-3))
)
self.network.require_connectivity_set(
ct, self.network.cell_types.test_cell, "test"
)
cs = self.storage._ConnectivitySet(self.storage._engine, "test")
for attr in ("tag", "pre_type", "post_type"):
with self.subTest(attr=attr):
self.assertTrue(hasattr(cs, attr), f"CS must have `{attr}` attr")

def test_io(self):
# Test that connections can be stored over chunked layout and can be loaded again.
cs = self.network.get_connectivity_set("all_to_all")
Expand Down

0 comments on commit e28742b

Please sign in to comment.