def test_exclude(self, exclude): """ NetPlanParser.parse() should honor the "exclude" parameter. """ parser = npparser.Parser(dirs=[ 'test_data/override/lib/netplan', 'test_data/override/etc/netplan', 'test_data/override/run/netplan', ]) files = parser.find_files() self.assertEqual(files, [ 'test_data/override/lib/netplan/01-override.yaml', ]) data = parser.parse(exclude=exclude) self.assertEqual(data.data, {}) parser = npparser.Parser(dirs=[ 'test_data/override/lib/netplan', 'test_data/override/etc-2/netplan', 'test_data/override/run/netplan', ]) files = parser.find_files() self.assertEqual(files, [ 'test_data/override/etc-2/netplan/01-override.yaml', ]) data = parser.parse(exclude=exclude) self.assertEqual(data.data, {})
def test_override(self): # type: (TestParser) -> None """ A file should override a file with the same name in an earlier directory. """ parser = npparser.Parser(dirs=[ "test_data/override/lib/netplan", "test_data/override/etc/netplan", "test_data/override/run/netplan", ]) files = parser.find_files() assert files == ["test_data/override/lib/netplan/01-override.yaml"] data = parser.parse() assert list(data.data.keys()) == ["eno1"] parser = npparser.Parser(dirs=[ "test_data/override/lib/netplan", "test_data/override/etc-2/netplan", "test_data/override/run/netplan", ]) files = parser.find_files() assert files == ["test_data/override/etc-2/netplan/01-override.yaml"] data = parser.parse() assert list(data.data.keys()) == ["eno2"]
def test_override(self): """ A file should override a file with the same name in an earlier directory. """ parser = npparser.Parser(dirs=[ 'test_data/override/lib/netplan', 'test_data/override/etc/netplan', 'test_data/override/run/netplan', ]) files = parser.find_files() self.assertEqual(files, [ 'test_data/override/lib/netplan/01-override.yaml', ]) data = parser.parse() self.assertEqual(list(data.data.keys()), ['eno1']) parser = npparser.Parser(dirs=[ 'test_data/override/lib/netplan', 'test_data/override/etc-2/netplan', 'test_data/override/run/netplan', ]) files = parser.find_files() self.assertEqual(files, [ 'test_data/override/etc-2/netplan/01-override.yaml', ]) data = parser.parse() self.assertEqual(list(data.data.keys()), ['eno2'])
def test_combine(self, cur, new, res): """ Unit tests for the _combine_dict() method. """ parser = npparser.Parser() data = cur parser._combine_dicts(data, new) self.assertEqual(data, res)
def test_combine( self, # type: TestParserCombine cur, # type: Dict[str, Any] new, # type: Dict[str, Any] res, # type: Dict[str, Any] ): # type: (...) -> None """ Unit tests for the _combine_dict() method. """ parser = npparser.Parser() data = cur parser._combine_dicts(data, new) # pylint: disable=protected-access assert data == res
def test_related(self, subdir, ifaces, parents, phys): """ get_all_interfaces() should return all the related interfaces, and get_physical_interfaces() should only return physical interfaces. """ dirs = [ 'test_data/{sub}/{d}/netplan'.format(sub=subdir, d=d) for d in ('lib', 'etc', 'run') ] parser = npparser.Parser(dirs=dirs) data = parser.parse() self.assertTrue(set(ifaces).issubset(set(data.data.keys()))) self.assertEqual(str(data.get_all_interfaces(ifaces)), parents) self.assertEqual(str(data.get_physical_interfaces(ifaces)), phys)
def test_exclude(self, exclude): # type: (TestParser, List[str]) -> None """ NetPlanParser.parse() should honor the "exclude" parameter. """ parser = npparser.Parser(dirs=[ "test_data/override/lib/netplan", "test_data/override/etc/netplan", "test_data/override/run/netplan", ]) files = parser.find_files() assert files == ["test_data/override/lib/netplan/01-override.yaml"] data = parser.parse(exclude=exclude) assert data.data == {} parser = npparser.Parser(dirs=[ "test_data/override/lib/netplan", "test_data/override/etc-2/netplan", "test_data/override/run/netplan", ]) files = parser.find_files() assert files == ["test_data/override/etc-2/netplan/01-override.yaml"] data = parser.parse(exclude=exclude) assert data.data == {}
def test_mtu(self, subdir, exclude, iface, mtu): """ _combine_dict() and "exclude" should work together to parse some real-life data files. """ dirs = [ 'test_data/{sub}/{d}/netplan'.format(sub=subdir, d=d) for d in ('lib', 'etc', 'run') ] parser = npparser.Parser(dirs=dirs) if exclude is None: data = parser.parse() else: data = parser.parse(exclude=exclude) self.assertIn(iface, data.data) self.assertEqual(data.data[iface].get('mtu'), mtu)
def test_related( self, # type: TestParser subdir, # type: str ifaces, # type: List[str] parents, # type: str phys, # type: str ): # type: (...) -> None """ get_all_interfaces() should return all the related interfaces, and get_physical_interfaces() should only return physical interfaces. """ dirs = [ "test_data/{sub}/{d}/netplan".format(sub=subdir, d=d) for d in ("lib", "etc", "run") ] parser = npparser.Parser(dirs=dirs) data = parser.parse() assert set(ifaces).issubset(set(data.data.keys())) assert str(data.get_all_interfaces(ifaces)) == parents assert str(data.get_physical_interfaces(ifaces)) == phys
def test_mtu( self, # type: TestParser subdir, # type: str exclude, # type: Optional[List[str]] iface, # type: str mtu, # type: Optional[int] ): # type: (...) -> None """ _combine_dict() and "exclude" should work together to parse some real-life data files. """ dirs = [ "test_data/{sub}/{d}/netplan".format(sub=subdir, d=d) for d in ("lib", "etc", "run") ] parser = npparser.Parser(dirs=dirs) if exclude is None: data = parser.parse() else: data = parser.parse(exclude=exclude) assert iface in data.data assert data.data[iface].get("mtu") == mtu