Main Content

polyspace.project.ScriptedTestStep Class

Namespace: polyspace.project

(Python) Create and manage scripted test steps

Since R2025a

Description

This Python® class contains information about a scripted test step that you author using the Polyspace® Test™ Python API. This class includes:

  • The body of the step that contains the code this step executes

  • Inputs supplied to the step body

  • Step observables

  • Assessments against which the success of the test is evaluated

Note

You can only assign strings to the Value property of an input, assessment, or observable. Therefore, put quotes around the values you want to assign. For example:

  • To specify the integer 42, assign the string "42" to the Value property.

  • To specify the double 3.14, assign the string "3.14" to the Value property.

  • To specify the string "My String", assign the string ""My String"" to the Value property.

  • To specify the address of a variable var, assign the string "&var" to the Value property.

When generating code for your tests, Polyspace Test uses the content of the string to reconstruct the value of the input, assessment, or observable.

Creation

Description

scriptedStep = testCase.TestSteps.createScripted(stepName) creates a scripted test step with name stepName in a polyspace.project.TestCase or polyspace.project.OwnedTestCase object testCase.

scriptedStep = testCase.TestSteps.createFrom(existingScriptedStep, stepName) creates a scripted test step with name newName by copying an existing scripted test step existingScriptedStep.

Input Arguments

expand all

Existing scripted test step to copy, specified as a polyspace.project.ScriptedTestStep object. The existing step can be from any test case.

Name of test step specified as a string. This name is assigned to the Name property of the newly created step.

Properties

expand all

Name of the test step, specified as a string. You specify this name when you create the scripted test step using either the createScripted or createFrom method.

Description associated with the test step, specified as a string.

Whether this step is executed or not when you run your project, specified as either True or False. The default value is True.

List of inputs associated with the test step, specified as a polyspace.project.StepInputList object. Each individual input contained in this list is a polyspace.project.StepInput object that contains these properties:

  • Name — Name of the input variable in your source code, specified as a string. This property is read-only.

  • Scope — Scope of the input variable such as "local", specified as a string. This property is read-only.

  • Type — Data type of the input, specified as a string. This property is read-only.

  • Value — Value of the input for this test step, specified as a string, polyspace.project.TestData object, or polyspace.project.TestParameter object. By default, the input values are initialized to "0".

This table summarizes the various ways you can access or modify a test inputs list object scriptedStep.Inputs, where scriptedStep is a polyspace.project.ScriptedTestStep object.

ActionCommand
Access individual inputs
  • Index using numeric location. For example, scriptedStep.Inputs[2].

  • Index using the name of the input variable varName. For example, scriptedStep.Inputs["varName"].

Assign value to an input

Assign a string, polyspace.project.TestData object, or polyspace.project.TestParameter object to the Value property. For example,

scriptedStep.Inputs[0].Value = "23"
scriptedStep.Inputs[1].Value = testData
scriptedStep.Inputs[2].Value = testParam
Add new input for a primitive type

Suppose that codeInfo is the polyspace.project.CodeInfo object that you obtain after parsing your source code. Also assume that your step body contains a variable myInput of int type that you want to specify as an input. Run this command:

dataType = codeInfo.getType("int")
scriptedStep.Inputs.create("myInput",dataType)

Delete an input
  • Remove an input by name:

    scriptedStep.Inputs.pop("myInput")
  • Remove the input at index 0:

    scriptedStep.Inputs.pop(0)
  • Remove the last input in the list:

    scriptedStep.Inputs.pop()
Delete all inputs

scriptedStep.Inputs.clear()

The code that the scripted test step executes, specified as a string. The following code snippet is an example of a step body specification.

# Step body that invokes saturate_and_cache multiple times.
scriptedStep.Body = r"""
out1 = saturate_and_cache(in);
out2 = saturate_and_cache(in+3);
out3 = saturate_and_cache(in+5);
"""

List of observables associated with the test step, specified as a polyspace.project.StepObservableList object. Each individual observable contained in this list is a polyspace.project.StepObservable object that contains these properties:

  • Name — Name of the observable variable in the step body, specified as a string. This property is read-only.

  • Type — Data type of the observable variable, specified as a string. This property is read-only.

This table summarizes the various ways you can access or modify an observable list object scriptedStep.Observables, where scriptedStep is a polyspace.project.ScriptedTestStep object.

ActionCommand
Access individual observables
  • Index using numeric location. For example, scriptedStep.Observables[2].

  • Index using the name of the observable variable varName. For example, scriptedStep.Observables["varName"].

Add new observable for a primitive type

Suppose that codeInfo is the polyspace.project.CodeInfo object that you obtain after parsing your source code. Also assume that your step body contains a variable myObservable of int type that you want to specify as an observable. Run this command:

dataType = codeInfo.getType("int")
scriptedStep.Observables.create("myObservable",dataType)

When you create a new observable, an assessment is automatically created for that observable. For example, to assign a value to the assessment that is automatically created for myObservable, run a command like this:

scriptedStep.Assessments["myObservable"].Value = "2"

Delete an observable
  • Delete an observable by name:

    scriptedStep.Observables.pop("myObservable")
  • Delete the observable at index 0:

    scriptedStep.Observables.pop(0)
  • Delete the last observable in the list:

    scriptedStep.Observables.pop()
Delete all observables
scriptedStep.Inputs.clear()

List of assessments associated with the test step, specified as a polyspace.project.StepAssessmentList object. Each individual assessment contained in this list is a polyspace.project.StepAssessment object that has these properties:

  • Comparator — Comparator for the assessment, specified as a polyspace.project.AssessmentComparator enum class object. The enum values are EQUAL, GREATER, GREATER_EQUAL, LESS, LESS_EQUAL, NONE, and NOT_EQUAL.

  • Enabled — Option to use this assessment to determine if the test passes, specified as True or False.

  • Name — Name of the assessment variable, specified as a string. This property is read-only.

  • Scope — Scope of the assessment variable such as "local" or "fcn_call", specified as a string. This property is read-only.

  • Tolerance — Tolerance of the assessment, specified as a string. This property is read-only.

  • Type — Data type of the assessment variable, or "call count" for function call count assessments, specified as a string. This property is read-only.

  • Value — Value of the assessment, specified as a string or a polyspace.project.TestData object. By default, the assessment values are initialized to "0", or "0u" for function call count assessments.

This table summarizes the various ways you can access or modify a test inputs list object scriptedStep.Inputs, where scriptedStep is a polyspace.project.ScriptedTestStep object.

ActionCommand
Access individual assessments
  • Index using numeric location. For example, scriptedStep.Assessments[2].

  • Index using the name of the assessment variable varName. For example, scriptedStep.Assessments["varName"].

  • Index using the name of an observable you add to a scripted step. For example, scriptedStep.Assessments["myObservable"].

Assign value to an assessment

Assign a string or a polyspace.project.TestData object to the Value property:

scriptedStep.Assessments[0].Value = "23"
scriptedStep.Inputs[1].Value = testData
Add new assessment
  • Create an assessment from an input:

    scriptedStep.Assessments.create(scriptedStep.Inputs[0])

  • Create an assessment from an observable:

    scriptedStep.Assessments.create(scriptedStep.Observables[0])

Add new function call count assessment

Create a function call count assessment and verify that a function is called at least once:

functionGetMinValue = codeInfo.getFunctionBySignature("int getMinValue(void)")
scriptedStep.Assessments.create(functionGetMinValue)
Modify the assessment so that it verifies that the function is called exactly once by updating the Comparator and Value properties:
scriptedStep.Assessments["getMinValue()"].Comparator = "EQUAL"
scriptedStep.Assessments["getMinValue()"].Value = "1u"

To add a function call count assessment for a function, the function must be supported for mocking. For more information see Limitations in polyspace.project.Mock.

Delete assessment

  • Remove an assessment by name:

    scriptedStep.Assessments.pop("myAssessment")
  • Remove the assessment at index 0:

    scriptedStep.Assessments.pop(0)
  • Remove the last assessment in the list:

    scriptedStep.Assessments.pop()

Delete all assessments

Use the clear method to delete all assessments:

scriptedStep.Assessments.clear()

Mocks applied to the step specified as a polyspace.project.ActiveMockSet object. Use the following methods to populate the set:

  • To apply a mock described by a polyspace.project.Mock object mock, use the add() method:

    scriptedStep.ActiveMocks.add(mock)
    For more information, see polyspace.project.Mock.

  • To remove a polyspace.project.Mock object mock from the step, use the remove() method:

    scriptedStep.ActiveMocks.remove(mock)

  • To remove all mocks, use the clear() method:

    scriptedStep.ActiveMocks.clear()

Version History

Introduced in R2025a