From 3cce49fe799bdf633aef2ab2bc5ece5dad3327ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 16 Feb 2022 10:24:07 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20plugin=20event=20identifie?= =?UTF-8?q?r=20generation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit plugin_Example_event was wrongly turned into PLUGIN__EXAMPLE_EVENT. Fixed regex to solve this. Closes #4417 --- src/octoprint/events.py | 2 +- tests/test_events.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/test_events.py diff --git a/src/octoprint/events.py b/src/octoprint/events.py index 1928fe7d7..537f220ed 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -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 diff --git a/tests/test_events.py b/tests/test_events.py new file mode 100644 index 000000000..5443836b7 --- /dev/null +++ b/tests/test_events.py @@ -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)