Documentation, comments and small changes

This commit is contained in:
2026-09-27 16:18:35 +03:00
parent 0e43b943c4
commit e1e164bd65
8 changed files with 653 additions and 211 deletions
+9 -19
View File
@@ -15,13 +15,16 @@ Author: Christos Choutouridis <cchoutou@ece.auth.gr>
"""
import json
from pathlib import Path
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Any, Dict, Union
from typing import Any, Dict, Union
from topology_parser import Topology, parse_topology
# ============================ Types and errors ============================
PathLike = Union[str, Path]
@@ -29,6 +32,8 @@ class TopologyLoadError(ValueError):
"""Raised when a topology file cannot be loaded as a JSON object."""
# ============================ Public interface ============================
def load_topology(path: PathLike) -> Dict[str, Any]:
"""Load a topology JSON file into a raw dictionary.
@@ -66,23 +71,8 @@ def load_topology(path: PathLike) -> Dict[str, Any]:
return raw
def load(path: PathLike) -> Topology:
"""Load and parse a topology file in one convenience call.
Args:
path: Path to the topology JSON file.
Returns:
Parsed Topology model.
Raises:
TopologyLoadError: If the JSON file cannot be loaded.
topology_parser.TopologyParseError: If the loaded JSON cannot be
represented by the topology grammar.
"""
return parse_topology(load_topology(path))
# =============================== Self-test ===============================
def _self_test() -> None:
"""Run a small smoke test against load_topology() and load()."""
@@ -108,7 +98,7 @@ def _self_test() -> None:
handle.flush()
raw = load_topology(handle.name)
topology = load(handle.name)
topology = parse_topology(load_topology(handle.name))
assert raw["nodes"][0]["name"] == "s1"
assert topology.nodes[0].name == "s1"