Skip to content

Commit

Permalink
Fix with pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubAndrysek committed Jan 15, 2025
1 parent 7b25eda commit 1545357
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
8 changes: 4 additions & 4 deletions mkdoxy/doxyrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def str2dox_dict(self, dox_str: str) -> dict:
@return: (dict) Dictionary.
"""
dox_dict = {}
dox_str = re.sub(r'\\\s*\n\s*', '', dox_str)
pattern = r'^\s*([^=\s]+)\s*(=|\+=)\s*(.*)$'
dox_str = re.sub(r"\\\s*\n\s*", "", dox_str)
pattern = r"^\s*([^=\s]+)\s*(=|\+=)\s*(.*)$"

try:
for line in dox_str.split("\n"):
Expand All @@ -173,14 +173,14 @@ def str2dox_dict(self, dox_str: str) -> dict:
)
key, operator, value = match.groups()
value = value.strip()
if operator == '=':
if operator == "=":
if value == "YES":
dox_dict[key] = True
elif value == "NO":
dox_dict[key] = False
else:
dox_dict[key] = value
if operator == '+=':
if operator == "+=":
dox_dict[key] = f"{dox_dict[key]} {value}"
except ValueError as e:
raise DoxygenCustomConfigNotValid(
Expand Down
73 changes: 36 additions & 37 deletions tests/test_doxyrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def test_str2dox_dict_expanded_config():
"# This is a comment \n"
"PROJECT_LOGO =\n"
'ABBREVIATE_BRIEF = "The $name class" \\ \n'
' is \n'
'FILE_PATTERNS = *.c \n'
'FILE_PATTERNS += *.cc\n'
'PREDEFINED = BUILD_DATE DOXYGEN=1\n'
" is \n"
"FILE_PATTERNS = *.c \n"
"FILE_PATTERNS += *.cc\n"
"PREDEFINED = BUILD_DATE DOXYGEN=1\n"
)

doxygen_run = DoxygenRun(
Expand All @@ -114,11 +114,12 @@ def test_str2dox_dict_expanded_config():
"PROJECT_LOGO": "",
"ABBREVIATE_BRIEF": '"The $name class" is',
"FILE_PATTERNS": "*.c *.cc",
"PREDEFINED": "BUILD_DATE DOXYGEN=1"
"PREDEFINED": "BUILD_DATE DOXYGEN=1",
}

assert result == expected_result


def test_str2dox_dict_expanded_config_errors():
doxygen_run = DoxygenRun(
doxygenBinPath="doxygen",
Expand All @@ -127,59 +128,57 @@ def test_str2dox_dict_expanded_config_errors():
doxyCfgNew={},
)

dox_str = (
"ONLY_KEY\n"
dox_str = "ONLY_KEY\n"
error_message = str(
"Invalid line: 'ONLY_KEY'"
"In custom Doxygen config file: None\n"
"Make sure the file is in standard Doxygen format."
"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/."
)
error_message = str(f"Invalid line: 'ONLY_KEY'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

dox_str = (
"= ONLY_VALUE\n"
dox_str = "= ONLY_VALUE\n"
error_message = str(
"Invalid line: '= ONLY_VALUE'"
"In custom Doxygen config file: None\n"
"Make sure the file is in standard Doxygen format."
"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/."
)
error_message = str(f"Invalid line: '= ONLY_VALUE'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

dox_str = (
"KEY WITH SPACES = VALUE\n"
dox_str = "KEY WITH SPACES = VALUE\n"
error_message = str(
"Invalid line: 'KEY WITH SPACES = VALUE'"
"In custom Doxygen config file: None\n"
"Make sure the file is in standard Doxygen format."
"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/."
)
error_message = str(f"Invalid line: 'KEY WITH SPACES = VALUE'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

dox_str = (
"BAD_OPERATOR := VALUE\n"
dox_str = "BAD_OPERATOR := VALUE\n"
error_message = str(
"Invalid line: 'BAD_OPERATOR := VALUE'"
"In custom Doxygen config file: None\n"
"Make sure the file is in standard Doxygen format."
"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/."
)
error_message = str(f"Invalid line: 'BAD_OPERATOR := VALUE'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

dox_str = (
"BAD_MULTILINE = BAD\n"
" VALUE\n"
dox_str = "BAD_MULTILINE = BAD\n" " VALUE\n"
error_message = str(
"Invalid line: ' VALUE'"
"In custom Doxygen config file: None\n"
"Make sure the file is in standard Doxygen format."
"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/."
)
error_message = str(f"Invalid line: ' VALUE'"
f"In custom Doxygen config file: None\n"
f"Make sure the file is in standard Doxygen format."
f"Look at https://mkdoxy.kubaandrysek.cz/usage/advanced/.")

with pytest.raises(DoxygenCustomConfigNotValid, match=error_message):
doxygen_run.str2dox_dict(dox_str)

0 comments on commit 1545357

Please sign in to comment.