Skip to content

Commit

Permalink
Merge pull request #55 from junghoon-vans/feature/add-error-handling-…
Browse files Browse the repository at this point in the history
…if-substitutions-are-not-provided

feat: Add error handling if substitutions are not provided
  • Loading branch information
junghoon-vans authored Jan 12, 2023
2 parents ff66c39 + ba3ec12 commit 880ac46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/utils/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])

Expand Down
6 changes: 6 additions & 0 deletions varst/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -59,6 +61,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'])


Expand Down

0 comments on commit 880ac46

Please sign in to comment.