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, executor_match=False)[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

  • executor_match (bool, optional) – This boolean determines whether to check for ‘executor’ property in buildspec and see if it matches one of the valid executor names. By default this check is not enforced during buildtest build however this is relevant when loading buildspecs into cache via buildtest buildspec find

Raises:
__str__()[source]

Return str(self).

__repr__()[source]

Return repr(self).

_check_schema_type(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:

InvalidBuildspecSchemaType (buildtest.exceptions.InvalidBuildspecSchemaType) – If there is no match with type property in test with available schema types

_check_executor(test)[source]

This method checks if executor property is not None and executor value is found in list of available executors. :param test: Name of test in buildspecs property of buildspec file :type test: str

Raises:

InvalidBuildspecExecutor (buildtest.exceptions.InvalidBuildspecExecutor) – If there is no match with executor property in test with list of available executors

validate()[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.

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()[source]

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