Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 2698f60..7aa6586

7aa6586 fix: sections can have hyphens in their second word
44cedf5 fix(tests): fix whitespaces in expected output

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 7aa658654eeb08fd53831effbfba4503a61e0eff
This commit is contained in:
dw-0
2024-06-19 21:14:50 +02:00
parent 08640e5b17
commit a17171b88e
3 changed files with 3 additions and 2 deletions

View File

@@ -85,7 +85,7 @@ class DuplicateOptionError(Exception):
class SimpleConfigParser: class SimpleConfigParser:
"""A customized config parser targeted at handling Klipper style config files""" """A customized config parser targeted at handling Klipper style config files"""
_SECTION_RE = re.compile(r"\s*\[(\w+ ?\w+)]\s*([#;].*)?$") _SECTION_RE = re.compile(r"\s*\[(\w+\s?[\w\-]+)]\s*([#;].*)?$")
_OPTION_RE = re.compile(r"^\s*(\w+)\s*[:=]\s*([^=:].*)\s*([#;].*)?$") _OPTION_RE = re.compile(r"^\s*(\w+)\s*[:=]\s*([^=:].*)\s*([#;].*)?$")
_MLOPTION_RE = re.compile(r"^\s*(\w+)\s*[:=]\s*([#;].*)?$") _MLOPTION_RE = re.compile(r"^\s*(\w+)\s*[:=]\s*([#;].*)?$")
_COMMENT_RE = re.compile(r"^\s*([#;].*)?$") _COMMENT_RE = re.compile(r"^\s*([#;].*)?$")

View File

@@ -1,5 +1,6 @@
testcases = [ testcases = [
("[example_section]", True), ("[example_section]", True),
("[update_manager moonraker-obico]", True),
("[example_section two]", True), ("[example_section two]", True),
("not_a_valid_section", False), ("not_a_valid_section", False),
("section: invalid", False), ("section: invalid", False),

View File

@@ -108,7 +108,7 @@ class TestPublicAPI:
assert parser._config[section]["body"][0]["option"] == option assert parser._config[section]["body"][0]["option"] == option
values = ["value1", "value2", "value3"] values = ["value1", "value2", "value3"]
raw_values = [" value1\n", " value2\n", " value3\n"] raw_values = [" value1\n", " value2\n", " value3\n"]
assert parser._config[section]["body"][0]["value"] == values assert parser._config[section]["body"][0]["value"] == values
assert parser._config[section]["body"][0]["_raw"] == f"{option}:\n" assert parser._config[section]["body"][0]["_raw"] == f"{option}:\n"
assert parser._config[section]["body"][0]["_raw_value"] == raw_values assert parser._config[section]["body"][0]["_raw_value"] == raw_values