"""Offline checks for sandbox verification parsing.""" import importlib.util import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[2] spec = importlib.util.spec_from_file_location('sandbox_verify', ROOT / 'scripts/network-sandbox-verify-host.py') verify = importlib.util.module_from_spec(spec) spec.loader.exec_module(verify) class SandboxVerifyTests(unittest.TestCase): def test_vlan_output(self): output = 'port vlan ids\ntap9100i1 1 PVID Egress Untagged\n 10\n 20\n' self.assertEqual(verify.vlan_ids(output), {1, 10, 20}) def test_expected_client_address(self): output = '2: eth0: \n inet 172.29.210.101/24 scope global eth0\n' self.assertEqual(verify.address_from_output(output, '172.29.210.0/24'), '172.29.210.101') with self.assertRaises(RuntimeError): verify.address_from_output(output, '172.29.220.0/24') if __name__ == '__main__': unittest.main()