88the full command is, and the output string data from the command.
99
1010"""
11+
1112from genie .libs .parser .utils .common import get_parser
1213from pyats .topology import Device
1314
@@ -32,6 +33,7 @@ class MockDevice: # pylint: disable=too-few-public-methods
3233 :type show_output_data: String
3334 :param show_output_data: The output data from the show command
3435 """
36+
3537 def __init__ (self , show_output_data : str ) -> None :
3638 self .show_output_data = show_output_data
3739
@@ -49,30 +51,32 @@ def execute(self, *args, **kwargs) -> str: # pylint: disable=unused-argument
4951 return self .show_output_data
5052
5153 # Set to hold supported nos
52- supported_nos = {'aireos' ,
53- 'apic' ,
54- 'asa' ,
55- 'bigip' ,
56- 'cheetah' ,
57- 'comware' ,
58- 'dnac' ,
59- 'gaia' ,
60- 'ios' ,
61- 'iosxe' ,
62- 'iosxr' ,
63- 'ironware' ,
64- 'junos' ,
65- 'linux' ,
66- 'nxos' ,
67- 'sros' ,
68- 'viptela' }
54+ supported_nos = {
55+ "aireos" ,
56+ "apic" ,
57+ "asa" ,
58+ "bigip" ,
59+ "cheetah" ,
60+ "comware" ,
61+ "dnac" ,
62+ "gaia" ,
63+ "ios" ,
64+ "iosxe" ,
65+ "iosxr" ,
66+ "ironware" ,
67+ "junos" ,
68+ "linux" ,
69+ "nxos" ,
70+ "sros" ,
71+ "viptela" ,
72+ }
6973
7074 def __init__ (self , nos ) -> None :
71- self .mock_pyats_device = Device (' Mock' )
72- self .mock_pyats_device .custom = {' abstraction' : {' order' : ['os' ]}}
75+ self .mock_pyats_device = Device (" Mock" )
76+ self .mock_pyats_device .custom = {" abstraction" : {" order" : ["os" ]}}
7377
7478 if nos not in self .supported_nos :
75- raise LookupError (f' nos needs to be one of theses options { self .supported_nos } ' )
79+ raise LookupError (f" nos needs to be one of theses options { self .supported_nos } " )
7680
7781 self .nos = nos
7882 self .mock_pyats_device .os = nos
@@ -95,12 +99,12 @@ def parse_string(self, show_command: str, show_output_data: str) -> dict:
9599 :raises TypeError: if the show_output_data is not a string
96100 """
97101 if not isinstance (show_output_data , str ):
98- raise TypeError (f' show_output_data must be a string received a { type (show_output_data )} ' )
102+ raise TypeError (f" show_output_data must be a string received a { type (show_output_data )} " )
99103
100104 self .show_output_data = show_output_data
101105
102106 if not isinstance (show_command , str ):
103- raise TypeError (f' show_command must be a string received a { type (show_command )} ' )
107+ raise TypeError (f" show_command must be a string received a { type (show_command )} " )
104108
105109 return self .__parse (show_command )
106110
@@ -119,9 +123,9 @@ def parse_file(self, show_command: str, file_name_and_path: str) -> dict:
119123 :raises FileNotFoundError: if the file you are trying to parse can't be found
120124 """
121125 if not isinstance (show_command , str ):
122- raise TypeError (f' show_command must be a string received a { type (show_command )} ' )
126+ raise TypeError (f" show_command must be a string received a { type (show_command )} " )
123127
124- with open (file_name_and_path , 'r' , encoding = ' utf-8' ) as file :
128+ with open (file_name_and_path , "r" , encoding = " utf-8" ) as file :
125129 self .show_output_data = file .read ()
126130
127131 return self .__parse (show_command )
@@ -139,9 +143,9 @@ def __remove_extra_spaces(string_item: str) -> str:
139143 :raises TypeError: if the string_item is not a string
140144 """
141145 if not isinstance (string_item , str ): # pragma: no cover
142- raise TypeError (f' string_item must be a string received a { type (string_item )} ' )
146+ raise TypeError (f" string_item must be a string received a { type (string_item )} " )
143147
144- string_item = ' ' .join (string_item .split ())
148+ string_item = " " .join (string_item .split ())
145149 return string_item
146150
147151 def __parse (self , show_command : str ) -> dict :
@@ -157,13 +161,14 @@ def __parse(self, show_command: str) -> dict:
157161 :raises ModuleNotFoundError: If it can not find a command to NOS mapping
158162 """
159163 if not isinstance (show_command , str ): # pragma: no cover
160- raise TypeError (f' show_command must be a string received a { type (show_command )} ' )
164+ raise TypeError (f" show_command must be a string received a { type (show_command )} " )
161165
162166 mock_device = self .MockDevice (self .show_output_data )
163167 try :
164168 found_parser = get_parser (self .__remove_extra_spaces (show_command ), self .mock_pyats_device )[0 ]
165169 return found_parser (device = mock_device ).parse ()
166170
167171 except Exception as error :
168- raise ModuleNotFoundError (f'Could not find module_name for command { show_command } '
169- f'for nos { self .nos } from genie: { error } ' ) from error
172+ raise ModuleNotFoundError (
173+ f"Could not find module_name for command { show_command } " f"for nos { self .nos } from genie: { error } "
174+ ) from error
0 commit comments