From f9b8bc20c256b7b00cd7242b0cc553b53ecd6f4a Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Wed, 26 Feb 2025 15:02:06 +0100 Subject: [PATCH 1/2] Fix single-line statement processing CURA-12386 The regex was not specific enough and would catch the rest of the line, now we force stopping as soon as we see a { or } --- plugins/CuraEngineBackend/StartSliceJob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index 875bbe153b..b276469d09 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -76,7 +76,7 @@ class GcodeStartEndFormatter: # will be used. Alternatively, if the expression is formatted as "{[expression], [extruder_nr]}", # then the expression will be evaluated with the extruder stack of the specified extruder_nr. - _instruction_regex = re.compile(r"{(?Pif|else|elif|endif)?\s*(?P.*?)\s*(?:,\s*(?P.*))?\s*}(?P\n?)") + _instruction_regex = re.compile(r"{(?Pif|else|elif|endif)?\s*(?P[^{}]*?)\s*(?:,\s*(?P[^{}]*))?\s*}(?P\n?)") def __init__(self, all_extruder_settings: Dict[str, Dict[str, Any]], default_extruder_nr: int = -1) -> None: super().__init__() From 2f2a93b9d00fe0434efdb279f60e05ba57e2d9ea Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Wed, 26 Feb 2025 15:02:22 +0100 Subject: [PATCH 2/2] Add unit test for single-line statement CURA-12386 --- conandata.yml | 4 ++++ tests/Machines/TestStartEndGCode.py | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/conandata.yml b/conandata.yml index 9ad6f889b5..5af5cdef64 100644 --- a/conandata.yml +++ b/conandata.yml @@ -265,6 +265,10 @@ pycharm_targets: module_name: Cura name: pytest in TestSettingVisibilityPresets.py script_name: tests/Settings/TestSettingVisibilityPresets.py + - jinja_path: .run_templates/pycharm_cura_test.run.xml.jinja + module_name: Cura + name: pytest in TestStartEndGCode.py + script_name: tests/Machines/TestStartEndGCode.py pip_requirements_core: any_os: diff --git a/tests/Machines/TestStartEndGCode.py b/tests/Machines/TestStartEndGCode.py index 13c14f5acc..611567bacd 100644 --- a/tests/Machines/TestStartEndGCode.py +++ b/tests/Machines/TestStartEndGCode.py @@ -7,12 +7,6 @@ from unittest.mock import MagicMock from plugins.CuraEngineBackend.StartSliceJob import GcodeStartEndFormatter -# def createMockedInstanceContainer(container_id): -# result = MagicMock() -# result.getId = MagicMock(return_value=container_id) -# result.getMetaDataEntry = MagicMock(side_effect=getMetadataEntrySideEffect) -# return result - class MockValueProvider: ## Creates a mock value provider. # @@ -259,7 +253,7 @@ Q2000 '' ), -( + ( 'Unexpected end character', None, '''{if material_temperature > 200, 0}} @@ -270,6 +264,20 @@ S2000 '''S2000 ''' ), + + ( + 'Multiple replaces on single line', + None, +'''BT={bed_temperature} IE={initial_extruder}''', +'''BT=50.0 IE=0''' + ), + + ( + 'Multiple extruder replaces on single line', + None, +'''MT0={material_temperature, 0} MT1={material_temperature, 1}''', +'''MT0=190.0 MT1=210.0''' + ), ] def pytest_generate_tests(metafunc):