Skip to content

Commit

Permalink
More testing adaptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibo-Joshi committed Feb 4, 2025
1 parent c40153b commit 90558ee
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ repos:
- id: mypy
name: mypy
files: ^(?!(tests|changes)).*\.py$
args:
- --enable-incomplete-feature=NewGenericSyntax
additional_dependencies:
- .
- pydantic-settings~=2.3
Expand Down
1 change: 1 addition & 0 deletions changes/unreleased/0064.TcBysgmjU9HuXcCNtAmXnp.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
features = "Add Classes :class:`~chango.concrete.BackwardCompatibleVersionScanner` and :class:`~chango.concrete.BackwardCompatibleChanGo` allowing to easily transition between change not formats"
breaking = "Adapt expected exceptions in :class:`~chango.abc.ChanGo` and :class:`~chango.abc.VersionScanner` to use :class:`~chango.error.ChanGoError`"
internal = "Switch to using :class:`~chango.concrete.sections.GitHubSectionChangeNote`"
[[pull_requests]]
uid = "64"
Expand Down
2 changes: 1 addition & 1 deletion src/chango/abc/_chango.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def load_version_note(self, version: VUIDInput) -> VNT:
:class:`VNT <typing.TypeVar>`: The loaded :class:`~chango.abc.VersionNote`.
Raises:
ValueError: If the version is not available.
~chango.error.ChanGoError: If the version is not available.
"""
changes = self.scanner.get_changes(version)
version_obj = self.scanner.get_version(version) if isinstance(version, str) else version
Expand Down
5 changes: 3 additions & 2 deletions src/chango/abc/_versionscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .._changenoteinfo import ChangeNoteInfo
from .._utils.types import VUIDInput
from .._version import Version
from ..error import ChanGoError


class VersionScanner(Collection[Version]):
Expand Down Expand Up @@ -112,12 +113,12 @@ def get_version(self, uid: str) -> Version:
:class:`~chango.Version`: The version.
Raises:
ValueError: If the version with the given identifier is not available.
~chango.error.ChanGoError: If the version with the given identifier is not available.
"""
try:
return next(version for version in self if version.uid == uid)
except StopIteration as exc:
raise ValueError(f"Version '{uid}' not available.") from exc
raise ChanGoError(f"Version '{uid}' not available.") from exc

@abc.abstractmethod
def get_changes(self, uid: VUIDInput) -> tuple[str, ...]:
Expand Down
5 changes: 3 additions & 2 deletions src/chango/concrete/_directorychango.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .._utils.types import VUIDInput
from ..abc import ChangeNote, ChanGo, VersionHistory, VersionNote
from ..action import ChanGoActionData
from ..error import ChanGoError
from ._directoryversionscanner import DirectoryVersionScanner
from .sections import SectionChangeNote, SectionVersionNote

Expand Down Expand Up @@ -93,8 +94,8 @@ def get_write_directory(self, change_note: CNT | str, version: VUIDInput) -> Pat
if isinstance(version, str):
try:
version_obj = self.scanner.get_version(version)
except ValueError as exc:
raise TypeError(
except ChanGoError as exc:
raise ChanGoError(
f"Version '{version}' not available yet. To get the write directory for a "
"new version, pass the version as `change.Version` object."
) from exc
Expand Down
3 changes: 2 additions & 1 deletion tests/abc/test_versionscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from chango import Version
from chango.abc import VersionScanner
from chango.concrete import DirectoryVersionScanner
from chango.error import ChanGoError
from tests.auxil.files import data_path


Expand Down Expand Up @@ -81,7 +82,7 @@ def test_get_version(self, scanner, idx):
assert version.date == dtm.date(2024, 1, idx)

def test_get_version_not_found(self, scanner):
with pytest.raises(ValueError, match="not available"):
with pytest.raises(ChanGoError, match="not available"):
scanner.get_version("1.4")

def test_invalidates_caches(self, scanner):
Expand Down

0 comments on commit 90558ee

Please sign in to comment.