mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-05 15:13:02 +02:00
test: env: Add support for querying global attributes
This will let other Infamy submodules tune their behavior based on the particular test system they are running on. Attributes are defined by creating graph-global attributes with an "ix_" prefix.
This commit is contained in:
@@ -7,6 +7,12 @@ import sys
|
||||
|
||||
from . import neigh, netconf, tap, topology
|
||||
|
||||
class NullEnv:
|
||||
def attr(self, _, default=None):
|
||||
return default
|
||||
|
||||
ENV = NullEnv()
|
||||
|
||||
class ArgumentParser(argparse.ArgumentParser):
|
||||
def __init__(self, ltop):
|
||||
super().__init__()
|
||||
@@ -37,6 +43,21 @@ class Env(object):
|
||||
|
||||
print(repr(self.ltop))
|
||||
|
||||
global ENV
|
||||
ENV = self
|
||||
|
||||
def attr(self, name, default=None):
|
||||
val = self.ptop.get_attr("ix_" + name)
|
||||
if val == None:
|
||||
return default
|
||||
|
||||
try:
|
||||
return int(val, 0)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return val
|
||||
|
||||
def attach(self, node, port, factory_default=True):
|
||||
if self.ltop:
|
||||
mapping = self.ltop.mapping[node]
|
||||
|
||||
Reference in New Issue
Block a user