Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit d8f3de5

Browse files
authored
Merge pull request #76 from courtneypacheco/fix-taxonomy-exception-class
Fix `TaxonomyReadingException` message not displaying
2 parents 69bb69b + b49c6ef commit d8f3de5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/instructlab/schema/taxonomy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@
3434
"""Default yamllint configuration"""
3535

3636

37+
# pylint: disable=unnecessary-pass
3738
class TaxonomyReadingException(Exception):
3839
"""An exception raised during reading of the taxonomy."""
3940

41+
pass
42+
4043

4144
class TaxonomyMessageFormat(enum.Enum):
4245
"""An enum for the format choices for taxonomy parsing messages"""

tests/test_parse.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,32 @@
66
import pathlib
77
import re
88
from collections.abc import Callable
9+
from unittest.mock import patch
910

1011
# Third Party
1112
import pytest
1213
from assertpy import assert_that
1314

14-
from instructlab.schema.taxonomy import TaxonomyMessageFormat, TaxonomyParser
15+
import instructlab.schema.taxonomy # noqa: F401
16+
from instructlab.schema.taxonomy import TaxonomyMessageFormat, TaxonomyParser, TaxonomyReadingException
17+
18+
19+
class TestParserInit:
20+
def test_parser_init_successful_when_schema_version_provided(self) -> None:
21+
taxonomy = TaxonomyParser(schema_version=2)
22+
assert_that(taxonomy).is_instance_of(TaxonomyParser)
23+
assert_that(taxonomy.schema_version).is_equal_to(2)
24+
25+
def test_parser_init_successful_when_schema_version_not_provided_and_defaults_to_latest(self) -> None:
26+
taxonomy = TaxonomyParser(schema_version=None)
27+
assert_that(taxonomy.schema_version).is_equal_to(int(instructlab.schema.schema_versions()[-1].name[1:]))
28+
29+
@patch.object(instructlab.schema.taxonomy, "schema_versions", return_value=[])
30+
def test_parser_init_fails_when_schema_version_not_found(self, mock_schema_versions) -> None:
31+
with pytest.raises(TaxonomyReadingException) as exc_info:
32+
TaxonomyParser(schema_version=None)
33+
mock_schema_versions.assert_called_once()
34+
assert_that(str(exc_info.value)).matches(r'Schema base ".*" does not contain any schema versions')
1535

1636

1737
class TestParsingLogging:

0 commit comments

Comments
 (0)