Project Generator API

ProjectGenerator

class ProjectGenerator

This is the base class for user defined project generators. All project generators should be derived form this class. It defines specific methods that are called during generation of projects. The required behaviour of a project 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 project 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 project 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 project 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 project 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 keept 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 : str | None = 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.

sourceProjectPath : str | None = None

Absolute path to the source project file containing the generator.

classmethod GetDescription()

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

Return type:

str

classmethod GetFormatRev()

Returns the format revision of the project 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 project generator. The identifier should be specified by setting the class variable ID.

Return type:

str

classmethod GetName()

Returns the name of the project 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 project 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 projects.

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 project 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 project 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

projectInstance = None

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

Type:

ApiClient.Project