🐛 Fix plugin event identifier generation

plugin_Example_event was wrongly turned into
PLUGIN__EXAMPLE_EVENT. Fixed regex to solve this.

Closes #4417
This commit is contained in:
Gina Häußge committed 2022-02-16 10:24:07 +01:00
1 parent f215523f43
commit 3cce49fe79
2 files changed
+23 -1

No files matched your search

+1 -1
View File
@@ -139,7 +139,7 @@ class Events:
return name, event
# based on https://stackoverflow.com/a/1176023
_first_cap_re = re.compile("(.)([A-Z][a-z]+)")
_first_cap_re = re.compile("([^_])([A-Z][a-z]+)")
_all_cap_re = re.compile("([a-z0-9])([A-Z])")
@classmethod
+22
View File
@@ -0,0 +1,22 @@
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
__copyright__ = "Copyright (C) 2022 The OctoPrint Project - Released under terms of the AGPLv3 License"
import unittest
import ddt
import octoprint.events
@ddt.ddt
class TestEvents(unittest.TestCase):
@ddt.data(
("plugin_example_event", "PLUGIN_EXAMPLE_EVENT"),
("plugin_Example_event", "PLUGIN_EXAMPLE_EVENT"),
("plugin_ExAmple_Event", "PLUGIN_EX_AMPLE_EVENT"),
("plugin_exAmple_EvEnt", "PLUGIN_EX_AMPLE_EV_ENT"),
)
@ddt.unpack
def test_to_identifier(self, value, expected):
actual = octoprint.events.Events._to_identifier(value)
self.assertEqual(actual, expected)