[pitivi] shortcuts: Make sure a group can be registered only once



commit a6c50c6cf3f815c57abc1c5f423ebc746667db10
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Sep 15 22:06:44 2016 +0200

    shortcuts: Make sure a group can be registered only once
    
    Reviewed-by: Jakub Brindza <jakub brindza gmail com>
    Differential Revision: https://phabricator.freedesktop.org/D1309

 pitivi/shortcuts.py     |    6 ++----
 tests/test_shortcuts.py |    6 +++---
 2 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/pitivi/shortcuts.py b/pitivi/shortcuts.py
index 31bad52..0794ebd 100644
--- a/pitivi/shortcuts.py
+++ b/pitivi/shortcuts.py
@@ -36,7 +36,6 @@ class ShortcutsManager(GObject.Object):
     def __init__(self, app):
         GObject.Object.__init__(self)
         self.app = app
-        self.groups = []
         self.group_titles = {}
         self.group_actions = {}
         self.default_accelerators = {}
@@ -124,8 +123,7 @@ class ShortcutsManager(GObject.Object):
             action_prefix (str): The group id.
             title (str): The title of the group.
         """
-        if action_prefix not in self.groups:
-            self.groups.append(action_prefix)
+        assert action_prefix not in self.group_titles
         self.group_titles[action_prefix] = title
 
     def reset_accels(self, action=None):
@@ -164,7 +162,7 @@ class ShortcutsWindow(Gtk.ShortcutsWindow):
         """Gathers the accelerators and populates the window."""
         section = Gtk.ShortcutsSection()
         section.show()
-        for group_id in self.app.shortcuts.groups:
+        for group_id in self.app.shortcuts.group_titles:
             group = Gtk.ShortcutsGroup(title=self.app.shortcuts.group_titles[group_id])
             group.show()
             for action, title in self.app.shortcuts.group_actions[group_id]:
diff --git a/tests/test_shortcuts.py b/tests/test_shortcuts.py
index f520f2b..9d12062 100644
--- a/tests/test_shortcuts.py
+++ b/tests/test_shortcuts.py
@@ -35,9 +35,9 @@ class TestShortcutsManager(TestCase):
 
         # Test register_group method
         manager.register_group("alpha_group", "The very first test group")
-        self.assertListEqual(manager.groups, ["alpha_group"])
+        with self.assertRaises(AssertionError):
+            manager.register_group("alpha_group", "")
         manager.register_group("beta_group", "Another test group")
-        self.assertListEqual(manager.groups, ["alpha_group", "beta_group"])
 
         # Test grouping using the stripping away group name from action name
         manager.add("alpha_group.first", ["<Primary>A"], "First action")
@@ -118,7 +118,7 @@ class TestShortcutsManager(TestCase):
         app = mock.MagicMock()
         with mock.patch("pitivi.shortcuts.xdg_config_home") as xdg_config_home,\
                 tempfile.TemporaryDirectory() as temp_dir,\
-                    mock.patch("os.remove") as os_remove_mock:
+                mock.patch("os.remove") as os_remove_mock:
             xdg_config_home.return_value = temp_dir
             manager = ShortcutsManager(app)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]