GlobalConstantsDefinition

class GlobalConstantsDefinition

Returned by

AppendConstant(name, value=None, description=None)

Appends a new global constant. If a constant with the same name already exists, it will be overwritten.

Parameters:
name : str

Name of the constant

value : string

Value expression for the constant. (for strings you need to include quotes!) Can be left empty to create new constant without value.

description : str

Description of the constant

Raises:

ApiError – If constant with the given name and value could not be appended, e.g. if the name is no valid identifier, or the value can not be parsed.

Clone()

Call this method if you want to use API-objects in multiple contexts, e.g. if you want to insert a specific test step in multiple blocks.

Returns:

A copy of this object

Return type:

GlobalConstantsDefinition

GetAllConstantNames()

Returns a list of all global constant names.

Returns:

List of all global constant names

Return type:

list[str]

GetDescription(name)

Returns the description of the constant specified by the given name.

Parameters:
name : str

Name of the constant

Returns:

Description text

Return type:

str

GetFilename()

Returns the file name of the global constants definition file, if this is a file. Returns None if this is part of the test configuration, a parameter set or an unsaved file.

Returns:

The file name of the saved file or None, if not a file

Return type:

str

GetValue(name)

Returns the string representation of the value expression of the constant, specified by the given name.

Parameters:
name : str

Name of the constant

Returns:

Expression for the constant value

Return type:

str

Raises:

ApiError – If the constant with the given name does not exist

RemoveConstant(name)

Removes the global constant specified by the given name.

Parameters:
name : str

Name of the constant

Returns:

True if successful. False if no constant with such name exists.

Return type:

boolean

Save(filename='', allowCompatibilityFallback=False)

Saves the global constants definition to a file. Appends file ending if needed.

Parameters:
filename : str

File name for the global constants definition file (*.gcd); Either absolute or relative to the ‘Parameter’ directory. If left out, use the existing file name and path (previously set with Save() or from ParameterApi.OpenGlobalConstantsDefinition())

allowCompatibilityFallback : bool

If True and a compatibility mode is active, save in the minimum compatible version when needed. If False, compatibility problems raise an exception instead.

SetDescription(name, description)

Sets the description of the constant specified by the given name.

Parameters:
name : str

Name of the constant

description : str

Description text

Raises:
  • ApiError – If the constant with the given name does not exist

  • ApiError – If description is no str

SetValue(name, value)

Sets the value expression of the constant specified by the given name.

Parameters:
name : str

Name of the constant

value : str

Value expression for the constant value (for strings you need to include quotes!) Can be set to ‘None’ to reset the constant’s value.

Raises:
  • ApiError – If the constant with the given name does not exist

  • ApiError – If the value is no valid expression