From ea03dee63a546b9f383cce5f5f8d66a4b5e5fe5c Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Mon, 14 Jun 2021 14:50:33 +0100 Subject: [PATCH] Regression test for #417 (#421) * Add failing test * STY: Fix line spacing issues Co-authored-by: Poruri Sai Rahul --- envisage/tests/test_application.py | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/envisage/tests/test_application.py b/envisage/tests/test_application.py index 9ffa954cf..76e330982 100644 --- a/envisage/tests/test_application.py +++ b/envisage/tests/test_application.py @@ -111,6 +111,53 @@ class PluginC(Plugin): x = List(Int, [98, 99, 100], contributes_to="a.x") +# PluginD and PluginE each contribute to the other's extension points, but both +# expect to be started before contributions are made. +# xref: enthought/envisage#417 + + +class PluginD(Plugin): + """ Plugin that expects to be started before contributing to + extension points. """ + + id = "D" + x = ExtensionPoint(List, id="d.x") + + y = List(Int, contributes_to="e.x") + + started = Bool(False) + + def start(self): + self.started = True + + def _y_default(self): + if self.started: + return [4, 5, 6] + else: + return [] + + +class PluginE(Plugin): + """ Another plugin that expects to be started before contributing to + extension points. """ + + id = "E" + x = ExtensionPoint(List, id="e.x") + + y = List(Int, contributes_to="d.x") + + started = Bool(False) + + def start(self): + self.started = True + + def _y_default(self): + if self.started: + return [1, 2, 3] + else: + return [] + + class ApplicationTestCase(unittest.TestCase): """ Tests for applications and plugins. """ @@ -265,6 +312,27 @@ def test_extension_point(self): self.assertEqual(6, len(extensions)) self.assertEqual([1, 2, 3, 98, 99, 100], extensions) + def test_extension_point_resolution_occurs_after_plugin_start(self): + # Regression test for enthought/envisage#417 + + # Given + d = PluginD() + e = PluginE() + application = TestApplication(plugins=[d, e]) + + # When + application.start() + + # Then + self.assertEqual( + application.get_extensions("d.x"), + [1, 2, 3], + ) + self.assertEqual( + application.get_extensions("e.x"), + [4, 5, 6], + ) + def test_add_extension_point_listener(self): """ add extension point listener """