How to use _getElementAtPosition method in pyatom

Best Python code snippet using pyatom_python

test_lsp.py

Source:test_lsp.py Github

copy

Full Screen

...538 path = Path(p.join(TEST_PROJECT, "another_library", "foo.vhd"))539 for _patch in patches:540 _patch.start()541 # Check locations outside return nothing542 self.assertIsNone(self.server._getElementAtPosition(path, Location(0, 0)))543 # Check design units are found, ensure boundaries match544 self.assertIsNone(self.server._getElementAtPosition(path, Location(1, 1)))545 self.assertIs(self.server._getElementAtPosition(path, Location(1, 2)), UNIT_A)546 self.assertIs(self.server._getElementAtPosition(path, Location(1, 7)), UNIT_A)547 self.assertIsNone(self.server._getElementAtPosition(path, Location(1, 8)))548 self.assertIsNone(self.server._getElementAtPosition(path, Location(3, 3)))549 self.assertIs(self.server._getElementAtPosition(path, Location(3, 4)), UNIT_A)550 self.assertIs(self.server._getElementAtPosition(path, Location(3, 9)), UNIT_A)551 self.assertIsNone(self.server._getElementAtPosition(path, Location(3, 10)))552 self.assertIsNone(self.server._getElementAtPosition(path, Location(5, 5)))553 self.assertIs(self.server._getElementAtPosition(path, Location(5, 6)), UNIT_B)554 self.assertIs(self.server._getElementAtPosition(path, Location(5, 11)), UNIT_B)555 self.assertIsNone(self.server._getElementAtPosition(path, Location(5, 12)))556 self.assertIsNone(self.server._getElementAtPosition(path, Location(7, 7)))557 self.assertIs(self.server._getElementAtPosition(path, Location(7, 8)), UNIT_B)558 self.assertIs(self.server._getElementAtPosition(path, Location(7, 13)), UNIT_B)559 self.assertIsNone(self.server._getElementAtPosition(path, Location(7, 14)))560 # Now check dependencies561 self.assertIsNone(self.server._getElementAtPosition(path, Location(9, 9)))562 self.assertIs(self.server._getElementAtPosition(path, Location(9, 10)), DEP_A)563 self.assertIs(self.server._getElementAtPosition(path, Location(9, 20)), DEP_A)564 self.assertIsNone(self.server._getElementAtPosition(path, Location(9, 21)))565 self.assertIsNone(self.server._getElementAtPosition(path, Location(11, 11)))566 self.assertIs(self.server._getElementAtPosition(path, Location(11, 12)), DEP_A)567 self.assertIs(self.server._getElementAtPosition(path, Location(11, 22)), DEP_A)568 self.assertIsNone(self.server._getElementAtPosition(path, Location(11, 23)))569 self.assertIsNone(self.server._getElementAtPosition(path, Location(13, 13)))570 self.assertIs(self.server._getElementAtPosition(path, Location(13, 14)), DEP_B)571 self.assertIs(self.server._getElementAtPosition(path, Location(13, 24)), DEP_B)572 self.assertIsNone(self.server._getElementAtPosition(path, Location(13, 25)))573 self.assertIsNone(self.server._getElementAtPosition(path, Location(15, 15)))574 self.assertIs(self.server._getElementAtPosition(path, Location(15, 16)), DEP_B)575 self.assertIs(self.server._getElementAtPosition(path, Location(15, 26)), DEP_B)576 self.assertIsNone(self.server._getElementAtPosition(path, Location(15, 27)))577 for _patch in patches:578 _patch.stop()579 @patch(580 "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",581 (Identifier("ieee"),),582 )583 def test_HoverOnInvalidRange(self):584 path = p.join(TEST_PROJECT, "another_library", "foo.vhd")585 self.assertIsNone(586 self.server.hover(uris.from_fs_path(path), {"line": 0, "character": 0})587 )588 @patch(589 "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",590 (Identifier("ieee"),),591 )592 def test_HoverOnDesignUnit(self):593 path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")594 very_common_pkg = p.join(TEST_PROJECT, "basic_library", "very_common_pkg.vhd")595 package_with_constants = p.join(596 TEST_PROJECT, "basic_library", "package_with_constants.vhd"597 )598 clock_divider = p.join(TEST_PROJECT, "basic_library", "clock_divider.vhd")599 expected = [600 "Build sequence for %s is" % str(path_to_foo),601 "",602 tabulate(603 [604 (1, "basic_library", str(very_common_pkg)),605 (2, "basic_library", str(package_with_constants)),606 (3, "basic_library", str(clock_divider)),607 (4, DEFAULT_LIBRARY.name, str(path_to_foo)),608 ],609 headers=("#", "Library", "Path"),610 tablefmt="plain",611 ),612 ]613 self.assertDictEqual(614 self.server.hover(615 uris.from_fs_path(path_to_foo), {"line": 7, "character": 7}616 ),617 {"contents": "\n".join(expected)},618 )619 @patch(620 "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",621 (Identifier("ieee"),),622 )623 def test_HoverOnDependency(self):624 path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")625 clock_divider = p.join(TEST_PROJECT, "basic_library", "clock_divider.vhd")626 self.assertDictEqual(627 self.server.hover(628 uris.from_fs_path(path_to_foo), {"line": 32, "character": 32}629 ),630 {"contents": 'Path "%s", library "basic_library"' % clock_divider},631 )632 @patch(633 "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",634 (Identifier("ieee"),),635 )636 def test_GetDefinitionMatchingDependency(self):637 source = p.join(TEST_PROJECT, "basic_library", "use_entity_a_and_b.vhd")638 target = p.join(TEST_PROJECT, "basic_library", "two_entities_one_file.vhd")639 definitions = self.server.definitions(640 uris.from_fs_path(source), {"line": 1, "character": 9}641 )642 self.assertIn(643 {644 "uri": uris.from_fs_path(target),645 "range": {646 "start": {"line": 1, "character": 7},647 "end": {"line": 1, "character": 15},648 },649 },650 definitions,651 )652 self.assertIn(653 {654 "uri": uris.from_fs_path(target),655 "range": {656 "start": {"line": 4, "character": 7},657 "end": {"line": 4, "character": 15},658 },659 },660 definitions,661 )662 @patch(663 "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",664 (Identifier("ieee"),),665 )666 def test_GetDefinitionBuiltInLibrary(self):667 path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")668 self.assertEqual(669 self.server.definitions(670 uris.from_fs_path(path_to_foo), {"line": 3, "character": 15}671 ),672 [],673 )674 @patch(675 "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",676 (Identifier("ieee"),),677 )678 def test_GetDefinitionNotKnown(self):679 path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")680 self.assertEqual(681 self.server.definitions(682 uris.from_fs_path(path_to_foo), {"line": 0, "character": 0}683 ),684 [],685 )686 @patch.object(687 hdl_checker.database.Database,688 "getReferencesToDesignUnit",689 return_value=[690 RequiredDesignUnit(691 name=Identifier("clock_divider"),692 library=Identifier("basic_library"),693 owner=Path("some_path"),694 locations=(Location(1, 2), Location(3, 4)),695 )696 ],697 )698 def test_ReferencesOfAValidElement(self, get_references):699 path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")700 # Make sure we picked up an existing element701 unit = self.server._getElementAtPosition(Path(path_to_foo), Location(7, 7))702 self.assertIsNotNone(unit)703 self.assertCountEqual(704 self.server.references(705 doc_uri=uris.from_fs_path(path_to_foo),706 position={"line": 7, "character": 7},707 exclude_declaration=True,708 ),709 (710 {711 "uri": uris.from_fs_path("some_path"),712 "range": {713 "start": {"line": 1, "character": 2},714 "end": {"line": 1, "character": 2},715 },716 },717 {718 "uri": uris.from_fs_path("some_path"),719 "range": {720 "start": {"line": 3, "character": 4},721 "end": {"line": 3, "character": 4},722 },723 },724 ),725 )726 get_references.assert_called_once()727 get_references.reset_mock()728 self.assertCountEqual(729 self.server.references(730 doc_uri=uris.from_fs_path(path_to_foo),731 position={"line": 7, "character": 7},732 exclude_declaration=False,733 ),734 (735 {736 "uri": uris.from_fs_path(path_to_foo),737 "range": {738 "start": {"line": 7, "character": 7},739 "end": {"line": 7, "character": 7},740 },741 },742 {743 "uri": uris.from_fs_path("some_path"),744 "range": {745 "start": {"line": 1, "character": 2},746 "end": {"line": 1, "character": 2},747 },748 },749 {750 "uri": uris.from_fs_path("some_path"),751 "range": {752 "start": {"line": 3, "character": 4},753 "end": {"line": 3, "character": 4},754 },755 },756 ),757 )758 def test_ReferencesOfAnInvalidElement(self):759 path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")760 # Make sure there's no element at this location761 unit = self.server._getElementAtPosition(Path(path_to_foo), Location(0, 0))762 self.assertIsNone(unit)763 for exclude_declaration in (True, False):764 self.assertIsNone(765 self.server.references(766 doc_uri=uris.from_fs_path(path_to_foo),767 position={"line": 0, "character": 0},768 exclude_declaration=exclude_declaration,769 )770 )...

Full Screen

Full Screen

lsp.py

Source:lsp.py Github

copy

Full Screen

...285 text = self.workspace.get_document(doc_uri).source286 return self.checker.getMessagesWithText(path, text)287 def references(self, doc_uri, position, exclude_declaration):288 # type: (URI, Dict[str, int], bool) -> Any289 element = self._getElementAtPosition(290 Path(to_fs_path(doc_uri)),291 Location(line=position["line"], column=position["character"]),292 )293 # Element not identified294 if element is None:295 return None296 references = [] # type: List[Dict[str, Any]]297 if not exclude_declaration:298 for line, column in element.locations:299 references += [300 {301 "uri": from_fs_path(str(element.owner)),302 "range": {303 "start": {"line": line, "character": column},304 "end": {"line": line, "character": column},305 },306 }307 ]308 for reference in self.checker.database.getReferencesToDesignUnit(element):309 for line, column in reference.locations:310 references += [311 {312 "uri": from_fs_path(str(reference.owner)),313 "range": {314 "start": {"line": line, "character": column},315 "end": {"line": line, "character": column},316 },317 }318 ]319 return references320 def m_workspace__did_change_configuration(self, settings=None):321 # type: (...) -> Any322 self._onConfigUpdate(settings or {})323 @property324 def _use_markdown_for_hover(self):325 """326 Returns True if the client has reported 'markdown' as one of the327 supported formats, i.e., 'markdown' is present inside328 TextDocumentClientCapabilities.hover.contentFormat329 """330 return MarkupKind.Markdown.value in (331 self.config.capabilities.get("textDocument", {})332 .get("hover", {})333 .get("contentFormat", [])334 )335 def _format(self, text):336 """337 Double line breaks if workspace supports markdown338 """339 if self._use_markdown_for_hover:340 return text.replace("\n", "\n\n")341 return text342 def _getBuildSequenceForHover(self, path):343 # type: (Path) -> str344 """345 Return a formatted text with the build sequence for the given path346 """347 sequence = [] # type: List[Tuple[int, str, str]]348 # Adds the sequence of dependencies' paths349 for i, (seq_library, seq_path) in enumerate(350 self.checker.database.getBuildSequence(351 path, self.checker.builder.builtin_libraries352 ),353 1,354 ):355 sequence += [(i, str(seq_library), str(seq_path))]356 # Adds the original path357 sequence += [358 (359 len(sequence) + 1,360 str(self.checker.database.getLibrary(path) or DEFAULT_LIBRARY),361 str(path),362 )363 ]364 return "Build sequence for {} is\n\n{}".format(365 path,366 tabulate(367 sequence,368 tablefmt="github" if self._use_markdown_for_hover else "plain",369 headers=("#", "Library", "Path"),370 ),371 )372 def _getDependencyInfoForHover(self, dependency):373 # type: (BaseDependencySpec) -> Optional[str]374 """375 Report which source defines a given dependency when the user hovers376 over its name377 """378 # If that doesn't match, check for dependencies379 info = self.checker.resolveDependencyToPath(dependency)380 if info is not None:381 return self._format('Path "{}", library "{}"'.format(info[0], info[1]))382 return "Couldn't find a source defining '{}.{}'".format(383 dependency.library, dependency.name384 )385 def _getElementAtPosition(self, path, position):386 # type: (Path, Location) -> Union[BaseDependencySpec, tAnyDesignUnit, None]387 """388 Gets design units and dependencies (in this order) of path and checks389 if their definitions include position. Not every element is identified,390 only those pertinent to the core functionality, e.g. design units and391 dependencies.392 """393 for meth in (394 self.checker.database.getDesignUnitsByPath,395 self.checker.database.getDependenciesByPath,396 ): # type: Callable397 for element in meth(path):398 if element.includes(position):399 return element400 return None401 def hover(self, doc_uri, position):402 # type: (URI, Dict[str, int]) -> Any403 path = Path(to_fs_path(doc_uri))404 # Check if the element under the cursor matches something we know405 element = self._getElementAtPosition(406 path, Location(line=position["line"], column=position["character"])407 )408 _logger.debug("Getting info from %s", element)409 if isinstance(element, (VerilogDesignUnit, VhdlDesignUnit)):410 return {"contents": self._getBuildSequenceForHover(path)}411 if isinstance(element, BaseDependencySpec):412 return {"contents": self._getDependencyInfoForHover(element)}413 return None414 @logCalls415 def definitions(self, doc_uri, position):416 # type: (...) -> Any417 doc_path = Path(to_fs_path(doc_uri))418 dependency = self._getElementAtPosition(419 doc_path, Location(line=position["line"], column=position["character"])420 )421 if not isinstance(dependency, BaseDependencySpec):422 _logger.debug("Go to definition not supported for item %s", dependency)423 return []424 # Work out where this dependency refers to425 info = self.checker.resolveDependencyToPath(dependency)426 if info is None:427 _logger.debug("Unable to resolve %s to a path", dependency)428 return []429 _logger.info("Dependency %s resolved to %s", dependency, info)430 # Make the response431 target_path, _ = info432 target_uri = from_fs_path(str(target_path))...

Full Screen

Full Screen

_a11y.py

Source:_a11y.py Github

copy

Full Screen

...222 if err == kAXErrorIllegalArgument:223 raise ValueError('Accessibility timeout values must be non-negative')224 if err == kAXErrorInvalidUIElement:225 _setError(err, 'The element reference is invalid')226 def _getElementAtPosition(self, x, y):227 if self.ref is None:228 raise ErrorUnsupported('Operation not supported on null element references')229 err, res = AXUIElementCopyElementAtPosition(self.ref, x, y, None)230 if err == kAXErrorIllegalArgument:231 raise ValueError('Arguments must be two floats.')232 return self.with_ref(res)233 @classmethod234 def with_ref(cls, ref):235 """236 Create a new Python AXUIElement object from a given Apple AXUIElementRef237 :param ref:238 :return:239 """240 if isinstance(ref, cls):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful