Пример #1
0
 def test_unloaded_extension(self):
     # check that unloaded extensions don't provide hooks
     # before we load our extension, the hook shouldn't be registered
     # invoking the hook shouldn't do anything now
     results = api.hook_invoke('test_hook')
     self.assertEquals(self.mock_hook.call_count, 0)
     self.assertEquals(results, [])
     # if we load, then unload our extension, the hook shouldn't be
     # registered
     self.load_extension()
     self.unload_extensions()
     results = api.hook_invoke('test_hook')
     self.assertEquals(self.mock_hook.call_count, 0)
     self.assertEquals(results, [])
Пример #2
0
 def test_unloaded_extension(self):
     # check that unloaded extensions don't provide hooks
     # before we load our extension, the hook shouldn't be registered
     # invoking the hook shouldn't do anything now
     results = api.hook_invoke('test_hook')
     self.assertEquals(self.mock_hook.call_count, 0)
     self.assertEquals(results, [])
     # if we load, then unload our extension, the hook shouldn't be
     # registered
     self.load_extension()
     self.unload_extensions()
     results = api.hook_invoke('test_hook')
     self.assertEquals(self.mock_hook.call_count, 0)
     self.assertEquals(results, [])
Пример #3
0
    def callback(self, tableview):
        """Callback to handle the context menu.

        This method can be passed into
        TableView.set_context_menu_callback
        """
        selected = [tableview.model[iter][0] for iter in tableview.get_selection()]

        if len(selected) == 1:
            menu = self._make_context_menu_single(selected[0])
        else:
            menu = self._make_context_menu_multiple(selected)
        # allow extensions to change the menu
        api.hook_invoke("item_context_menu", selected, menu)
        return menu
Пример #4
0
 def test_hook_invoke(self):
     # test calling hook functions
     self.load_extension()
     # setup our mock function to return a value
     self.mock_hook.return_value = 123
     # invoke the hook
     results1 = api.hook_invoke('test_hook', 1, 2, foo=3)
     results2 = api.hook_invoke('test_hook', 4, 5, bar=6)
     # check thath the function was called and the results are correct
     self.assertEquals(self.mock_hook.call_count, 2)
     self.assertEquals(self.mock_hook.call_args_list[0],
             ((1, 2), {'foo': 3}))
     self.assertEquals(self.mock_hook.call_args_list[1],
             ((4, 5), {'bar': 6}))
     self.assertEquals(results1, [123])
     self.assertEquals(results2, [123])
Пример #5
0
    def callback(self, tableview):
        """Callback to handle the context menu.

        This method can be passed into
        TableView.set_context_menu_callback
        """
        selected = [
            tableview.model[iter][0] for iter in tableview.get_selection()
        ]

        if len(selected) == 1:
            menu = self._make_context_menu_single(selected[0])
        else:
            menu = self._make_context_menu_multiple(selected)
        # allow extensions to change the menu
        api.hook_invoke('item_context_menu', selected, menu)
        return menu
Пример #6
0
 def test_hook_invoke(self):
     # test calling hook functions
     self.load_extension()
     # setup our mock function to return a value
     self.mock_hook.return_value = 123
     # invoke the hook
     results1 = api.hook_invoke('test_hook', 1, 2, foo=3)
     results2 = api.hook_invoke('test_hook', 4, 5, bar=6)
     # check thath the function was called and the results are correct
     self.assertEquals(self.mock_hook.call_count, 2)
     self.assertEquals(self.mock_hook.call_args_list[0], ((1, 2), {
         'foo': 3
     }))
     self.assertEquals(self.mock_hook.call_args_list[1], ((4, 5), {
         'bar': 6
     }))
     self.assertEquals(results1, [123])
     self.assertEquals(results2, [123])
Пример #7
0
 def test_hook_exception(self):
     # test hook functions raising exceptions
     self.load_extension()
     self.log_filter.reset_records()
     # setup our mock function to throw an error
     self.mock_hook.side_effect = ValueError("Bad Value")
     # invoke the hook
     results = api.hook_invoke('test_hook')
     # check that the error isn't included in the results and that we
     # logged the exception
     self.log_filter.check_record_count(1)
     self.log_filter.check_record_level(logging.ERROR)
     self.assertEquals(results, [])
Пример #8
0
 def test_hook_exception(self):
     # test hook functions raising exceptions
     self.load_extension()
     self.log_filter.reset_records()
     # setup our mock function to throw an error
     self.mock_hook.side_effect = ValueError("Bad Value")
     # invoke the hook
     results = api.hook_invoke('test_hook')
     # check that the error isn't included in the results and that we
     # logged the exception
     self.log_filter.check_record_count(1)
     self.log_filter.check_record_level(logging.ERROR)
     self.assertEquals(results, [])