@@ -53,6 +53,17 @@
Loading
53 53
        self.name = name
54 54
55 55
56 +
class TargetById:
57 +
    """ A locator for locating the next UI target using an id.
58 +
59 +
    Attributes
60 +
    ----------
61 +
    id : str
62 +
    """
63 +
    def __init__(self, id):
64 +
        self.id = id
65 +
66 +
56 67
class WidgetType(enum.Enum):
57 68
    """ A locator for locating nested widgets within a UI. Many editors will
58 69
    contain many sub-widgets (e.g. a textbox, slider, tabs, buttons, etc.).

@@ -12,6 +12,20 @@
Loading
12 12
from traitsui.testing.tester import locator
13 13
14 14
15 +
def find_by_id_in_nested_ui(wrapper, location):
16 +
    """ Helper function for resolving from a target to a TargetById. The
17 +
    target must have a solver registered from it to an instance of
18 +
    traitsui.ui.UI
19 +
20 +
    Parameters
21 +
    ----------
22 +
    wrapper : UIWrapper
23 +
    location : instance of locator.TargetById
24 +
    """
25 +
    new_interactor = wrapper.locate(locator.NestedUI())
26 +
    return new_interactor.find_by_id(location.id).target
27 +
28 +
15 29
def find_by_name_in_nested_ui(wrapper, location):
16 30
    """ Helper function for resolving from a target to a TargetByName. The
17 31
    target must have a solver registered from it to an instance of
@@ -52,3 +66,8 @@
Loading
52 66
        locator_class=locator.TargetByName,
53 67
        solver=find_by_name_in_nested_ui,
54 68
    )
69 +
    registry.register_solver(
70 +
        target_class=target_class,
71 +
        locator_class=locator.TargetById,
72 +
        solver=find_by_id_in_nested_ui,
73 +
    )

@@ -189,6 +189,27 @@
Loading
189 189
            delay=self.delay,
190 190
        ).find_by_name(name=name)
191 191
192 +
    def find_by_id(self, ui, id):
193 +
        """ Find the TraitsUI editor with the given identifier and return a new
194 +
        ``UIWrapper`` object for further interactions with the editor.
195 +
196 +
        Parameters
197 +
        ----------
198 +
        ui : traitsui.ui.UI
199 +
            The UI created, e.g. by ``create_ui``.
200 +
        id : str
201 +
            Id for finding an item in the UI.
202 +
203 +
        Returns
204 +
        -------
205 +
        wrapper : UIWrapper
206 +
        """
207 +
        return UIWrapper(
208 +
            target=ui,
209 +
            registries=self._registries,
210 +
            delay=self.delay,
211 +
        ).find_by_id(id=id)
212 +
192 213
193 214
def _get_editor_by_name(ui, name):
194 215
    """ Return a single Editor from an instance of traitsui.ui.UI with
@@ -221,6 +242,32 @@
Loading
221 242
    return editor
222 243
223 244
245 +
def _get_editor_by_id(ui, id):
246 +
    """ Return single Editor from an instance of traitsui.ui.UI with
247 +
    the given identifier.
248 +
249 +
    Parameters
250 +
    ----------
251 +
    ui : traitsui.ui.UI
252 +
        The UI from which an editor will be retrieved.
253 +
    id : str
254 +
        Id for finding an item in the UI.
255 +
256 +
    Returns
257 +
    -------
258 +
    editor : Editor
259 +
        The single editor found.
260 +
    """
261 +
    try:
262 +
        editor = getattr(ui.info, id)
263 +
    except AttributeError:
264 +
        raise ValueError(
265 +
            "No editors found with id {!r}. Got these: {!r}".format(
266 +
                id, ui._names)
267 +
            )
268 +
    return editor
269 +
270 +
224 271
def _get_ui_registry():
225 272
    """ Return a TargetRegistry with traitsui.ui.UI as the target.
226 273
@@ -236,4 +283,11 @@
Loading
236 283
            _get_editor_by_name(wrapper.target, location.name)
237 284
        ),
238 285
    )
286 +
    registry.register_solver(
287 +
        target_class=UI,
288 +
        locator_class=locator.TargetById,
289 +
        solver=lambda wrapper, location: (
290 +
            _get_editor_by_id(wrapper.target, location.id)
291 +
        ),
292 +
    )
239 293
    return registry

@@ -102,6 +102,20 @@
Loading
102 102
        """
103 103
        return self.locate(locator.TargetByName(name=name))
104 104
105 +
    def find_by_id(self, id):
106 +
        """ Find a target inside the current target using an id.
107 +
108 +
        Parameters
109 +
        ----------
110 +
        id : str
111 +
            Id for finding an item in the UI.
112 +
113 +
        Returns
114 +
        -------
115 +
        wrapper : UIWrapper
116 +
        """
117 +
        return self.locate(locator.TargetById(id=id))
118 +
105 119
    def perform(self, interaction):
106 120
        """ Perform a user interaction that causes side effects.
107 121
Files Coverage
traitsui 33.5%
Project Totals (283 files) 33.5%
2277.1
TRAVIS_OS_NAME=linux
2277.2
TRAVIS_OS_NAME=linux
1
codecov:
2
  notify:
3
    require_ci_to_pass: yes
4

5
coverage:
6
  precision: 1
7
  round: up
8

9
  status:
10
    patch:
11
      default:
12
        only_pulls: yes
13

14
comment : off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading