Skip to content

Commit

Permalink
fix tests; add news
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Feb 14, 2025
1 parent 36690fd commit e298578
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/1096.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make `rarfile` an optional dependency, install with subliminal[rar]
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ docs = [
"towncrier",
]
tests = [
"subliminal[rar]",
"coverage[toml]>=7",
"pytest>=6.0",
"pytest-cov",
Expand Down
8 changes: 5 additions & 3 deletions src/subliminal/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ def scan_archive(path: str | os.PathLike, name: str | None = None) -> Video: #
path = Path(path)

# rar
if '.rar' in ARCHIVE_EXTENSIONS and path.name.lower().endswith('.rar'):
if '.rar' in ARCHIVE_EXTENSIONS and path.suffix.lower() == '.rar':
try:
video = scan_archive_rar(path, name=name)
except (Error, NotRarFile, RarCannotExec, ValueError) as e:
raise ArchiveError from e
args = (e.message,) if hasattr(e, 'message') else e.args
raise ArchiveError(*args) from e

return video

raise ArchiveError
msg = f'{path.suffix!r} is not a valid archive'
raise ArchiveError(msg)


def scan_archive_rar(path: str | os.PathLike, name: str | None = None) -> Video: # pragma: no cover
Expand Down
9 changes: 5 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
scan_videos,
search_external_subtitles,
)
from subliminal.exceptions import ArchiveError
from subliminal.subtitle import Subtitle
from subliminal.utils import timestamp
from subliminal.video import Episode, Movie
Expand Down Expand Up @@ -285,7 +286,7 @@ def test_scan_archive_invalid_extension(movies: dict[str, Movie], tmpdir, monkey
monkeypatch.chdir(str(tmpdir))
movie_name = os.path.splitext(movies['interstellar'].name)[0] + '.mp3'
tmpdir.ensure(movie_name)
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ArchiveError) as excinfo:
scan_archive(movie_name)
assert str(excinfo.value) == "'.mp3' is not a valid archive"

Expand Down Expand Up @@ -442,20 +443,20 @@ def test_scan_archive_with_multiple_videos(rar: dict[str, str], mkv: dict[str, s

@unix_platform
def test_scan_archive_with_no_video(rar: dict[str, str]) -> None:
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ArchiveError) as excinfo:
scan_archive(rar['simple'])
assert excinfo.value.args == ('No video in archive',)


@unix_platform
def test_scan_bad_archive(mkv: dict[str, str]) -> None:
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ArchiveError) as excinfo:
scan_archive(mkv['test1'])
assert excinfo.value.args == ("'.mkv' is not a valid archive",)


@unix_platform
def test_scan_password_protected_archive(rar: dict[str, str]) -> None:
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ArchiveError) as excinfo:
scan_archive(rar['pwd-protected'])
assert excinfo.value.args == ('Rar requires a password',)

0 comments on commit e298578

Please sign in to comment.