ConfigOption: add _get_user_input method to allow to mock it in tests

This commit is contained in:
Benjamin Renard 2023-01-09 13:32:25 +01:00
parent 014a0802f8
commit 6a7368deb5

View file

@ -222,6 +222,14 @@ class BaseOption: # pylint: disable=too-many-instance-attributes
lines.append('')
return '\n'.join(lines)
@staticmethod
def _get_user_input(prompt):
"""
Get user console input
Note: do not use directly input() to allow to mock it in tests
"""
return input(prompt)
def _ask_value(self, prompt=None, **kwargs):
""" Ask to user to enter value of this option and return it """
if self.comment:
@ -236,7 +244,7 @@ class BaseOption: # pylint: disable=too-many-instance-attributes
)
else:
prompt += f'[{self.to_config(default_value)}] '
value = input(prompt)
value = self._get_user_input(prompt)
return default_value if value == '' else value
def ask_value(self, set_it=True):