Files
vppcfg/vppcfg/config/test_tap.py
Ray Kinsella 9f2ef0e56a build: fix python load paths
Fixed python load paths so that vppcfg will work installed as python
library and standalone from the source directory, fixing load
pathes for resources such as yaml files along the way.

Added a make target for pylint called 'make check-style', fixed a
number of minor pylint issues along the way.

Signed-off-by: Ray Kinsella <mdr@ashroe.eu>
2022-07-12 15:38:14 +01:00

53 lines
1.9 KiB
Python

#
# Copyright (c) 2022 Pim van Pelt
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -*- coding: utf-8 -*-
""" Unit tests for taps """
import unittest
import yaml
from . import tap
from .unittestyaml import UnitTestYaml
class TestTAPMethods(unittest.TestCase):
def setUp(self):
with UnitTestYaml("test_tap.yaml") as f:
self.cfg = yaml.load(f, Loader=yaml.FullLoader)
def test_get_by_name(self):
ifname, iface = tap.get_by_name(self.cfg, "tap0")
self.assertIsNotNone(iface)
self.assertEqual("tap0", ifname)
ifname, iface = tap.get_by_name(self.cfg, "tap-noexist")
self.assertIsNone(ifname)
self.assertIsNone(iface)
def test_is_tap(self):
self.assertTrue(tap.is_tap(self.cfg, "tap0"))
self.assertTrue(tap.is_tap(self.cfg, "tap1"))
self.assertFalse(tap.is_tap(self.cfg, "tap-noexist"))
def test_is_host_name_unique(self):
self.assertTrue(tap.is_host_name_unique(self.cfg, "tap0"))
self.assertTrue(tap.is_host_name_unique(self.cfg, "tap1"))
self.assertTrue(tap.is_host_name_unique(self.cfg, "tap-noexist"))
self.assertFalse(tap.is_host_name_unique(self.cfg, "vpp-tap"))
def test_enumerators(self):
ifs = tap.get_taps(self.cfg)
self.assertEqual(len(ifs), 4)
self.assertIn("tap0", ifs)
self.assertIn("tap1", ifs)
self.assertNotIn("tap-noexist", ifs)