test: topology: Add helper to retrieve graph-global attributes

This will allow us to define attributes that are specific to a
particular test system.
This commit is contained in:
Tobias Waldekranz
2024-05-20 16:21:06 +02:00
parent e53f3362be
commit 52c6c2274e
+12 -8
View File
@@ -1,6 +1,15 @@
import networkx as nx
from networkx.algorithms import isomorphism
def _qstrip(text):
if text == None:
return None
if text.startswith("\"") and text.endswith("\""):
return text[1:-1]
return text
def map_edges(les, pes):
acc = []
les = sorted(list(les.values()), key=lambda x: x.get("kind", ""), reverse=True)
@@ -22,14 +31,6 @@ def match_edge(pes, les):
class Topology:
def __init__(self, dotg):
def _qstrip(text):
if text == None:
return None
if text.startswith("\"") and text.endswith("\""):
return text[1:-1]
return text
self.dotg = dotg
self.g = nx.MultiGraph()
@@ -142,6 +143,9 @@ class Topology:
def get_infixen(self):
return self.get_nodes(lambda _, attrs: attrs.get("kind") == "infix")
def get_attr(self, name, default=None):
return _qstrip(self.dotg.get_attributes().get(name, default))
# Support calling this script like so...
#
# python3 topology.py <physical> <logical>