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)