File: test_ids.py

package info (click to toggle)
python-envisage 7.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,880 kB
  • sloc: python: 8,696; makefile: 76; sh: 5
file content (61 lines) | stat: -rw-r--r-- 2,266 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# (C) Copyright 2007-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

import unittest

import envisage.ids
from envisage.api import CorePlugin
from envisage.plugins.python_shell.python_shell_plugin import PythonShellPlugin
from envisage.ui.tasks.api import TasksPlugin


class TestIds(unittest.TestCase):
    def test_id_strings(self):
        extension_point_ids = [
            # Extension point IDs
            "PREFERENCES",
            "SERVICE_OFFERS",
            "BINDINGS",
            "COMMANDS",
            "PREFERENCES_CATEGORIES",
            "PREFERENCES_PANES",
            "TASKS",
            "TASK_EXTENSIONS",
        ]

        for extension_point_id in extension_point_ids:
            id_value = getattr(envisage.ids, extension_point_id)
            self.assertIsInstance(id_value, str)

    def test_id_strings_against_plugin_constants(self):
        # Check extension point IDs against ground truth on plugins
        self.check_id_against_plugin("PREFERENCES", CorePlugin)
        self.check_id_against_plugin("SERVICE_OFFERS", CorePlugin)
        self.check_id_against_plugin("BINDINGS", PythonShellPlugin)
        self.check_id_against_plugin("COMMANDS", PythonShellPlugin)
        self.check_id_against_plugin("PREFERENCES_CATEGORIES", TasksPlugin)
        self.check_id_against_plugin("PREFERENCES_PANES", TasksPlugin)
        self.check_id_against_plugin("TASKS", TasksPlugin)
        self.check_id_against_plugin("TASK_EXTENSIONS", TasksPlugin)

    def check_id_against_plugin(self, id_string, plugin_klass):
        """
        Check that the value of an id string matches that of a class variable.

        Parameters
        ----------
        id_string : str
            Identifier for the id.
        plugin_klass : type
            The Plugin subclass to check.
        """
        self.assertEqual(
            getattr(envisage.ids, id_string), getattr(plugin_klass, id_string)
        )