From 52c6c2274e8bdd5958650fc199f1877753be0f37 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Wed, 15 May 2024 08:59:18 +0000 Subject: [PATCH] test: topology: Add helper to retrieve graph-global attributes This will allow us to define attributes that are specific to a particular test system. --- test/infamy/topology.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/infamy/topology.py b/test/infamy/topology.py index 4a365ae4..a94e9a98 100644 --- a/test/infamy/topology.py +++ b/test/infamy/topology.py @@ -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