Best Python code snippet using pyatom_python
test_lsp.py
Source:test_lsp.py  
...571        path = Path(p.join(TEST_PROJECT, "another_library", "foo.vhd"))572        for _patch in patches:573            _patch.start()574        # Check locations outside return nothing575        self.assertIsNone(self.server.getElementAtPosition(path, Position(0, 0)))576        # Check design units are found, ensure boundaries match577        self.assertIsNone(self.server.getElementAtPosition(path, Position(1, 1)))578        self.assertIs(self.server.getElementAtPosition(path, Position(1, 2)), unit_a)579        self.assertIs(self.server.getElementAtPosition(path, Position(1, 7)), unit_a)580        self.assertIsNone(self.server.getElementAtPosition(path, Position(1, 8)))581        self.assertIsNone(self.server.getElementAtPosition(path, Position(3, 3)))582        self.assertIs(self.server.getElementAtPosition(path, Position(3, 4)), unit_a)583        self.assertIs(self.server.getElementAtPosition(path, Position(3, 9)), unit_a)584        self.assertIsNone(self.server.getElementAtPosition(path, Position(3, 10)))585        self.assertIsNone(self.server.getElementAtPosition(path, Position(5, 5)))586        self.assertIs(self.server.getElementAtPosition(path, Position(5, 6)), unit_b)587        self.assertIs(self.server.getElementAtPosition(path, Position(5, 11)), unit_b)588        self.assertIsNone(self.server.getElementAtPosition(path, Position(5, 12)))589        self.assertIsNone(self.server.getElementAtPosition(path, Position(7, 7)))590        self.assertIs(self.server.getElementAtPosition(path, Position(7, 8)), unit_b)591        self.assertIs(self.server.getElementAtPosition(path, Position(7, 13)), unit_b)592        self.assertIsNone(self.server.getElementAtPosition(path, Position(7, 14)))593        # Now check dependencies594        self.assertIsNone(self.server.getElementAtPosition(path, Position(9, 9)))595        self.assertIs(self.server.getElementAtPosition(path, Position(9, 10)), dep_a)596        self.assertIs(self.server.getElementAtPosition(path, Position(9, 20)), dep_a)597        self.assertIsNone(self.server.getElementAtPosition(path, Position(9, 21)))598        self.assertIsNone(self.server.getElementAtPosition(path, Position(11, 11)))599        self.assertIs(self.server.getElementAtPosition(path, Position(11, 12)), dep_a)600        self.assertIs(self.server.getElementAtPosition(path, Position(11, 22)), dep_a)601        self.assertIsNone(self.server.getElementAtPosition(path, Position(11, 23)))602        self.assertIsNone(self.server.getElementAtPosition(path, Position(13, 13)))603        self.assertIs(self.server.getElementAtPosition(path, Position(13, 14)), dep_b)604        self.assertIs(self.server.getElementAtPosition(path, Position(13, 24)), dep_b)605        self.assertIsNone(self.server.getElementAtPosition(path, Position(13, 25)))606        self.assertIsNone(self.server.getElementAtPosition(path, Position(15, 15)))607        self.assertIs(self.server.getElementAtPosition(path, Position(15, 16)), dep_b)608        self.assertIs(self.server.getElementAtPosition(path, Position(15, 26)), dep_b)609        self.assertIsNone(self.server.getElementAtPosition(path, Position(15, 27)))610        for _patch in patches:611            _patch.stop()612    @patch(613        "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",614        (Identifier("ieee"),),615    )616    def test_HoverOnInvalidRange(self):617        _logger.info("#" * 100)618        self.assertIsNone(619            self.client.lsp.send_request(620                features.HOVER,621                HoverParams(622                    TextDocumentIdentifier(623                        uris.from_fs_path(624                            p.join(TEST_PROJECT, "another_library", "foo.vhd")625                        )626                    ),627                    Position(line=0, character=0),628                ),629            ).result(LSP_REQUEST_TIMEOUT)630        )631    @patch(632        "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",633        (Identifier("ieee"),),634    )635    def test_HoverOnDesignUnit(self):636        _logger.info("#" * 100)637        path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")638        very_common_pkg = p.join(TEST_PROJECT, "basic_library", "very_common_pkg.vhd")639        package_with_constants = p.join(640            TEST_PROJECT, "basic_library", "package_with_constants.vhd"641        )642        clock_divider = p.join(TEST_PROJECT, "basic_library", "clock_divider.vhd")643        expected = [644            "Build sequence for %s is" % str(path_to_foo),645            "",646            tabulate(647                [648                    (1, "basic_library", str(very_common_pkg)),649                    (2, "basic_library", str(package_with_constants)),650                    (3, "basic_library", str(clock_divider)),651                    (4, DEFAULT_LIBRARY.name, str(path_to_foo)),652                ],653                headers=("#", "Library", "Path"),654                tablefmt="plain",655            ),656        ]657        self.assertEqual(658            self.client.lsp.send_request(659                features.HOVER,660                HoverParams(661                    TextDocumentIdentifier(uris.from_fs_path(path_to_foo)),662                    Position(line=7, character=7),663                ),664            )665            .result(LSP_REQUEST_TIMEOUT)666            .contents,667            "\n".join(expected),668        )669    @patch(670        "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",671        (Identifier("ieee"),),672    )673    def test_HoverOnDependency(self):674        _logger.info("#" * 100)675        path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")676        clock_divider = p.join(TEST_PROJECT, "basic_library", "clock_divider.vhd")677        self.assertEqual(678            self.client.lsp.send_request(679                features.HOVER,680                HoverParams(681                    TextDocumentIdentifier(uris.from_fs_path(path_to_foo)),682                    Position(line=32, character=32),683                ),684            )685            .result(LSP_REQUEST_TIMEOUT)686            .contents,687            'Path "%s", library "basic_library"' % clock_divider,688        )689    @patch(690        "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",691        (Identifier("ieee"),),692    )  # pylint: disable=invalid-name693    def test_GetDefinitionMatchingDependency(self):694        _logger.info("#" * 100)695        source = p.join(TEST_PROJECT, "basic_library", "use_entity_a_and_b.vhd")696        target = p.join(TEST_PROJECT, "basic_library", "two_entities_one_file.vhd")697        definitions = {698            (699                x.uri,700                x.range.start.line,701                x.range.start.character,702                x.range.end.line,703                x.range.end.character,704            )705            for x in self.client.lsp.send_request(706                features.DEFINITION,707                TextDocumentPositionParams(708                    TextDocumentIdentifier(uris.from_fs_path(source)), Position(1, 9),709                ),710            ).result(LSP_REQUEST_TIMEOUT)711        }712        self.assertIn(713            (uris.from_fs_path(target), 1, 7, 1, 15), definitions,714        )715        self.assertIn(716            (uris.from_fs_path(target), 4, 7, 4, 15), definitions,717        )718    @patch(719        "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",720        (Identifier("ieee"),),721    )  # pylint: disable=invalid-name722    def test_GetDefinitionBuiltInLibrary(self) -> None:723        _logger.info("#" * 100)724        path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")725        self.assertFalse(726            self.server.definitions(727                TextDocumentPositionParams(728                    TextDocumentIdentifier(uris.from_fs_path(path_to_foo)),729                    Position(3, 15),730                )731            )732        )733    @patch(734        "hdl_checker.builders.base_builder.BaseBuilder.builtin_libraries",735        (Identifier("ieee"),),736    )737    def test_GetDefinitionNotKnown(self) -> None:738        _logger.info("#" * 100)739        path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")740        self.assertFalse(741            self.server.definitions(742                TextDocumentPositionParams(743                    TextDocumentIdentifier(uris.from_fs_path(path_to_foo)),744                    Position(0, 0),745                )746            )747        )748    @patch.object(749        hdl_checker.database.Database,750        "getReferencesToDesignUnit",751        return_value=[752            RequiredDesignUnit(753                name=Identifier("clock_divider"),754                library=Identifier("basic_library"),755                owner=Path("some_path"),756                locations=(Location(1, 2), Location(3, 4)),757            )758        ],759    )760    def test_ReferencesOfAValidElement(self, get_references) -> Any:761        _logger.info("#" * 100)762        # We'll pass the path to foo.vhd but we're patching the763        # getReferencesToDesignUnit to return "some_path"764        path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")765        # Make sure we picked up an existing element766        unit = self.server.getElementAtPosition(Path(path_to_foo), Position(7, 7))767        self.assertIsNotNone(unit)768        references = [769            (770                x.uri,771                x.range.start.line,772                x.range.start.character,773                x.range.end.line,774                x.range.end.character,775            )776            for x in self.client.lsp.send_request(777                features.REFERENCES,778                ReferenceParams(779                    TextDocumentIdentifier(uris.from_fs_path(path_to_foo)),780                    Position(7, 7),781                    ReferenceContext(include_declaration=False),782                ),783            ).result(LSP_REQUEST_TIMEOUT)784        ]785        self.assertCountEqual(786            references,787            {788                (uris.from_fs_path("some_path"), 1, 2, 1, 3),789                (uris.from_fs_path("some_path"), 3, 4, 3, 5),790            },791        )792        get_references.assert_called_once()793        get_references.reset_mock()794        references = [795            (796                x.uri,797                x.range.start.line,798                x.range.start.character,799                x.range.end.line,800                x.range.end.character,801            )802            for x in self.client.lsp.send_request(803                features.REFERENCES,804                ReferenceParams(805                    TextDocumentIdentifier(uris.from_fs_path(path_to_foo)),806                    Position(7, 7),807                    ReferenceContext(include_declaration=True),808                ),809            ).result(LSP_REQUEST_TIMEOUT)810        ]811        self.assertCountEqual(812            references,813            {814                (uris.from_fs_path(path_to_foo), 7, 7, 7, 8),815                (uris.from_fs_path("some_path"), 1, 2, 1, 3),816                (uris.from_fs_path("some_path"), 3, 4, 3, 5),817            },818        )819    def test_ReferencesOfAnInvalidElement(self):  # pylint: disable=invalid-name820        _logger.info("#" * 100)821        path_to_foo = p.join(TEST_PROJECT, "another_library", "foo.vhd")822        # Make sure there's no element at this location823        unit = self.server.getElementAtPosition(Path(path_to_foo), Position(0, 0))824        self.assertIsNone(unit)825        for include_declaration in (False, True):826            self.assertIsNone(827                self.server.references(828                    ReferenceParams(829                        TextDocumentIdentifier(uris.from_fs_path(path_to_foo)),830                        Position(0, 0),831                        ReferenceContext(include_declaration=include_declaration),832                    )833                )834            )835    def test_changeConfiguration(self):836        _logger.info("#" * 100)837        # pylint: disable=no-member...Diagram.py
Source:Diagram.py  
1from base import IBase2from lib.Addons.Plugin.Communication.ComSpec import *3from lib.Addons.Plugin.Interface.decorators import *4from lib.Commands.Diagrams import CCreateElementCommand5from lib.Drawing.Connection import CConnection6from lib.Drawing.Diagram import CDiagram7from lib.Drawing.Element import CElement8from lib.Elements.Object import CElementObject9from lib.Connections.Object import CConnectionObject10from lib.Addons.Plugin.Interface.Classes.DomainObject import IDomainObject11from lib.Drawing import CConLabelInfo12from lib.Project.ProjectNode import CProjectNode13class IDiagram(IDomainObject):14    __cls__ = CDiagram15    16    def GetElement(him, obj):17        return him.HasElementObject(obj)18    19    def GetConnection(him, obj):20        return him.GetConnection(obj)21    22    def GetSelected(him):23        return list(IBase.GetAdapter().application.GetOpenedDrawingAreas().GetDrawingArea(him).GetSelection().GetSelected())24    def GetSelectedElements(him):25        return list(IBase.GetAdapter().application.GetOpenedDrawingAreas().GetDrawingArea(him).GetSelection().GetSelectedElements(True))26    def GetSelectedConnectionLabels(him):27        selElements = IBase.GetAdapter().application.GetOpenedDrawingAreas().GetDrawingArea(him).GetSelection().GetSelectedElements(False)28        return [item for item in selElements if isinstance(item, CConLabelInfo)]29    30    def GetSelectedConnections(him): 31        return list(IBase.GetAdapter().application.GetOpenedDrawingAreas().GetDrawingArea(him).GetSelection().GetSelectedConnections())32        33    def GetSelectSquare(him):34        selection = IBase.GetAdapter().application.GetOpenedDrawingAreas().GetDrawingArea(him).GetSelection()35        return him.GetSelectSquare(selection)36    37    def GetElementAtPosition(him, pos): 38        return him.GetElementAtPosition(pos)39    40    def GetElementsInRange(him, topLeft, bottomRight, includeAll = True):41        return list(him.GetElementsInRange(topLeft, bottomRight, includeAll))42    43    def GetSizeSquare(him):44        return him.GetSizeSquare()45    46    def GetElements(him):47        return list(him.GetElements())48        49    def GetConnections(him):50        return list(him.GetConnections())51    52    def GetName(him):53        return him.GetName()54    55    @destructive56    def CreateElement(him, command, elementType):57        cmd = CCreateElementCommand(elementType, him, IBase.GetAdapter().application.GetOpenedDrawingAreas())58        command.Execute(cmd)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
