Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix index slice in ExtensionPointChangedEvent when plugin changes #357

Merged
merged 2 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion envisage/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _anytrait_changed(self, trait_name, old, new):
else:
added = new
removed = old
index = slice(0, max(len(old), len(new)))
index = slice(0, len(old))

# Let the extension registry know about the change.
self._fire_extension_point_changed(
Expand Down
16 changes: 15 additions & 1 deletion envisage/tests/test_extension_point_changed.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def test_assign_non_empty_list(self):
# won't fire a changed event.
self.assertEqual([1, 2, 3, 98, 99, 100], a.x)

# Keep the old values for later slicing check
source_values = list(a.x)

# Assign a non-empty list to one of the plugin's contributions.
b.x = [2, 4, 6, 8]

Expand All @@ -259,8 +262,19 @@ def test_assign_non_empty_list(self):
self.assertEqual("x_items", listener.trait_name)
self.assertEqual([2, 4, 6, 8], listener.new.added)
self.assertEqual([1, 2, 3], listener.new.removed)

# The removed entry should match what the old values say
self.assertEqual(
listener.new.removed, source_values[listener.new.index]
)

# If we use the index and apply the changes to the old list, we should
# recover the new list
source_values[listener.new.index] = listener.new.added
self.assertEqual(source_values, application.get_extensions("a.x"))

self.assertEqual(0, listener.new.index.start)
self.assertEqual(4, listener.new.index.stop)
self.assertEqual(3, listener.new.index.stop)

def test_add_plugin(self):
""" add plugin """
Expand Down