Main Content

polyspace.project.OwnedTestCase Class

Namespace: polyspace.project

(Python) Create and manage owned test cases saved in project

Since R2026a

Description

This Python® class contains information about a graphical test case that is part of a specific Polyspace® Platform project and can only be accessed via the corresponding project object. Owned test cases are saved in the .psprjx project file and are not accessible from other projects. You can author this test case by using the Polyspace Python API or the Polyspace Platform user interface.

To create modular projects, where project components like configurations and graphical tests are saved in separate files, consider using test references. A test reference is a graphical test case that is saved in a separate .pstestd file that is referenced by the project. To work with test references in the Polyspace Python API see polyspace.project.TestCaseRef and polyspace.project.TestCase. For more information about project structure, see Modularize Project by Using External Configurations, Test References, and External Stub Files.

Creation

Description

Create Test Case

testCase = testSuite.TestCases.create(testName) creates an empty polyspace.project.OwnedTestCase object testCase in the test suite testSuite of a project. The Name property of the resulting polyspace.project.OwnedTestCase object is testName. For more information on the polyspace.project.TestSuite object and its methods, see the description of the TestSuites property of the polyspace.project.Project class.

Load Test Case

testCase = testSuite.TestCases[testName] loads the existing polyspace.project.OwnedTestCase object with Name property set to testName from the test suite testSuite of a project.

Create Copy of Test Case

testCase = testSuite.TestCases.createFrom(ownedTestCaseObj, testName) creates a new polyspace.project.OwnedTestCase object testCase in the test suite testSuite by copying an existing polyspace.project.OwnedTestCase object. Use the testName argument to set the Name property of the resulting polyspace.project.OwnedTestCase object.

testCase = testSuite.TestCases.createFrom(existingTestFile) creates a new polyspace.project.OwnedTestCase object testCase in the test suite testSuite by copying the test case from existingTestFile.pstestd.

testCase = testSuite.TestCases.createFrom(existingTestFile, testName) creates a new polyspace.project.OwnedTestCase object testCase in the test suite testSuite by copying the test case from existingTestFile.pstestd. Use the testName argument to set the Name property of the resulting polyspace.project.OwnedTestCase object.

Convert Test Case

testCase = testSuite.TestCases.moveAsOwned(existingTestCaseRefObj) converts the test case referenced by existingTestCaseRefObj in testSuite to a polyspace.project.OwnedTestCase object in the same test suite. The conversion removes the existingTestCaseRefObj from the test suite.

Input Arguments

expand all

Name of test case, specified as a string. This argument sets the Name property of the polyspace.project.OwnedTestCase object.

Existing test case to copy, specified as a polyspace.project.OwnedTestCase object.

Existing test case file to copy the graphical test from, specified as a full or relative path to the .pstestd file. All relative paths are considered relative to the location of the .psprjx project file.

Example: "myTestCaseFile.pstestd"

Example: r"L:\projects\test_refs\myTest.pstestd"

Existing polyspace.project.TestCaseRef object to convert to a polyspace.project.OwnedTestCase object within the same test suite.

Properties

expand all

Name of the test case, specified as a string.

Description of the test case, specified as a string.

Code to run as the preamble for the test case, specified as a string. This code runs before the actual setup phase.

Code to run during the setup phase of the test case, specified as a string. This code sets up the test environment.

Code to run during the teardown phase of the test case, specified as a string. This code performs cleanup actions such as deallocating resources after the test has been executed.

List of test data associated with the test case, specified as a polyspace.project.TestDataList object. Each individual test data contained in this list is an instance of the polyspace.project.TestData class that contains these properties:

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

  • Type — Type of the test data, specified as a string. This property is read-only.

  • Value — Value of the test data, specified as a string. By default, the test data values are initialized to "0".

    Note

    You can only assign strings to the Value property of a test data object. Therefore, put quotes around the values you 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 test data or parameter.

This table summarizes the various ways you can modify a test data list object testCase.TestData, where testCase is a polyspace.project.OwnedTestCase object or a polyspace.project.TestCase object.

ActionCommand
Add new test data

testData = testCase.TestData.create("myTestData",dataType) adds a test data object whose Name property is set to "myTestData". Here, dataType is a polyspace.project.Type object.

The testData object contains values of type dataType that are initialized to "0". To update these values, set the Value property of testData.

For example, to create a test data array of dimension 4 that contains the integers -1, 1, 3, and 5, run these commands. Here codeInfo is the polyspace.project.CodeInfo object that you obtain after parsing source code that contains the int data type.

at = codeInfo.getType("int[4]")
myData = testCase.TestData.create("myTestData",at)
for k, v in enumerate([-1, 1, 3, 5]):
    myData[k].Value = str(v)

To access members of an aggregate such as a structure or union, use the member name as index. For instance, suppose that you define a structure type Number as follows:

typedef struct Number {
    int intValue;
    double dblValue;
} Number;
You can access the member intValue of a test data of this type as follows:
type = codeInfo.getType("Number")
data = testCase.TestData.create("my_data", type)
data["intValue"].Value = "1"

Delete test data
  • proj.TestData.pop("myTestData") removes the test data object with name "myTestData" from the list.

  • proj.TestData.pop(0) removes the test data object at index 0 from the list.

  • proj.TestData.pop() removes the last test data object in the list.

Delete all test data

proj.TestData.clear() removes all test data from the list.

List of test parameters, iteration strategy, and whether to load parameters at run time, specified as a polyspace.project.TestParameters object. This object has these properties:

  • Parameters — List of test parameters, specified as a polyspace.project.TestParameterList object. Each individual test parameter contained in this list is an instance of the polyspace.project.TestParameter class that has these properties:

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

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

    • Value — Values of the test parameter elements, specified as strings. By default, the test parameter element values are initialized to "0".

      Note

      You can only assign strings to the Value property of a test parameters object. Therefore, put quotes around the values you 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 test data or parameter.

    This table summarizes the various ways you can modify a test parameter list object params.Parameters, where params is a polyspace.project.TestParameters object.

    ActionCommand
    Add new test parameter

    testParam = params.Parameters.create("myTestParam",dataType) adds a test parameter object whose Name property is set to "myTestParam". Here, dataType is a polyspace.project.Type object.

    The testParam object contains values of type dataType that are initialized to "0". To update these values, set the Value property of the elements of testParam.

    For example, to create a test data array of dimension 4 that contains all integers from -50 through 50, run these commands. Here codeInfo is the polyspace.project.CodeInfo object that you obtain after parsing source code that contains the int data type.

    testParam = params.Parameters.create("myParam", codeInfo.getType("int[101]"))
    for k in range(101):
     testParam[k].Value = str(k-50)

    To access members of an aggregate such as a structure or union, use the member name as index. For instance, suppose that you define a structure type Number as follows:

    typedef struct Number {
        int intValue;
        double dblValue;
    } Number;
    You can access the member intValue of a two-value test parameter of this type as follows:
    type = codeInfo.getType("Number[2]")
    testParam = params.Parameter.create("my_param", type)
    testParam[0]["intValue"].Value = "1"
    testParam[1]["intValue"].Value = "2"

    Delete a test parameter
    • params.Parameters.pop("myTestParam") removes the test parameter with name "myTestParam" from the list.

    • params.Parameters.pop(0) removes the test parameter at index 0 from the list.

    • params.Parameters.pop() removes the last test parameter in the list.

    Delete all test parameters

    params.Parameters.clear() removes all test parameters from the list.

  • Iteration — Parameter iteration strategy, specified as a polyspace.project.ParameterIterationMode enum class object. The enum values are EXHAUSTIVE and SEQUENTIAL.

  • LoadAtRunTime — Whether to load the parameter values at run time instead of embedding them in the generate code, specified as a boolean.

For more information on the Iteration and LoadAtRunTime properties, see Decide Parameterization Strategy.

List of tabular and scripted test steps associated with the test case, specified as a polyspace.project.TestStepList object. Each individual test step contained in this list is an instance of either the polyspace.project.TabularTestStep class or the polyspace.project.ScriptedTestStep class.

This table summarizes the various ways you can modify a test steps list object testCase.TestSteps, where testCase is a polyspace.project.OwnedTestCase or polyspace.project.TestCase object.

ActionCommand
Add a new tabular test step

tabularStep = testCase.TestSteps.createTabular("myTabularStep",functionToTest) adds a tabular test step whose Name property is set to "myTabularStep". This step exercises the function referenced by the polyspace.project.Function object functionToTest.

For example, to add a tabular test step for a function with signature int saturate_value(int) in your source code, run the following commands. Here codeInfo is the polyspace.project.CodeInfo object that you obtain after parsing your source code.

func = codeInfo.getFunctionBySignature("int saturate_value(int)")
step = testCase.TestSteps.createTabular("myStep", func)
Add a new scripted test step

scriptedStep = testCase.TestSteps.createScripted("myScriptedStep") adds a scripted test step whose Name property is set to "myScriptedStep".

Add copy of an existing test step

testStep = testCase.TestSteps.createFrom(existingTestStep,newName)

Here existingTestStep is an existing polyspace.project.TabularTestStep or polyspace.project.ScriptedTestStep object and newName is the name you associate with the copied test step.

Delete a test step
  • testCase.TestSteps.pop("myTestStep") removes the test step with name "myTestStep" from the list.

  • testCase.TestSteps.pop(idx) removes the test step at index idx from the list.

  • testCase.TestSteps.pop() removes the last test step in the list.

Delete all test steps

testCase.TestSteps.clear() removes all test steps from the list.

Methods

expand all

Version History

Introduced in R2026a

expand all