Package Generator API

PackageGenerator

class PackageGenerator

This is the base class for user defined package generators. All package generators should be derived form this class. It defines specific methods that are called during generation of packages. The required behaviour of a package generator is implemented by overwriting these methods.

Some fields and methods must be overridden (mandatory), others may be overridden (optional). There are also methods that are only to be called by the user implementation and should not be overridden (those without a note).

DESCRIPTION = ''

A short description of the package generator.

Type:

str

FORMAT_REV = 0

The format revision identifies structure and type of the generator data that is saved in project files. Do not return any other value than 0 if you do not also provide for conversion of outdated versions into the current one. It is recommended keeping changes in your generation data structure compatible with former versions and always keep 0 for the format revision.

ID = ''

A universally unique identifier to make the package generator unique. The ID should be generated automatically to be unique.

Type:

str

Info

Setting this field is mandatory

NAME = ''

The display name of the package generator.

Type:

str

Info

Setting this field is mandatory

SERIALIZE : dict[str, tuple[str, str] | tuple[str, str, object]] = {}

Declaration of instance variables of the package generator, that are to be exported/imported to/from xml format (e.g. during saving/loading a project). The declaration contains an item for each instance variable in form of an dictionary. Example:

SERIALIZE = {
                "foo": ("FOO-VAR", "integer", 23),
                "bar": ("BAR", "string"),
                "params: ("PARAMETERS", "list")
            }

The declaration items key must match the name of the corresponding instance variable (e.g. for an instance variable self.foo the item’s key must be “foo”). The item’s value must be a tuple containing at least 2 elements. So the general syntax for a declaration item is:

``<variable name>: (<variable alias>, <type alias>, [default value])``

Syntax and meaning of the tuple’s elements are:

  • <variable alias> declares the name of the xml element that is used for the variable’s xml representation.

  • <type alias> keyword specifing the python variable’s type. The following table gives all keywords and their corresponding python type respectively:

    • boolean: bool

    • integer: int

    • long: int

    • float: float

    • string: str

    • unicode: str

    • list: list

    • dict: dict

PLEASE NOTE: Keys of dictionaries being (de-)serialized must be strings. Furthermore values of dictionaries and lists are required to be of type bool, int, float, str, list or dict. The same restrictions apply to embedded lists and dictionaries. The types long and unicode are only kept for compatibility. Do not use these in new code.

  • <default value> is an optional element. It specifies the variable’s default value. If the variable’s value equals its default value during export the variable is not exported at all. Conversely, the variable is assigned its default value during import if the xml data does not provide an value for the variable.

Type:

dict

api = None

Access to the internal ecu.test API. The API will be assigned at runtime, in order to be independent from ecu.test for testing purposes.

See also

Internal APIs

projectPath = None

Absolute path to the project file containing the generator. In case of direct execution, this is the source project. In case of static generation it is the destination project.

classmethod GetDescription()

Returns the description of the package generator. The description can be specified by setting the class variable DESCRIPTION.

Return type:

str

classmethod GetFormatRev()

Returns the format revision of the package generator. The format revision can be specified by setting the class variable FORMAT_REV. This is an optional parameter.

Return type:

int

classmethod GetId()

Returns the universally unique identifier of the package generator. The identifier should be specified by setting the class variable ID.

Return type:

str

classmethod GetName()

Returns the name of the package generator. The name should be specified by setting the class variable NAME.

Return type:

str

Check()

Implement this method to allow checking of of the user-implemented generator.

Returns:

A list of error messages or an empty list if everything is fine.

Return type:

list<str>

Info

Overriding this method is optional

CreateCycleData(name=None, template=None)

Creates an instance of class CycleData.

Parameters:
name : str

A name for this cycle that will be displayed in the report. (optional)

template : str

Path to template package file to be used as base for generator. (optional)

Returns:

The cycle data object

Return type:

CycleData

DryGenerationEnabled()

Returns True, if the generator runs in dry generation mode. In this mode, the generator is used to generate a project with static packages.

Return type:

bool

GenerationIterator()

Implement this method for the generation of the data for on cycle. This is an iterator and it should return an CycleData object with the python keyword ‘yield’. To create an CycleData object, use the method CreateCycleData() and store all information in this object. Example:

def GenerationIterator(self):
    for line in file:
        yield CreateCycleData({'lineData': line})

Info

Overriding this method is mandatory

GetDialog()

Implement this method to return the configuration dialog of your package generator. The dialog should set the generator data.

Return type:

wx.Dialog, None

Info

Overriding this method is optional

GetParameterText()

Implement this method to show the parameters of your package generator in properties column.

Returns:

parameter text

Return type:

str

Info

Overriding this method is optional

GetTargetItemCount()

Implement this method to define the expected number of cycle sets to be generated as information for progress indicators. Will be called for updates throughout the generation. Therefore, you can dynamically return the size of the current task.

Returns:

expected count of cycle sets to be generated

Return type:

int

PostGeneration()

Implement this method to specify post generation behavior. This method is called after the generation. This method will be called even if an exception occurs during generation (incl. PreGeneration), but not if the project execution is aborted (by the user or because of an “abort on error” setting).

Info

Overriding this method is optional

PreGeneration()

Implement this method to specify pre generation behavior. This method is called before the generation.

Info

Overriding this method is optional

class CycleData

A container for all data that can be generated during one cycle.

objectApi = None

The Object API which is used to create test steps.

Type:

ApiClient.ApiClient

packageInstance = None

The package instance to be completed and executed. Based on a provided template or empty.

Type:

ApiClient.Package

AppendParameterSet(name)

Appends a parameter set for this cycle.

Parameters:
name : str

Name of the parameter set that will be displayed in the report.

Returns:

Parameter set

Return type:

ApiClient.ParameterSet

GetParameterSets()

Returns a list of all parameter sets assigned to this cycle.

Returns:

List of parameter sets for this cycle.

Return type:

list<ApiClient.ParameterSet>

ReferenceTestPackageGenerator

class ReferenceTestPackageGeneratorTools

This class provides convenience methods that can be used within the user code section of the Reference Test Package Generator.

An instance of this class is globally available as variable ‘tools’

static AppendTraceAnalysisReference(traceAnalysis, analysisReference, refName, testName)

Adds analysis reference trace step to the current trace analysis. The created ApiClient.TraceAnalysisReference. object is returned.

Parameters:
traceAnalysis

the current reference test trace analysis object

analysisReference : string

name of the episode

refName : string

name of the reference signal

testName : string

name of the test signal

Returns:

object of the analysis reference trace step

Return type:

ApiClient.TraceAnalysisReference

static ApplyPattern(string, pattern, debug=False)

Reduces a string according to a wildcard pattern.

Pattern syntax:

( ) … denotes part of the string that is of interest

* … substitute for any string

? … substitute for any character

If the pattern does not match the string, the full string is returned as is.

Example:

string = 'Signal_XY', pattern = 'Signal_(*)', result: 'XY'

Parameters:
string : str

String that is to be reduced

pattern : str

Pattern that is to be applied to the string

debug=False

Set to True to create debug prints

Returns:

Reduced substring or full string, if pattern does not match

static EnablePlot(traceStep, plotName='')

Adds a plot to the given traceStep with all signals used by the traceStep.

Parameters:
traceStep

the traceStep for which the plot will be enabled

plotName : string, optional

name of the plot, defaults to ‘Signal plot’

static Filter(signalList, includeFilter, excludeFilter='')

Removes signals from a list according to certain criteria.

The filter syntax corresponds to the Filter syntax as described in the ecu.test User Documentation under “Handling > Filter”.

Parameters:
signalList

List with Signal objects that is to be reduced

includeFilter : str

Filter to include certain signals. An empty filter includes everything.

E.g.: "name = '*_important'" (this can also be abbreviated to "'*_important'")

excludeFilter : str

Filter to exclude certain signals. An empty filter excludes nothing.

E.g.: "device != 'Primary'"

Returns:

List of filtered Signal objects

static GetOrCreateEpisode(traceAnalysis, episodeName=None)

The episode with the specified name is returned. If no name is specified, the first episode is returned. If no episode (with the specified name) yet exists, a new episode will be created and appended to the traceAnalysis. The newly created ApiClient.Episode object is returned.

Parameters:
traceAnalysis

the current reference test trace analysis object

episodeName : string, optional

name of the episode

Returns:

object of the episode

Return type:

ApiClient.Episode

class Signal

Represents a single signal inside a trace file. Signals can be easily compared with other Signal objects. Signals can also be used as a set for bulk operations.

device
Returns:

device name within trace file

Return type:

string

name
Returns:

signal name

Return type:

string

type
Returns:

type of trace file (ref|test)

Return type:

string

GetSignalGroupName()

Returns the signal group name of this signal.

Returns:

signal group name

Return type:

string