diff --git a/.github/workflows/actionlint.dockerfile b/.github/workflows/actionlint.dockerfile index 79db008..9de2e84 100644 --- a/.github/workflows/actionlint.dockerfile +++ b/.github/workflows/actionlint.dockerfile @@ -1,3 +1,3 @@ # Since dependabot cannot update workflows using docker, # we use this indirection since dependabot can update this file. -FROM rhysd/actionlint:1.7.1@sha256:435ecdb63b1169e80ca3e136290072548c07fc4d76a044cf5541021712f8f344 +FROM rhysd/actionlint:1.7.4@sha256:82244e1db1c60d82c7792180a48dd0bcb838370bb589d53ff132503fc9485868 diff --git a/.github/workflows/actionlint.yml b/.github/workflows/actionlint.yml index 150d7ff..68a58ad 100644 --- a/.github/workflows/actionlint.yml +++ b/.github/workflows/actionlint.yml @@ -30,12 +30,12 @@ jobs: runs-on: ubuntu-latest steps: - name: "Harden Runner" - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: "Checkout" - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 0 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d34a0ba..2d727e8 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -33,14 +33,14 @@ jobs: runs-on: ubuntu-latest steps: - name: "Harden Runner" - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: "Checkout" - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 0 - name: "Check Markdown documents" - uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 # v16.0.0 + uses: DavidAnson/markdownlint-cli2-action@eb5ca3ab411449c66620fe7f1b3c9e10547144b0 # v18.0.0 with: globs: '**/*.md' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2b7e7f0..b8cf46a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -59,17 +59,17 @@ jobs: tox -e mypy steps: - name: "Harden Runner" - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: "Checkout" - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 0 - name: "Setup Python" - uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1 + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 with: python-version: "3.11" diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 52e254d..29123f7 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -35,19 +35,19 @@ jobs: runs-on: ubuntu-latest steps: - name: "Harden Runner" - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: "Checkout" - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: # for setuptools-scm fetch-depth: 0 - name: "Build and Inspect" - uses: hynek/build-and-inspect-python-package@2dbbf2b252d3a3c7cec7a810e3ed5983bd17b13a # v2.8.0 + uses: hynek/build-and-inspect-python-package@14c7e53f5d033cfa99f7af916fa59a6f7f356394 # v2.11.0 # push to Test PyPI on # - a new GitHub release is published @@ -65,7 +65,7 @@ jobs: steps: - name: "Harden Runner" - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs @@ -76,7 +76,7 @@ jobs: path: dist - name: "Upload to Test PyPI" - uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0 # v1.9.0 + uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 with: repository-url: https://test.pypi.org/legacy/ @@ -97,7 +97,7 @@ jobs: steps: - name: "Harden Runner" - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs @@ -128,4 +128,4 @@ jobs: rm ./dist/*.sigstore.json - name: "Upload to PyPI" - uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0 # v1.9.0 + uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a0fc51b..2074011 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,17 +48,17 @@ jobs: - "ubuntu-latest" steps: - name: "Harden Runner" - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: "Checkout" - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 0 - name: "Setup Python ${{ matrix.python }}" - uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1 + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 with: python-version: ${{ matrix.python }} diff --git a/README.md b/README.md index 5740d49..8ead50a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Taxonomy Schema +![Lint](https://github.com/instructlab/schema/actions/workflows/lint.yml/badge.svg?branch=main) +![Tests](https://github.com/instructlab/schema/actions/workflows/test.yml/badge.svg?branch=main) +![Build](https://github.com/instructlab/schema/actions/workflows/pypi.yml/badge.svg?branch=main) + This Python package defines the JSON schema and a parser for the InstructLab [Taxonomy](https://github.com/instructlab/taxonomy) YAML. Consumers of this schema can `pip install instructlab-schema`, and use the `instructlab.schema.taxonomy.TaxonomyParser` class to parse and validate `qna.yaml` taxonomy files. diff --git a/src/instructlab/schema/taxonomy.py b/src/instructlab/schema/taxonomy.py index a3e9e14..9e2f9c7 100644 --- a/src/instructlab/schema/taxonomy.py +++ b/src/instructlab/schema/taxonomy.py @@ -34,9 +34,12 @@ """Default yamllint configuration""" +# pylint: disable=unnecessary-pass class TaxonomyReadingException(Exception): """An exception raised during reading of the taxonomy.""" + pass + class TaxonomyMessageFormat(enum.Enum): """An enum for the format choices for taxonomy parsing messages""" diff --git a/tests/test_parse.py b/tests/test_parse.py index e13e778..b1b39a3 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -6,12 +6,32 @@ import pathlib import re from collections.abc import Callable +from unittest.mock import patch # Third Party import pytest from assertpy import assert_that -from instructlab.schema.taxonomy import TaxonomyMessageFormat, TaxonomyParser +import instructlab.schema.taxonomy # noqa: F401 +from instructlab.schema.taxonomy import TaxonomyMessageFormat, TaxonomyParser, TaxonomyReadingException + + +class TestParserInit: + def test_parser_init_successful_when_schema_version_provided(self) -> None: + taxonomy = TaxonomyParser(schema_version=2) + assert_that(taxonomy).is_instance_of(TaxonomyParser) + assert_that(taxonomy.schema_version).is_equal_to(2) + + def test_parser_init_successful_when_schema_version_not_provided_and_defaults_to_latest(self) -> None: + taxonomy = TaxonomyParser(schema_version=None) + assert_that(taxonomy.schema_version).is_equal_to(int(instructlab.schema.schema_versions()[-1].name[1:])) + + @patch.object(instructlab.schema.taxonomy, "schema_versions", return_value=[]) + def test_parser_init_fails_when_schema_version_not_found(self, mock_schema_versions) -> None: + with pytest.raises(TaxonomyReadingException) as exc_info: + TaxonomyParser(schema_version=None) + mock_schema_versions.assert_called_once() + assert_that(str(exc_info.value)).matches(r'Schema base ".*" does not contain any schema versions') class TestParsingLogging: