Contenido principal

polyspace.project.CodeInfo Class

R2026b

Namespace: polyspace.project

(Python) Store information about types, functions, and globals in parsed source code

Since R2025a

Description

This Python® class contains information about data types, functions, and global variables in your source code. When authoring tests using the Polyspace® Test™ Python API, create an object of this class. Then use the information stored in this object to create test data, parameters, and steps.

Creation

Description

codeInfo = polyspace.project.parseCode(proj) parses the source code in the project proj and stores information about data types, functions, and global variables in the polyspace.project.CodeInfo object codeInfo. For extensions of this syntax, see polyspace.project.parseCode.

If an error occurs during code parsing, the function throws an exception of type polyspace.ErrorWithLog. (since R2026a)

example

Input Arguments

expand all

Polyspace Platform project, specified as a polyspace.project.Project object.

Properties

expand all

Since R2026a

Parse log information, returned as a polyspace.ExecutionLog object.

This polyspace.ExecutionLog object has the following property:

PropertyDescription
Content

Parse log content, specified as a single string.

To display the parse log string from a polyspace.project.CodeInfo object codeInfo in a human readable format, enter:

print(codeInfo.ParseLog.Content)

To save the run log content to a file, use the save() method. For instance, to save the error string from a polyspace.project.CodeInfo object codeInfo to a file logs.txt, enter:

codeInfo.ParseLog.save("logs.txt")

Note

This property contains the logs from a successful code parsing. If an error occurs during code parsing, the polyspace.project.parseCode() function throws an exception of type polyspace.ErrorWithLog. Catch this exception in an except block to see the error log content. For more information, see polyspace.ErrorWithLog.

Functions in the source code, returned as a list of polyspace.project.Function objects. Each object stores the function name, signature, and support information for stubbing, mocking, testing, and test generation.

Global variables in the source code, returned as a list of polyspace.project.Global objects. Each object stores the variable name and support information for stubbing.

Data types in the source code, specified as a list of polyspace.project.Type objects.

Examples

collapse all

Import the required modules, create a project, and add the source files.

## Import modules
import polyspace.project
import os

## Create project
examples_path = os.path.join(polyspace.__install_path__, "polyspace", 
                            "examples", "doc_pstest", "getting_started_test_manager")

proj = polyspace.project.Project("parseProject.psprjx")

## Add source files and include path
proj.Code.Files.add(os.path.join(examples_path, "algo.c"))
proj.Code.Files.add(os.path.join(examples_path, "saturate.c"))
proj.IncludePaths.add(os.path.join(examples_path))

Parse the code to get information about the source code in the project proj.

codeInfo = polyspace.project.parseCode(proj)

Identify undefined functions in the project. Use the StubbingSupport property of each polyspace.project.Function object to create a list of functions that require a stub.

undefinedFuncList = [f for f in codeInfo.Functions if f.StubbingSupport]

Identify undefined variables in the project. Use the StubbingSupport property of each polyspace.project.Global object to create a list of variables that require a stub.

undefinedVarList = [v for v in codeInfo.Globals if v.StubbingSupport]

Once you identify the undefined functions and variables, you can create stubs for them in one of these ways:

Methods

expand all

Version History

Introduced in R2025a

expand all