Merge branch 'pr/3916' into maintenance

This commit is contained in:
Gina Häußge committed 2021-02-23 11:32:55 +01:00
commit 97b6f25cfd
2 files changed
+23 -2

No files matched your search

+6 -2
View File
@@ -182,7 +182,7 @@ Groups will be as follows:
* ``value``: reported position value
"""
regex_firmware_splitter = re.compile(r"\s*([A-Z0-9_]+):\s*")
regex_firmware_splitter = re.compile(r"(^|\s+)([A-Z][A-Z0-9_]*):")
"""Regex to use for splitting M115 responses."""
regex_resend_linenumber = re.compile(r"(N|N:)?(?P<n>%s)" % regex_int_pattern)
@@ -6091,6 +6091,10 @@ def parse_firmware_line(line):
The result will be a dictionary mapping from the contained keys to the contained
values.
Valid keys must only contain A-Z, 0-9 and _ and must start with a letter. See the
unit tests for valid and invalid examples. There sadly is no existing specification
of the key format, but this is the format extracted from real life logs.
Arguments:
line (str): the line to parse
@@ -6108,7 +6112,7 @@ def parse_firmware_line(line):
split_line = regex_firmware_splitter.split(line.strip())[
1:
] # first entry is empty start of trimmed string
for key, value in chunks(split_line, 2):
for _, key, value in chunks(split_line, 3):
result[key] = value.strip()
return result
+17
View File
@@ -376,6 +376,23 @@ class TestCommHelpers(unittest.TestCase):
"UUID": "00000000-0000-0000-0000-000000000000",
},
),
# Test firmware name with time created
(
"FIRMWARE_NAME:Marlin 2.0.7.2 (Nov 27 2020 14:30:11) SOURCE_CODE_URL:https://github.com/MarlinFirmware/Marlin PROTOCOL_VERSION:1.0 MACHINE_TYPE:Ender 5 Pro EXTRUDER_COUNT:1 UUID:cede2a2f-41a2-4748-9b12-c55c62f367ff",
{
"FIRMWARE_NAME": "Marlin 2.0.7.2 (Nov 27 2020 14:30:11)",
"SOURCE_CODE_URL": "https://github.com/MarlinFirmware/Marlin",
"PROTOCOL_VERSION": "1.0",
"MACHINE_TYPE": "Ender 5 Pro",
"EXTRUDER_COUNT": "1",
"UUID": "cede2a2f-41a2-4748-9b12-c55c62f367ff",
},
),
# Test that keys beginning with _ or number are ignored
(
"KEY1:VALUE1 _KEY2:INVALID 123:INVALID 1KEY:INVALID KEY2:VALUE2",
{"KEY1": "VALUE1 _KEY2:INVALID 123:INVALID 1KEY:INVALID", "KEY2": "VALUE2"},
),
)
@unpack
def test_parse_firmware_line(self, line, expected):