buildtest.buildsystem.parser

BuildspecParser is will validate a Buildspec file with the global schema and each test will be validated with one of the subschemnas based on the type field. The BuilderBase is the base class for all builders that expose functions to run builds.

Module Contents

Classes

BuildspecParser

A BuildspecParser is responsible for validating a Buildspec file with JSON Schema.

class buildtest.buildsystem.parser.BuildspecParser(buildspec, buildexecutor)[source]

A BuildspecParser is responsible for validating a Buildspec file with JSON Schema.

The type (e.g., script) and version are derived from reading in the file, and then matching to a Buildspec schema.

The schemas are located in folder buildtest/schemas, we load the schema dictionary and validate each buildspec with global schema and a sub-schema based on the type field. If the schema fails validation check, then we stop immediately.

The init method will run some checks against buildspec before loading buildspec. buildtest will validate the entire buildspec with global.schema.json and validate each test section with the designated type schema. For instance of test includes type: script we will validate the test with schema script.schema.json.

If there is any error during the init method, an exception will be raised.

Parameters
  • buildspec (str) – Full path to buildspec file

  • buildexecutor (buildtest.executors.setup.BuildExecutor) – Instance object of class BuildExecutor used for accessing executors which is created based on configuration file

Raises

BuildTestError – Raise exception if there is issue with buildexecutor, or buildspec is not resolved to file path. If buildspec is a directory path we raise an exception

__str__(self)[source]

Return str(self).

__repr__(self)[source]

Return repr(self).

_check_schema_type(self, test)[source]

Check type field is a valid sub-schema and verify type + version will resolve to a schema file.

Parameters

test (str) – Name of test in buildspecs property of buildspec file

Raises

BuildspecError – If there is no match with type property in test with available schema types

validate(self)[source]

This method will validate the entire buildspec file with global schema and each test section with a sub-schema. The global validation ensures that the overall structure of the file is sound for further parsing. We load in the global.schema.json for this purpose.

A buildspec is composed of one or more tests, each section is validated with a sub-schema. The type field is used for sub-schema lookup from schema library. Finally we validate loaded recipe with sub-schema.

get_test_names(self)[source]

Return a list of test names from a buildspec file. The test names are defined under the ‘buildspecs’ property