From 64de883b3f40322c5048745af0a5eef5be570616 Mon Sep 17 00:00:00 2001 From: dw-0 Date: Fri, 21 Jun 2024 15:52:08 +0200 Subject: [PATCH] Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 7aa6586..47c353f 47c353f refactor: improve section regex dd904bc test: add more test cases git-subtree-dir: kiauh/core/submodules/simple_config_parser git-subtree-split: 47c353f4e91e6be9605394b174834e1f34c9cfdf --- src/simple_config_parser/simple_config_parser.py | 2 +- tests/features/line_parsing/data/case_parse_option.py | 5 +++++ tests/features/line_parsing/data/case_parse_section.py | 2 ++ .../line_type_detection/data/case_line_is_section.py | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/simple_config_parser/simple_config_parser.py b/src/simple_config_parser/simple_config_parser.py index a4b2128..3275bf3 100644 --- a/src/simple_config_parser/simple_config_parser.py +++ b/src/simple_config_parser/simple_config_parser.py @@ -85,7 +85,7 @@ class DuplicateOptionError(Exception): class SimpleConfigParser: """A customized config parser targeted at handling Klipper style config files""" - _SECTION_RE = re.compile(r"\s*\[(\w+\s?[\w\-]+)]\s*([#;].*)?$") + _SECTION_RE = re.compile(r"\s*\[(\w+\s?.+)]\s*([#;].*)?$") _OPTION_RE = re.compile(r"^\s*(\w+)\s*[:=]\s*([^=:].*)\s*([#;].*)?$") _MLOPTION_RE = re.compile(r"^\s*(\w+)\s*[:=]\s*([#;].*)?$") _COMMENT_RE = re.compile(r"^\s*([#;].*)?$") diff --git a/tests/features/line_parsing/data/case_parse_option.py b/tests/features/line_parsing/data/case_parse_option.py index e4901f5..fbe9001 100644 --- a/tests/features/line_parsing/data/case_parse_option.py +++ b/tests/features/line_parsing/data/case_parse_option.py @@ -8,6 +8,11 @@ testcases = [ ("option: value\n", "option", "value"), ("option: value # inline comment", "option", "value"), ("option: value # inline comment\n", "option", "value"), + ( + "description: Helper: park toolhead used in PAUSE and CANCEL_PRINT", + "description", + "Helper: park toolhead used in PAUSE and CANCEL_PRINT", + ), ("description: homing!", "description", "homing!"), ("description: inline macro :-)", "description", "inline macro :-)"), ("path: %GCODES_DIR%", "path", "%GCODES_DIR%"), diff --git a/tests/features/line_parsing/data/case_parse_section.py b/tests/features/line_parsing/data/case_parse_section.py index ea1536d..bab0f69 100644 --- a/tests/features/line_parsing/data/case_parse_section.py +++ b/tests/features/line_parsing/data/case_parse_section.py @@ -3,4 +3,6 @@ testcases = [ ("[test_section two]", "test_section two"), ("[section1] # inline comment", "section1"), ("[section2] ; second comment", "section2"), + ("[include moonraker-obico-update.cfg]", "include moonraker-obico-update.cfg"), + ("[include moonraker_obico_macros.cfg]", "include moonraker_obico_macros.cfg"), ] diff --git a/tests/features/line_type_detection/data/case_line_is_section.py b/tests/features/line_type_detection/data/case_line_is_section.py index d2ef185..42b93d0 100644 --- a/tests/features/line_type_detection/data/case_line_is_section.py +++ b/tests/features/line_type_detection/data/case_line_is_section.py @@ -1,6 +1,11 @@ testcases = [ ("[example_section]", True), + ("[gcode_macro CANCEL_PRINT]", True), + ("[gcode_macro SET_PAUSE_NEXT_LAYER]", True), + ("[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]", True), ("[update_manager moonraker-obico]", True), + ("[include moonraker_obico_macros.cfg]", True), + ("[include moonraker-obico-update.cfg]", True), ("[example_section two]", True), ("not_a_valid_section", False), ("section: invalid", False),