Project generator

Advice for use can be found in section Project generator in chapter Projects.

This generator can be used to create dynamically projects. The usage is the similar to the Package generator for projects. The API differs in the point that it is only allowed to use project steps.

The project generators have to be in the project generator directory.

The project generator interface is documented in the Project Generator API Reference.

Info

The interface is included in the ecu.test Interface Python Library ecutest-interface.

Every CycleData object represents a generated project. In general, the following workflow may be used for generating projects:

  1. Creating a CycleData object by doing cd = self.CreateCycleData()

  2. Creating the project steps on the CycleData object via the Object API.

  3. When doing yield cd, the generated project is passed to trace.check and executed immediately.

These steps can be repeated as often as required, until the desired number of projects has been generated.

Examples

Simple example for the implementation of the API

# -*- coding: utf-8 -*-

import os

from datetime import date

from tts.interface.projectGenerator.ProjectGenerator import ProjectGenerator


class ProjectGeneratorExample(ProjectGenerator):

    ID = '64ada5a1-d42f-11e3-9cdf-080027005456'
    NAME = 'Project generator example'
    DESCRIPTION = 'Create a project with all packages from the "everyday" directory and on ' \
                  'weekeends additional with all packages from the weekend sub directory.'
    SERIALIZE = {}

    def __init__(self):
        pass

    def GetDialog(self):
        return None

    def PreGeneration(self):
        print('Start generation')

    def GenerationIterator(self):
        print('Run generation')

        cd = self.CreateCycleData()  # creates cycledata object
        cd.SetName("GeneratedExample")
        project = cd.projectInstance  #  The project instance to be completed and executed
        objectApi = cd.objectApi # The Object API which is used to create test steps
        componentApi = objectApi.ProjectApi.ComponentApi

        pkgBasePath = os.path.join(self.api.GetSetting('packagePath'), "ExamplePackages",
                                   "ProjectGenExample")
        everydayPath = os.path.join(pkgBasePath, "everyday")
        for root, dirnames, filenames in os.walk(everydayPath):
            for filename in filenames:
                packageCall = componentApi.CreatePackageCall(filename,
                                                             os.path.join(root, filename))
                project.AppendComponent(packageCall)

        if date.today().weekday() in (5, 6):  # 5 == Saturday, 6 == Sunday
            weekendPath = os.path.join(pkgBasePath, "weekend")
            for root, dirnames, filenames in os.walk(weekendPath):
                for filename in filenames:
                    packageCall = componentApi.CreatePackageCall(filename,
                                                                 os.path.join(root, filename))
                    project.AppendComponent(packageCall)
        yield cd

    def PostGeneration(self):
        print('Generation finished')

Examples provided

In order to be able to use the provided example it has to be copied into your workspace.

Select the option Copy examples in the workspace selection dialog. Doing this, the necessary examples are copied into the current workspace.

Project generator example

The project generator Project-Example shows the flexible usage of the project generation. It creates a project and inserts package calls from the directory “erveryday” and, if the execution happens on weekend, with package calls from the directory “weekend”.