Skip to content

Commit

Permalink
dont raise NotAnIdentifier function
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Feb 27, 2023
1 parent c254c8d commit 9204678
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
6 changes: 4 additions & 2 deletions snakefmt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class EmptyContextError(Exception):
pass


class NotAnIdentifierError(Exception):
pass
def NotAnIdentifierError(line_nb: str, identifier: str, keyword_line: str):
raise SyntaxError(
f"{line_nb}'{identifier}' in '{keyword_line}' is not a valid identifier"
)


def ColonError(line_nb: str, identifier: str, keyword_line: str):
Expand Down
5 changes: 1 addition & 4 deletions snakefmt/parser/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,7 @@ def validate_userule_syntax(self, snakefile: TokenIterator):
def validate_rulelike_syntax(self, snakefile: TokenIterator):
if not is_colon(self.token):
if self.token.type != tokenize.NAME:
raise NotAnIdentifierError(
f"{self.line_nb}'{self.token.string}' in '{self.keyword_line}' is "
f"not a valid identifier"
)
NotAnIdentifierError(self.line_nb, self.token.string, self.keyword_line)
self.keyword_line += f" {self.token.string}"
self.token = next(snakefile)
if not is_colon(self.token):
Expand Down
5 changes: 1 addition & 4 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
InvalidParameterSyntax,
InvalidPython,
NoParametersError,
NotAnIdentifierError,
TooManyParameters,
)
from snakefmt.formatter import TAB
Expand Down Expand Up @@ -63,9 +62,7 @@ def test_keyword_cannot_be_named(self):
setup_formatter('workdir a: "/to/dir"')

def test_invalid_name_for_keyword(self):
with pytest.raises(
NotAnIdentifierError, match=".*checkpoint.*valid identifier"
):
with pytest.raises(SyntaxError, match=".*checkpoint.*valid identifier"):
setup_formatter("checkpoint (): \n" '\tinput: "a"')

def test_explicitly_unrecognised_keyword(self):
Expand Down

0 comments on commit 9204678

Please sign in to comment.