コード例 #1
0
  def testParseIndex(self):
    """Test reading and index and parsing to index and compiled tables."""
    file_path = os.path.join('testdata', 'parseindex_index')
    indx = clitable.IndexTable(file_path=file_path)
    # Compare number of entries found in the index table.
    self.assertEqual(indx.index.size, 3)
    self.assertEqual(indx.index[2]['Template'], 'clitable_templateC')
    self.assertEqual(indx.index[3]['Template'], 'clitable_templateD')
    self.assertEqual(indx.index[1]['Command'], 'sh[[ow]] ve[[rsion]]')
    self.assertEqual(indx.index[1]['Hostname'], '.*')

    self.assertEqual(indx.compiled.size, 3)
    for col in ('Command', 'Vendor', 'Template', 'Hostname'):
      self.assertTrue(isinstance(indx.compiled[1][col],
                                 copyable_regex_object.CopyableRegexObject))

    self.assertTrue(indx.compiled[1]['Hostname'].match('random string'))

    def _PreParse(key, value):
      if key == 'Template':
        return value.upper()
      return value

    def _PreCompile(key, value):
      if key in ('Template', 'Command'):
        return None
      return value

    self.assertEqual(indx.compiled.size, 3)
    indx = clitable.IndexTable(_PreParse, _PreCompile, file_path)
    self.assertEqual(indx.index[2]['Template'], 'CLITABLE_TEMPLATEC')
    self.assertEqual(indx.index[1]['Command'], 'sh[[ow]] ve[[rsion]]')
    self.assertTrue(isinstance(indx.compiled[1]['Hostname'],
                               copyable_regex_object.CopyableRegexObject))
    self.assertFalse(indx.compiled[1]['Command'])
コード例 #2
0
 def testGetRowMatch(self):
   """Tests retreiving rows from table."""
   file_path = os.path.join('testdata', 'parseindex_index')
   indx = clitable.IndexTable(file_path=file_path)
   self.assertEqual(1, indx.GetRowMatch({'Hostname': 'abc'}))
   self.assertEqual(2, indx.GetRowMatch({'Hostname': 'abc',
                                         'Vendor': 'VendorB'}))
コード例 #3
0
ファイル: clitable_test.py プロジェクト: zhaoxuan2020/textfsm
 def testCopy(self):
     """Tests copy of IndexTable object."""
     file_path = os.path.join('testdata', 'parseindex_index')
     indx = clitable.IndexTable(file_path=file_path)
     copy.deepcopy(indx)