increase test coverage for textfsm module.

This commit is contained in:
Gareth J. Greenaway 2023-10-24 12:07:38 -07:00 committed by Pedro Algarvio
parent 8c86b5ec70
commit 7ad348dd48
2 changed files with 14 additions and 7 deletions

View file

@ -19,7 +19,7 @@ inside the renderer (Jinja, Mako, Genshi, etc.).
import logging
import os
from salt.utils.files import fopen
import salt.utils.files
try:
import textfsm
@ -188,11 +188,14 @@ def extract(template_path, raw_text=None, raw_text_file=None, saltenv="base"):
# Disabling pylint W8470 to nto complain about fopen.
# Unfortunately textFSM needs the file handle rather than the content...
# pylint: disable=W8470
tpl_file_handle = fopen(tpl_cached_path, "r")
# pylint: disable=W8470
log.debug(tpl_file_handle.read())
tpl_file_handle.seek(0) # move the object position back at the top of the file
fsm_handler = textfsm.TextFSM(tpl_file_handle)
with salt.utils.files.fopen(tpl_cached_path, "r") as tpl_file_handle:
# pylint: disable=W8470
tpl_file_data = tpl_file_handle.read()
log.debug(tpl_file_data)
tpl_file_handle.seek(
0
) # move the object position back at the top of the file
fsm_handler = textfsm.TextFSM(tpl_file_handle)
except textfsm.TextFSMTemplateError as tfte:
log.error("Unable to parse the TextFSM template", exc_info=True)
ret["comment"] = (

View file

@ -71,7 +71,7 @@ class MockFH:
self.write = Mock(side_effect=self._write)
self.writelines = Mock(side_effect=self._writelines)
self.close = Mock()
self.seek = Mock()
self.seek = Mock(side_effect=self._seek)
self.__loc = 0
self.__read_data_ok = False
@ -219,6 +219,10 @@ class MockFH:
def __exit__(self, exc_type, exc_val, exc_tb): # pylint: disable=unused-argument
pass
def _seek(self, pos=0):
self.__loc = pos
self.read_data_iter = self._iterate_read_data(self.read_data)
class MockCall:
def __init__(self, *args, **kwargs):