:py:mod:`buildtest.buildsystem.parser` ====================================== .. py:module:: buildtest.buildsystem.parser .. autoapi-nested-parse:: 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 ~~~~~~~ .. autoapisummary:: buildtest.buildsystem.parser.BuildspecParser .. py:class:: BuildspecParser(buildspec, buildexecutor, executor_match=False) 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. :param buildspec: Full path to buildspec file :type buildspec: str :param buildexecutor: Instance object of class BuildExecutor used for accessing executors which is created based on configuration file :type buildexecutor: buildtest.executors.setup.BuildExecutor :param executor_match: 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` :type executor_match: bool, optional :raises ExecutorError (buildtest.exceptions.ExecutorError): 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 :raises InvalidBuildspec (buildtest.exceptions.InvalidBuildspec): Raise exception when buildspec is invalid. .. py:method:: __str__() Return str(self). .. py:method:: __repr__() Return repr(self). .. py:method:: _check_schema_type(test) Check ``type`` field is a valid sub-schema and verify ``type`` + ``version`` will resolve to a schema file. :param test: Name of test in ``buildspecs`` property of buildspec file :type test: str :raises InvalidBuildspecSchemaType (buildtest.exceptions.InvalidBuildspecSchemaType): If there is no match with ``type`` property in test with available schema types .. py:method:: _check_executor(test) 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 .. py:method:: validate() 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. .. py:method:: get_test_names() Return a list of test names from a buildspec file. The test names are defined under the 'buildspecs' property