]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/munet/compat.py
Merge pull request #13455 from sri-mohan1/srib-ldpd
[mirror_frr.git] / tests / topotests / munet / compat.py
1 # -*- coding: utf-8 eval: (blacken-mode 1) -*-
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 #
4 # November 16 2022, Christian Hopps <chopps@labn.net>
5 #
6 # Copyright (c) 2022, LabN Consulting, L.L.C.
7 #
8 """Provide compatible APIs."""
9
10
11 class PytestConfig:
12 """Pytest config duck-type-compatible object using argprase args."""
13
14 class Namespace:
15 """A namespace defined by a dictionary of values."""
16
17 def __init__(self, args):
18 self.args = args
19
20 def __getattr__(self, attr):
21 return self.args[attr] if attr in self.args else None
22
23 def __init__(self, args):
24 self.args = vars(args)
25 self.option = PytestConfig.Namespace(self.args)
26
27 def getoption(self, name, default=None, skip=False):
28 assert not skip
29 if name.startswith("--"):
30 name = name[2:]
31 name = name.replace("-", "_")
32 if name in self.args:
33 return self.args[name] if self.args[name] is not None else default
34 return default