From 6a7368deb54aa0a5ee7e412aac93b904a8e61b8c Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 9 Jan 2023 13:32:25 +0100 Subject: [PATCH] ConfigOption: add _get_user_input method to allow to mock it in tests --- mylib/config.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mylib/config.py b/mylib/config.py index ec50ba1..387ad96 100644 --- a/mylib/config.py +++ b/mylib/config.py @@ -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):