Tools

Go to Definition

If the cursor is placed on the name of a Python function in the editor press F12 to see the definition of the function. If the function is a .NET function a stub file, recognisable by the .pyi extension, is displayed.

A stub file contains the interface definition and documentation of the public (public) .NET members that can be accessed within the Python script.
Stub-Datei
Figure 1. Example of the stub file of the ScpiPowerSupplyModule
  1. Assembly information and creation date of the stub file

  2. Using the example of the class ScpiPowerSupplyModule, its members are illustrated:

    1. Constructors

    2. Properties

    3. Methods

  3. A member marked as favorite is listed at the top in autocomplete

You can jump back to the previous position using arrow left or the keyboard shortcut Ctrl+-.

Error List

Errors, warnings and information messages related to the Python script are displayed in the Error List. Open the Python script module View  Error List in the menu. By double-clicking on an error, you can jump directly to the corresponding line in the Python file.

scriptErrorlist en
Figure 2. Error List window in the table bar

ToDo List

You can enter tasks in the Python script via comments which have to begin with a keyword for the respective task.
You find a list of keywords in main menu at Tools  Options  Script  ToDo List.

settingsScriptToDoList en
Figure 3. ToDo List in the script options

Open the ToDo List of the Python script module View  ToDo list in the menu.

toDoList en
Figure 4. ToDo List window in the tab bar

Output

The Output window displays debug information and the print commands from the Python script.
Open the Python script module View  Output in the menu.

scriptOutput en
Figure 5. Output window in the tab bar

Call Stack

Open View  Call Stack in the menu of the Python script module .

scriptCallStack en
Figure 6. Call Stack window in the tab bar

The Call Stack is a mechanism with which an interpreter (in this case the Python interpreter) can track its position in a script that calls several functions. The Call Stack contains information about the function and its original file that is currently being executed and the sub-functions that are called from the calling function.

The Call Stack is only active in debug mode bug.

Code formatting

To format the Python code of a file automatically select codeFormatTool or the keyboard shortcut Ctrl+Shift+F.

Example 1. Code formatting
Before formatting
def Func(x,y,   z =12)  :
    return x    *Y*z#return
After formatting
def Func(x, y, z=12):
    return x * Y * z  #return

The formatting tool can be configured with the pyproject.toml file, see YAPF documentation.

Example 2. pyproject.toml
[tool.yapf]
based_on_style = 'pep8' (1)
column_limit = 240 (2)
1 Use the style PEP 8
2 Lines should not exceed 240 characters

Git integration

If the versioning management software Git is installed, the following tools are available:

  • git opens the Git-GUI, or Git Extensions if it is installed

  • source commit displays the current branch and opens the Git GUI or the commit dialogue of Git Extensions

Unit tests

LisRT supports Unit testing with the help of Python - Unit Testing Framework. Click on the testsTool tool to open the Tests window.

tabTestsInitial en
Figure 7. Tests window on the right in the tab bar
  • testsRefresh Searching for unit tests

  • testsRun Executes all unit tests

  • testsRunSelected Executes the selected unit tests

  • testsStop Cancels the test run

  • testsFilter Filter for all, passed and failed tests

Example 3. Unit test

In this example, the Python method get_image_name(type_name) from the Python file visual.inspection.py is tested.

import unittest
from visual_inspection import *

class TestVisualInspection(unittest.TestCase): (1)

    def test_get_image_name(self): (2)
        type_name = 'test.png'
        self.assertEqual('image_test.png', get_image_name(type_name)) (3)
1 The name of a test case must begin with test
2 The name of a test must begin with test
3 The test ends with an assert function
tabTestsWithExample en
Figure 8. Unit test example