From 3c034393dd46e5b36fd6054430463316fbc12ad6 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Wed, 11 Jan 2023 15:20:15 +0900 Subject: [PATCH 1/3] feat(parser): Check if substitutions are provided or not --- varst/utils/parser.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/varst/utils/parser.py b/varst/utils/parser.py index 6245a4d..265e27d 100644 --- a/varst/utils/parser.py +++ b/varst/utils/parser.py @@ -59,6 +59,10 @@ def parse(self, argv: Optional[Sequence[str]]) -> None: self.input_file = self.output_file = arg_dict['input'] if arg_dict['output'] is not None: self.output_file = arg_dict['output'] + + substitutions = arg_dict['substitutions'] + if not substitutions: + raise ValueError("Substitutions are not passed") self.sub_pairs = _parse_kv(arg_dict['substitutions']) From 781911ff08d83e5c97cecf5802629efdac8af384 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Wed, 11 Jan 2023 15:44:13 +0900 Subject: [PATCH 2/3] test(parser): Add test case to check if substitutions are provided --- tests/utils/test_parser.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/utils/test_parser.py b/tests/utils/test_parser.py index 604ac9a..5520114 100644 --- a/tests/utils/test_parser.py +++ b/tests/utils/test_parser.py @@ -32,8 +32,14 @@ def test_parse_without_file_path(parser: Parser): assert parser.output_file == './README.rst' +def test_parse_without_substitutions(parser: Parser): + with pytest.raises(ValueError): + parser.parse(['-i=./CHANGELOG.rst', '-o=./CHANGELOG.rst']) + + def test_parse_with_file_path(parser: Parser): parser.parse([ + 'varst=variable to reStructuredText', '-i=./CHANGELOG.rst', '-o=./CHANGELOG.rst', ]) From ba3ec12fdb4cfd9c3b17942157fb54d3fcb834c9 Mon Sep 17 00:00:00 2001 From: Jeonghun-Ban Date: Thu, 12 Jan 2023 16:21:01 +0900 Subject: [PATCH 3/3] docs(parser): Add exception information to parse method --- varst/utils/parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/varst/utils/parser.py b/varst/utils/parser.py index 265e27d..e990448 100644 --- a/varst/utils/parser.py +++ b/varst/utils/parser.py @@ -51,6 +51,8 @@ def parse(self, argv: Optional[Sequence[str]]) -> None: Args: argv: Arguments vector + Raises: + ValueError: If the substitutions are not passed """ args = self._parser.parse_args(argv)