From 820d1ee00975d2e7859e4b2aded88dbf56a3b347 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 27 Feb 2021 16:12:34 +0100 Subject: Added configuration file section/key names check --- .gitignore | 1 + minishell_test/config.py | 14 ++++++++++---- minishell_test/test/captured.py | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 3f00532..85ad925 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ dist/ *.egg-info build/ .tox/ +bash3.2.57 diff --git a/minishell_test/config.py b/minishell_test/config.py index 5a45e8b..1368740 100644 --- a/minishell_test/config.py +++ b/minishell_test/config.py @@ -6,7 +6,7 @@ # By: cacharle +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/02/26 09:40:36 by cacharle #+# #+# # -# Updated: 2021/02/27 15:13:19 by cacharle ### ########.fr # +# Updated: 2021/02/27 16:11:46 by cacharle ### ########.fr # # # # ############################################################################ # @@ -49,12 +49,17 @@ CONFIG_FILENAME = Path('minishell_test.cfg') config = ConfigParser() config.read(DATA_DIR / 'default.cfg') - -# TODO check user_config for unkown stuff user_config = ConfigParser() user_config.read(MINISHELL_DIR / CONFIG_FILENAME) -config.read_dict({**config, **user_config}) +for section in user_config: + if section not in config: + raise RuntimeError(f"Unknown section name: {section}") + for key in user_config[section]: + if key not in config[section]: + raise RuntimeError(f"Unknown key name: {key}") + +config.read_dict({**config, **user_config}) BONUS = config.getboolean('minishell_test', 'bonus') EXEC_NAME = config.get('minishell_test', 'exec_name') @@ -68,6 +73,7 @@ CHECK_ERROR_MESSAGES = config.getboolean('minishell_test', 'check_error_mess SHELL_AVAILABLE_COMMANDS = config.getmultiline('shell', 'available_commands') SHELL_PATH_VARIABLE = config.get('shell', 'path_variable') + SHELL_REFERENCE_PATH = config.getpath('shell:reference', 'path') SHELL_REFERENCE_ARGS = config.getargs('shell:reference', 'args') diff --git a/minishell_test/test/captured.py b/minishell_test/test/captured.py index e1ef29a..d2fda8b 100644 --- a/minishell_test/test/captured.py +++ b/minishell_test/test/captured.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:16:25 by charles #+# #+# # -# Updated: 2021/02/27 15:25:58 by cacharle ### ########.fr # +# Updated: 2021/02/27 15:48:30 by cacharle ### ########.fr # # # # ############################################################################ # @@ -32,7 +32,7 @@ class Captured: """ lines = output.split('\n') - for i, _ in enumerate(lines): + for i, line in enumerate(lines): lines[i] = line = re.sub(f"line [01]: ", "", lines[i], 1) if line.startswith(config.SHELL_REFERENCE_PREFIX): lines[i] = config.MINISHELL_PREFIX + line[len(config.SHELL_REFERENCE_PREFIX):] -- cgit