Debian Codegraph @

envisage/tests/test_ids.py

raw
1 # (C) Copyright 2007-2025 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10
11 import unittest
12
13 import envisage.ids
14 from envisage.api import CorePlugin
15 from envisage.plugins.python_shell.python_shell_plugin import PythonShellPlugin
16 from envisage.ui.tasks.api import TasksPlugin
17
18
19 class TestIds(unittest.TestCase):
20 def test_id_strings(self):
21 extension_point_ids = [
22 # Extension point IDs
23 "PREFERENCES",
24 "SERVICE_OFFERS",
25 "BINDINGS",
26 "COMMANDS",
27 "PREFERENCES_CATEGORIES",
28 "PREFERENCES_PANES",
29 "TASKS",
30 "TASK_EXTENSIONS",
31 ]
32
33 for extension_point_id in extension_point_ids:
34 id_value = getattr(envisage.ids, extension_point_id)
35 self.assertIsInstance(id_value, str)
36
37 def test_id_strings_against_plugin_constants(self):
38 # Check extension point IDs against ground truth on plugins
39 self.check_id_against_plugin("PREFERENCES", CorePlugin)
40 self.check_id_against_plugin("SERVICE_OFFERS", CorePlugin)
41 self.check_id_against_plugin("BINDINGS", PythonShellPlugin)
42 self.check_id_against_plugin("COMMANDS", PythonShellPlugin)
43 self.check_id_against_plugin("PREFERENCES_CATEGORIES", TasksPlugin)
44 self.check_id_against_plugin("PREFERENCES_PANES", TasksPlugin)
45 self.check_id_against_plugin("TASKS", TasksPlugin)
46 self.check_id_against_plugin("TASK_EXTENSIONS", TasksPlugin)
47
48 def check_id_against_plugin(self, id_string, plugin_klass):
49 """
50 Check that the value of an id string matches that of a class variable.
51
52 Parameters
53 ----------
54 id_string : str
55 Identifier for the id.
56 plugin_klass : type
57 The Plugin subclass to check.
58 """
59 self.assertEqual(
60 getattr(envisage.ids, id_string), getattr(plugin_klass, id_string)
61 )