robotframework-platynui 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. PlatynUI/ButtonKeywords.py +9 -0
  2. PlatynUI/TextKeywords.py +7 -0
  3. PlatynUI/__about__.py +4 -0
  4. PlatynUI/__init__.py +34 -0
  5. PlatynUI/core/__init__.py +13 -0
  6. PlatynUI/core/adapter.py +152 -0
  7. PlatynUI/core/adapterfactory.py +51 -0
  8. PlatynUI/core/adapterproxy.py +168 -0
  9. PlatynUI/core/contextbase.py +586 -0
  10. PlatynUI/core/exceptions.py +77 -0
  11. PlatynUI/core/internal/__init__.py +0 -0
  12. PlatynUI/core/internal/decorator.py +148 -0
  13. PlatynUI/core/locatorbase.py +197 -0
  14. PlatynUI/core/locatorscope.py +17 -0
  15. PlatynUI/core/predicate.py +15 -0
  16. PlatynUI/core/settings.py +63 -0
  17. PlatynUI/core/strategies/__init__.py +1 -0
  18. PlatynUI/core/strategies/strategies.py +26 -0
  19. PlatynUI/core/strategybase.py +8 -0
  20. PlatynUI/core/strategyimpl.py +102 -0
  21. PlatynUI/core/technology.py +25 -0
  22. PlatynUI/core/types.py +421 -0
  23. PlatynUI/core/wait_for.py +47 -0
  24. PlatynUI/core/weight_calculator.py +110 -0
  25. PlatynUI/py.typed +0 -0
  26. PlatynUI/robot/__init__.py +0 -0
  27. PlatynUI/robot/reporting.py +74 -0
  28. PlatynUI/technology/__init__.py +0 -0
  29. PlatynUI/technology/uiautomation/.gitignore +1 -0
  30. PlatynUI/technology/uiautomation/__init__.py +4 -0
  31. PlatynUI/technology/uiautomation/core/adapterfactory.py +88 -0
  32. PlatynUI/technology/uiautomation/core/displaydevice.py +23 -0
  33. PlatynUI/technology/uiautomation/core/impls/__init__.py +2 -0
  34. PlatynUI/technology/uiautomation/core/impls/control.py +31 -0
  35. PlatynUI/technology/uiautomation/core/impls/window.py +83 -0
  36. PlatynUI/technology/uiautomation/core/keyboarddevice.py +21 -0
  37. PlatynUI/technology/uiautomation/core/loader.py +117 -0
  38. PlatynUI/technology/uiautomation/core/mousedevice.py +29 -0
  39. PlatynUI/technology/uiautomation/core/technology.py +61 -0
  40. PlatynUI/technology/uiautomation/core/uiaadapter.py +197 -0
  41. PlatynUI/technology/uiautomation/core/uiabase.py +19 -0
  42. PlatynUI/technology/uiautomation/desktop.py +11 -0
  43. PlatynUI/technology/uiautomation/locator.py +435 -0
  44. PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Core.dll +0 -0
  45. PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.Core.dll +0 -0
  46. PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.dll +0 -0
  47. PlatynUI/technology/uiautomation/runtime/Microsoft.Xaml.Behaviors.dll +0 -0
  48. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.deps.json +266 -0
  49. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.dll +0 -0
  50. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.exe +0 -0
  51. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.runtimeconfig.json +19 -0
  52. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.dll +0 -0
  53. PlatynUI/technology/uiautomation/runtime/System.ComponentModel.Composition.dll +0 -0
  54. PlatynUI/technology/uiautomation/spy/__init__.py +0 -0
  55. PlatynUI/technology/uiautomation/spy/__main__.py +24 -0
  56. PlatynUI/ui/__init__.py +65 -0
  57. PlatynUI/ui/application.py +27 -0
  58. PlatynUI/ui/buttons.py +82 -0
  59. PlatynUI/ui/combobox.py +149 -0
  60. PlatynUI/ui/container.py +9 -0
  61. PlatynUI/ui/control.py +49 -0
  62. PlatynUI/ui/core/__init__.py +3 -0
  63. PlatynUI/ui/core/devices/__init__.py +6 -0
  64. PlatynUI/ui/core/devices/basedisplaydevice.py +25 -0
  65. PlatynUI/ui/core/devices/basekeyboarddevice.py +64 -0
  66. PlatynUI/ui/core/devices/basemousedevice.py +30 -0
  67. PlatynUI/ui/core/devices/basescreendevice.py +16 -0
  68. PlatynUI/ui/core/devices/displaydevice.py +113 -0
  69. PlatynUI/ui/core/devices/inputdevice.py +24 -0
  70. PlatynUI/ui/core/devices/keyboarddevice.py +279 -0
  71. PlatynUI/ui/core/devices/keyboardproxy.py +69 -0
  72. PlatynUI/ui/core/devices/mousebutton.py +11 -0
  73. PlatynUI/ui/core/devices/mousedevice.py +279 -0
  74. PlatynUI/ui/core/devices/mouseproxy.py +178 -0
  75. PlatynUI/ui/core/ui_technology.py +31 -0
  76. PlatynUI/ui/core/window_manager.py +59 -0
  77. PlatynUI/ui/desktopbase.py +56 -0
  78. PlatynUI/ui/dialog.py +10 -0
  79. PlatynUI/ui/edit.py +48 -0
  80. PlatynUI/ui/element.py +265 -0
  81. PlatynUI/ui/graphic.py +14 -0
  82. PlatynUI/ui/header.py +33 -0
  83. PlatynUI/ui/item.py +100 -0
  84. PlatynUI/ui/lists.py +37 -0
  85. PlatynUI/ui/menus.py +42 -0
  86. PlatynUI/ui/orientation.py +9 -0
  87. PlatynUI/ui/pane.py +14 -0
  88. PlatynUI/ui/proxies/__init__.py +4 -0
  89. PlatynUI/ui/proxies/standardproxies.py +391 -0
  90. PlatynUI/ui/scrollbar.py +9 -0
  91. PlatynUI/ui/strategies/__init__.py +19 -0
  92. PlatynUI/ui/strategies/activatable.py +27 -0
  93. PlatynUI/ui/strategies/application.py +28 -0
  94. PlatynUI/ui/strategies/closeable.py +22 -0
  95. PlatynUI/ui/strategies/control.py +16 -0
  96. PlatynUI/ui/strategies/editable.py +13 -0
  97. PlatynUI/ui/strategies/element.py +65 -0
  98. PlatynUI/ui/strategies/expandable.py +27 -0
  99. PlatynUI/ui/strategies/hasnativewindowhandle.py +14 -0
  100. PlatynUI/ui/strategies/hasorientation.py +15 -0
  101. PlatynUI/ui/strategies/maximizeable.py +27 -0
  102. PlatynUI/ui/strategies/minimizeable.py +27 -0
  103. PlatynUI/ui/strategies/movable.py +14 -0
  104. PlatynUI/ui/strategies/resizable.py +13 -0
  105. PlatynUI/ui/strategies/restorable.py +13 -0
  106. PlatynUI/ui/strategies/selectable.py +27 -0
  107. PlatynUI/ui/strategies/text.py +55 -0
  108. PlatynUI/ui/strategies/title.py +14 -0
  109. PlatynUI/ui/strategies/toggleable.py +23 -0
  110. PlatynUI/ui/strategies/value.py +15 -0
  111. PlatynUI/ui/table.py +56 -0
  112. PlatynUI/ui/tabs.py +28 -0
  113. PlatynUI/ui/text.py +14 -0
  114. PlatynUI/ui/togglestate.py +12 -0
  115. PlatynUI/ui/tree.py +99 -0
  116. PlatynUI/ui/unknown.py +9 -0
  117. PlatynUI/ui/window.py +177 -0
  118. robotframework_platynui-0.0.1.dist-info/METADATA +49 -0
  119. robotframework_platynui-0.0.1.dist-info/RECORD +122 -0
  120. robotframework_platynui-0.0.1.dist-info/WHEEL +4 -0
  121. robotframework_platynui-0.0.1.dist-info/entry_points.txt +2 -0
  122. robotframework_platynui-0.0.1.dist-info/licenses/LICENSE.txt +73 -0
PlatynUI/core/types.py ADDED
@@ -0,0 +1,421 @@
1
+ from typing import Any, Callable, Iterator, Optional
2
+
3
+ __all__ = ["Point", "VirtualPoint", "Rect", "Size"]
4
+
5
+
6
+ class Point:
7
+ def __init__(self, x: Optional[float] = None, y: Optional[float] = None) -> None:
8
+ self._x = x
9
+ self._y = y
10
+
11
+ @property
12
+ def is_valid(self) -> bool:
13
+ return self._x is not None and self._y is not None
14
+
15
+ @property
16
+ def x(self) -> float:
17
+ if self._x is None:
18
+ raise ValueError("x is not set")
19
+
20
+ return self._x
21
+
22
+ @x.setter
23
+ def x(self, v: float) -> None:
24
+ self._x = v
25
+
26
+ def x_is_valid(self) -> bool:
27
+ return self._x is not None
28
+
29
+ def y_is_valid(self) -> bool:
30
+ return self._y is not None
31
+
32
+ @property
33
+ def y(self) -> float:
34
+ if self._y is None:
35
+ raise ValueError("y is not set")
36
+
37
+ return self._y
38
+
39
+ @y.setter
40
+ def y(self, v: float) -> None:
41
+ self._y = v
42
+
43
+ def __iter__(self) -> Iterator[Optional[float]]:
44
+ yield self.x
45
+ yield self.y
46
+
47
+ def __repr__(self) -> str:
48
+ return "Point(x=%s, y=%s)" % (self.x, self.y)
49
+
50
+ def clone(self) -> "Point":
51
+ return Point(self.x, self.y)
52
+
53
+ def __eq__(self, other: Any) -> bool:
54
+ if isinstance(other, Point):
55
+ return self.x == other.x and self.y == other.y
56
+
57
+ return False
58
+
59
+ def __bool__(self) -> bool:
60
+ return self.is_valid
61
+
62
+ def __add__(self, other: Any) -> "Point":
63
+ if isinstance(other, Point):
64
+ return Point(
65
+ self.x + other.x if self.x is not None and other.x is not None else None,
66
+ self.y + other.y if self.y is not None and other.y is not None else None,
67
+ )
68
+
69
+ raise NotImplementedError
70
+
71
+
72
+ class VirtualPoint(Point):
73
+ def __init__(self, name: Any, func: Callable[["Rect"], Point]):
74
+ super().__init__()
75
+ self.name = name
76
+ self.func = func
77
+
78
+ @property
79
+ def is_valid(self) -> bool:
80
+ return False
81
+
82
+ def calc_rect(self, r: Optional["Rect"]) -> Point:
83
+ if r is None:
84
+ return Point()
85
+
86
+ return self.func(r)
87
+
88
+ def __eq__(self, other: Any) -> bool:
89
+ if isinstance(other, VirtualPoint):
90
+ return bool(self.name == other.name)
91
+
92
+ raise NotImplementedError
93
+
94
+ def __repr__(self) -> str:
95
+ return "VirtualPoint(%s)" % repr(self.name)
96
+
97
+
98
+ class Size:
99
+ def __init__(self, width: Optional[float] = None, height: Optional[float] = None):
100
+ self._width = width
101
+ self._height = height
102
+
103
+ @property
104
+ def width(self) -> float:
105
+ if self._width is None:
106
+ raise ValueError("width is not set")
107
+
108
+ return self._width
109
+
110
+ @width.setter
111
+ def width(self, v: float) -> None:
112
+ self._width = v
113
+
114
+ @property
115
+ def height(self) -> float:
116
+ if self._height is None:
117
+ raise ValueError("height is not set")
118
+ return self._height
119
+
120
+ @height.setter
121
+ def height(self, v: float) -> None:
122
+ self._height = v
123
+
124
+ @property
125
+ def is_valid(self) -> bool:
126
+ return self.width is not None and self.height is not None
127
+
128
+ def __iter__(self) -> Iterator[Optional[float]]:
129
+ yield self.width
130
+ yield self.height
131
+
132
+ def __repr__(self) -> str:
133
+ return "Size(width=%s, height=%s)" % (self.width, self.height)
134
+
135
+ def clone(self) -> "Size":
136
+ return Size(self.width, self.height)
137
+
138
+ def __eq__(self, other: Any) -> bool:
139
+ if isinstance(other, Size):
140
+ return self.width == other.width and self.height == other.height
141
+
142
+ return False
143
+
144
+ def __bool__(self) -> bool:
145
+ return self.is_valid
146
+
147
+
148
+ class Rect:
149
+ def __init__(
150
+ self,
151
+ left: Optional[float] = None,
152
+ top: Optional[float] = None,
153
+ width: Optional[float] = None,
154
+ height: Optional[float] = None,
155
+ ):
156
+ self._left = left
157
+ self._top = top
158
+ self._width = width
159
+ self._height = height
160
+
161
+ @property
162
+ def x1(self) -> float:
163
+ return self.left
164
+
165
+ @property
166
+ def y1(self) -> float:
167
+ return self.top
168
+
169
+ @property
170
+ def x2(self) -> float:
171
+ return self.left + self.width - 1
172
+
173
+ @property
174
+ def y2(self) -> float:
175
+ return self.top + self.height - 1
176
+
177
+ @property
178
+ def is_valid(self) -> bool:
179
+ return (
180
+ self._left is not None
181
+ and self._top is not None
182
+ and self._width is not None
183
+ and self._height is not None
184
+ and self.x1 <= self.x2
185
+ and self.y1 <= self.y2
186
+ )
187
+
188
+ @property
189
+ def is_null(self) -> bool:
190
+ return self.x2 == self.x1 - 1 and self.y2 == self.y1 - 1
191
+
192
+ @property
193
+ def is_empty(self) -> bool:
194
+ return self.x1 > self.x2 or self.y1 > self.y2
195
+
196
+ @property
197
+ def left(self) -> float:
198
+ if self._left is None:
199
+ raise ValueError("left is not set")
200
+ return self._left
201
+
202
+ @left.setter
203
+ def left(self, v: float) -> None:
204
+ self._left = v
205
+
206
+ @property
207
+ def top(self) -> float:
208
+ if self._top is None:
209
+ raise ValueError("top is not set")
210
+
211
+ return self._top
212
+
213
+ @top.setter
214
+ def top(self, v: float) -> None:
215
+ self._top = v
216
+
217
+ @property
218
+ def width(self) -> float:
219
+ if self._width is None:
220
+ raise ValueError("width is not set")
221
+
222
+ return self._width
223
+
224
+ @width.setter
225
+ def width(self, v: float) -> None:
226
+ self._width = v
227
+
228
+ @property
229
+ def height(self) -> float:
230
+ if self._height is None:
231
+ raise ValueError("height is not set")
232
+
233
+ return self._height
234
+
235
+ @height.setter
236
+ def height(self, v: float) -> None:
237
+ self._height = v
238
+
239
+ @property
240
+ def right(self) -> float:
241
+ return self.left + self.width - 1
242
+
243
+ @property
244
+ def bottom(self) -> float:
245
+ return self.top + self.height - 1
246
+
247
+ @property
248
+ def top_left(self) -> Point:
249
+ if not self:
250
+ return Point()
251
+ return Point(self.left, self.top)
252
+
253
+ @property
254
+ def top_right(self) -> Point:
255
+ if not self:
256
+ return Point()
257
+ return Point(self.right, self.top)
258
+
259
+ @property
260
+ def bottom_right(self) -> Point:
261
+ if not self:
262
+ return Point()
263
+ return Point(self.right, self.bottom)
264
+
265
+ @property
266
+ def bottom_left(self) -> Point:
267
+ if not self:
268
+ return Point()
269
+ return Point(self.left, self.bottom)
270
+
271
+ @property
272
+ def center(self) -> Point:
273
+ if not self:
274
+ return Point()
275
+ return Point(self.left + self.width / 2, self.top + self.height / 2)
276
+
277
+ @property
278
+ def size(self) -> Size:
279
+ return Size(self.width, self.height)
280
+
281
+ def __iter__(self) -> Iterator[float]:
282
+ yield self.left
283
+ yield self.top
284
+ yield self.width
285
+ yield self.height
286
+
287
+ def __repr__(self) -> str:
288
+ return "Rect(left=%s, top=%s, width=%s, height=%s)" % (self.left, self.top, self.width, self.height)
289
+
290
+ def __eq__(self, other: Any) -> bool:
291
+ if isinstance(other, Rect):
292
+ o = other
293
+ return self.left == o.left and self.top == o.top and self.width == o.width and self.height == o.height
294
+
295
+ return False
296
+
297
+ def __bool__(self) -> bool:
298
+ return self.is_valid
299
+
300
+ def contains(
301
+ self, p: Optional[Point] = None, x: Optional[float] = None, y: Optional[float] = None, proper: bool = False
302
+ ) -> bool:
303
+ if not self:
304
+ return False
305
+
306
+ if p is None:
307
+ p = Point()
308
+
309
+ if x is not None:
310
+ p.x = x
311
+ if y is not None:
312
+ p.y = y
313
+
314
+ if not p:
315
+ return False
316
+
317
+ x1 = self.x1
318
+ y1 = self.y1
319
+ x2 = self.x2
320
+ y2 = self.y2
321
+
322
+ if x2 < x1 - 1:
323
+ l = x2
324
+ r = x1
325
+ else:
326
+ l = x1
327
+ r = x2
328
+
329
+ if proper:
330
+ if p.x <= l or p.x >= r:
331
+ return False
332
+ else:
333
+ if p.x < l or p.x > r:
334
+ return False
335
+
336
+ if y2 < y1 - 1:
337
+ t = y2
338
+ b = y1
339
+ else:
340
+ t = y1
341
+ b = y2
342
+
343
+ if proper:
344
+ if p.y <= t or p.y >= b:
345
+ return False
346
+ else:
347
+ if p.y < t or p.y > b:
348
+ return False
349
+
350
+ return True
351
+
352
+ def __contains__(self, p: Point) -> bool:
353
+ return self.contains(p)
354
+
355
+ def intersected(self, r: "Rect") -> "Rect":
356
+ if not self or not r:
357
+ return Rect()
358
+
359
+ l1 = self.x1
360
+ r1 = self.x1
361
+ if self.x2 - self.x1 + 1 < 0:
362
+ l1 = self.x2
363
+ else:
364
+ r1 = self.x2
365
+
366
+ l2 = r.x1
367
+ r2 = r.x1
368
+ if r.x2 - r.x1 + 1 < 0:
369
+ l2 = r.x2
370
+ else:
371
+ r2 = r.x2
372
+
373
+ if l1 > r2 or l2 > r1:
374
+ return Rect()
375
+
376
+ t1 = self.y1
377
+ b1 = self.y1
378
+ if self.y2 - self.y1 + 1 < 0:
379
+ t1 = self.y2
380
+ else:
381
+ b1 = self.y2
382
+
383
+ t2 = r.y1
384
+ b2 = r.y1
385
+ if r.y2 - r.y1 + 1 < 0:
386
+ t2 = r.y2
387
+ else:
388
+ b2 = r.y2
389
+
390
+ if t1 > b2 or t2 > b1:
391
+ return Rect()
392
+
393
+ x1 = max(l1, l2)
394
+ x2 = min(r1, r2)
395
+ y1 = max(t1, t2)
396
+ y2 = min(b1, b2)
397
+
398
+ return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1)
399
+
400
+ def inflated(self, dx: float, dy: float) -> "Rect":
401
+ if not self:
402
+ return Rect()
403
+
404
+ return Rect(self.left - dx, self.top - dy, self.width + dx, self.height + dy)
405
+
406
+ def deflated(self, dx: float, dy: float) -> "Rect":
407
+ if not self:
408
+ return Rect()
409
+
410
+ return Rect(self.left + dx, self.top + dy, self.width - dx, self.height - dy)
411
+
412
+ TOP_LEFT = VirtualPoint("top_left", lambda r: r.top_left)
413
+ TOP_RIGHT = VirtualPoint("top_left", lambda r: Point(r.right, r.top))
414
+ TOP = VirtualPoint("top", lambda r: Point(None, r.top))
415
+ VMIDDLE = VirtualPoint("bottom", lambda r: Point(None, r.top + r.height // 2))
416
+ HMIDDLE = VirtualPoint("right", lambda r: Point(r.left + r.width // 2, None))
417
+ BOTTOM = VirtualPoint("bottom", lambda r: Point(None, r.top + r.height - 1))
418
+ LEFT = VirtualPoint("left", lambda r: Point(r.left, None))
419
+ RIGHT = VirtualPoint("right", lambda r: Point(r.left + r.width - 1, None))
420
+ CENTER = VirtualPoint("center", lambda r: r.center)
421
+ BOTTOM_RIGHT = VirtualPoint("bottom_right", lambda r: r.bottom_right)
@@ -0,0 +1,47 @@
1
+ import time
2
+ from typing import Callable, Optional
3
+
4
+ from .exceptions import PlatynUiFatalError
5
+ from .settings import Settings
6
+
7
+ __all__ = ["wait_for"]
8
+
9
+
10
+ def wait_for(
11
+ *predicates: Callable[[], bool],
12
+ timeout: Optional[float] = None,
13
+ delay: Optional[float] = None,
14
+ invalidater: Optional[Callable[[], None]] = None,
15
+ ) -> bool:
16
+ if timeout is None:
17
+ timeout = Settings.current().wait_for_timeout
18
+
19
+ if delay is None:
20
+ delay = Settings.current().wait_for_delay
21
+
22
+ start_time = time.time()
23
+ result = False
24
+
25
+ while not result:
26
+ if time.time() - start_time > timeout:
27
+ break
28
+ for p in predicates:
29
+ if time.time() - start_time > timeout:
30
+ break
31
+ try:
32
+ result = p()
33
+ except (PlatynUiFatalError, KeyboardInterrupt, SystemExit):
34
+ raise
35
+
36
+ if not result:
37
+ break
38
+
39
+ if result:
40
+ break
41
+
42
+ time.sleep(delay)
43
+
44
+ if invalidater is not None:
45
+ invalidater()
46
+
47
+ return result
@@ -0,0 +1,110 @@
1
+ import re
2
+ from typing import TYPE_CHECKING, Any, Dict, cast
3
+
4
+ from .strategies import NativeProperties, Properties
5
+
6
+ if TYPE_CHECKING:
7
+ from .adapter import Adapter
8
+
9
+
10
+ class WeightCalculator:
11
+ def __init__(self, adapter: "Adapter"):
12
+ self.adapter = adapter
13
+ self.cache: Dict[str, Any] = {}
14
+ self.native_properties_cache: Dict[str, Any] = {}
15
+ self.properties_cache: Dict[str, Any] = {}
16
+
17
+ def cached(self, name: str) -> Any:
18
+ if name in self.cache:
19
+ return self.cache[name]
20
+
21
+ if hasattr(self.adapter, name):
22
+ self.cache[name] = getattr(self.adapter, name)
23
+ else:
24
+ self.cache[name] = None
25
+
26
+ return self.cache[name]
27
+
28
+ def properties_cached(self, name: str) -> Any:
29
+ if name in self.properties_cache:
30
+ return self.properties_cache[name]
31
+
32
+ if Properties.strategy_name in self.adapter.supported_strategies:
33
+ self.properties_cache[name] = self.adapter.get_strategy(Properties).get_property_value(name)
34
+ else:
35
+ self.properties_cache[name] = None
36
+
37
+ return self.properties_cache[name]
38
+
39
+ def native_properties_cached(self, name: str) -> Any:
40
+ if name in self.native_properties_cache:
41
+ return self.native_properties_cache[name]
42
+
43
+ if NativeProperties.strategy_name in self.adapter.supported_strategies:
44
+ self.native_properties_cache[name] = self.adapter.get_strategy(NativeProperties).get_native_property_value(
45
+ name
46
+ )
47
+ else:
48
+ self.native_properties_cache[name] = None
49
+
50
+ return self.native_properties_cache[name]
51
+
52
+ @staticmethod
53
+ def test_values(actual: Any, expected: Any) -> bool:
54
+ if isinstance(expected, re.Pattern):
55
+ return expected.fullmatch(str(actual)) is not None
56
+
57
+ return bool(actual == expected)
58
+
59
+ def calculate(self, criterias: Dict[str, object]) -> int:
60
+ weight = 0
61
+
62
+ if "technology" in criterias and criterias["technology"] is not None:
63
+ if self.test_values(type(self.adapter.technology), criterias["technology"]):
64
+ weight += 100000
65
+ else:
66
+ return 0
67
+
68
+ if "role" in criterias and criterias["role"] is not None:
69
+ if self.cached("role") == criterias["role"]:
70
+ weight += 10000
71
+ else:
72
+ try:
73
+ i = list(self.cached("supported_roles")).index(criterias["role"])
74
+ weight += 5000 - i
75
+ except ValueError:
76
+ return 0
77
+
78
+ if "framework_id" in criterias and criterias["framework_id"] is not None:
79
+ if self.test_values(self.cached("framework_id"), criterias["framework_id"]):
80
+ weight += 1000
81
+ else:
82
+ return 0
83
+
84
+ if "class_name" in criterias and criterias["class_name"] is not None:
85
+ if self.test_values(self.cached("class_name"), criterias["class_name"]):
86
+ weight += 500
87
+ else:
88
+ return 0
89
+
90
+ if "tag_name" in criterias and criterias["tag_name"] is not None:
91
+ if self.test_values(self.cached("tag_name"), criterias["tag_name"]):
92
+ weight += 400
93
+ else:
94
+ return 0
95
+
96
+ if "properties" in criterias and criterias["properties"] is not None:
97
+ for p, v in cast(Dict[str, Any], criterias["properties"]).items():
98
+ if self.test_values(self.properties_cached(p), v):
99
+ weight += 200
100
+ else:
101
+ return 0
102
+
103
+ if "native_properties" in criterias and criterias["native_properties"] is not None:
104
+ for p, v in cast(Dict[str, Any], criterias["native_properties"]).items():
105
+ if self.test_values(self.native_properties_cached(p), v):
106
+ weight += 200
107
+ else:
108
+ return 0
109
+
110
+ return weight
PlatynUI/py.typed ADDED
File without changes
File without changes
@@ -0,0 +1,74 @@
1
+ from inspect import ismethod
2
+ from typing import (
3
+ Any,
4
+ Callable,
5
+ Optional,
6
+ TypeVar,
7
+ Union,
8
+ overload,
9
+ )
10
+
11
+ from robot.result import Keyword as KeywordResult
12
+ from robot.running.bodyrunner import KeywordRunner
13
+ from robot.running.context import EXECUTION_CONTEXTS
14
+ from robot.running.librarykeyword import LibraryKeyword
15
+ from robot.running.model import Argument, Keyword
16
+ from robot.running.statusreporter import StatusReporter
17
+ from typing_extensions import ParamSpec
18
+
19
+ T = TypeVar("T")
20
+ P = ParamSpec("P")
21
+
22
+
23
+ @overload
24
+ def report_as_keyword(__func: Callable[P, T]) -> Callable[P, T]: ...
25
+
26
+
27
+ @overload
28
+ def report_as_keyword(
29
+ *,
30
+ name: Optional[str] = None,
31
+ ) -> Callable[[Callable[P, T]], Callable[P, T]]: ...
32
+
33
+
34
+ def report_as_keyword(
35
+ __func: Optional[Callable[P, T]] = None,
36
+ *,
37
+ name: Optional[str] = None,
38
+ ) -> Union[Callable[P, T], Callable[[Callable[P, T]], Callable[P, T]]]:
39
+ def decorator(func: Callable[P, T]) -> Callable[P, T]:
40
+
41
+ implementation = LibraryKeyword(None, name or func.__qualname__)
42
+
43
+ def wrapper(*args: P.args, **kwds: P.kwargs) -> T:
44
+
45
+ report_args = (*args, *(Argument(k, v) for k, v in kwds.items()))
46
+ if ismethod(func):
47
+ report_args = report_args[1:]
48
+
49
+ data = Keyword(implementation.name, args=report_args)
50
+
51
+ if EXECUTION_CONTEXTS.current is None:
52
+ return func(*args, **kwds)
53
+
54
+ result = EXECUTION_CONTEXTS.current.steps[-1][1] if EXECUTION_CONTEXTS.current.steps else None
55
+
56
+ if result is None:
57
+ result = EXECUTION_CONTEXTS.current.test or EXECUTION_CONTEXTS.current.suite
58
+
59
+ if result is None:
60
+ return func(*args, **kwds)
61
+ kw_result = result.body.create_keyword()
62
+ kw_result.config(name=implementation.name, args=data.args)
63
+ try:
64
+ with StatusReporter(data, kw_result, EXECUTION_CONTEXTS.current, implementation=implementation):
65
+ return func(*args, **kwds)
66
+ except BaseException as e:
67
+ raise e
68
+
69
+ return wrapper
70
+
71
+ if __func is None:
72
+ return decorator
73
+
74
+ return decorator(__func)
File without changes
@@ -0,0 +1 @@
1
+ runtime
@@ -0,0 +1,4 @@
1
+ from .desktop import Desktop
2
+ from .locator import Locator, locator
3
+
4
+ __all__ = ["Locator", "Desktop", "locator"]