def test_genie_parse_no_genie(monkeypatch): def mock_import_module(name, package): raise ModuleNotFoundError monkeypatch.setattr(importlib, "import_module", mock_import_module) with pytest.warns(UserWarning) as warning_msg: genie_parse(platform="blah", command="blah", output="blah") assert ( str(warning_msg._list[0].message) == "\n***** Module 'None' not installed! ****************************************************\nTo resolve this issue, install 'None'. You can do this in one of the following ways:\n1: 'pip install -r requirements-genie.txt'\n2: 'pip install scrapli[genie]'\n***** Module 'None' not installed! ****************************************************" )
def test_genie_no_genie_installed(monkeypatch): def _import_module(name, package): raise ModuleNotFoundError monkeypatch.setattr("importlib.import_module", _import_module) with pytest.warns(UserWarning) as exc: output = genie_parse("cisco_nxos", "show racecar", "something") assert "Optional Extra Not Installed!" in str(exc.list[0].message) assert output == []
def genie_parse_output(self) -> Union[Dict[str, Any], List[Any]]: """ Parse results with genie, always return structured data Returns an empty list if parsing fails! Args: N/A Returns: structured_result: empty list or parsed data from genie Raises: N/A """ structured_result = genie_parse(self.genie_platform, self.channel_input, self.result) return structured_result
def test_genie_parse_failure(): result = genie_parse("iosxe", "show ip arp", "not really arp data") assert result == [] # genie loads about nine million modules... for whatever reason these two upset pyfakefs del sys.modules["ats.configuration"] del sys.modules["pyats.configuration"]
def test_genie_parse_success(): result = genie_parse("iosxe", "show ip arp", IOS_ARP) assert isinstance(result, dict) assert (result["interfaces"]["Vlan254"]["ipv4"]["neighbors"] ["172.31.254.1"]["ip"] == "172.31.254.1")
def test_genie_parse_failure(): result = genie_parse("iosxe", "show ip arp", "not really arp data") assert result == [] # w/out killing this module pyfakefs explodes. dont remember why/how i found that out... del sys.modules["pyats.configuration"]
def test_genie_parse_failure(): result = genie_parse("iosxe", "show ip arp", "not really arp data") assert result == [] del sys.modules["ats.configuration"] del sys.modules["pyats.configuration"]