Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 18f54f3

Browse files
committedMar 13, 2025·
add cattrs tests
1 parent f1f9954 commit 18f54f3

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
 

‎pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ tests = [
7070
"pytest>=6.0",
7171
"pytest-cov",
7272
"pytest-xdist",
73+
"cattrs",
74+
"packaging",
7375
"sympy",
7476
"vcrpy>=5", # keep synchronized with docs dependencies
7577
"importlib_metadata>=4.6; python_version<'3.10'",

‎tests/test_subtitle.py

+24
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from __future__ import annotations
22

33
import os
4+
from importlib.metadata import version as get_version
45
from textwrap import dedent
56
from typing import TYPE_CHECKING
67

78
import pytest
89
from babelfish import Language # type: ignore[import-untyped]
10+
from cattrs import structure, unstructure
11+
from packaging.version import Version
912

1013
from subliminal.subtitle import (
1114
EmbeddedSubtitle,
@@ -566,3 +569,24 @@ def test_embedded_subtitle_info_foreign_only(monkeypatch: pytest.MonkeyPatch) ->
566569
assert subtitle.foreign_only is True
567570
assert isinstance(subtitle.id, str)
568571
assert isinstance(subtitle.info, str)
572+
573+
574+
@pytest.mark.skipif(
575+
Version(get_version('babelfish')) <= Version('0.6.1'),
576+
reason='babelfish.Language needs to be a hashable dataclass',
577+
)
578+
def test_serialize_subtitle() -> None:
579+
content = b'1\n00:01:00 --> 00:02:00\nA long text\n\n'
580+
581+
subtitle = Subtitle(
582+
language=Language('eng'),
583+
hearing_impaired=False,
584+
page_link=None,
585+
encoding=None,
586+
)
587+
subtitle.content = content
588+
589+
ser = unstructure(subtitle)
590+
new_subtitle = structure(ser, Subtitle)
591+
592+
assert subtitle == new_subtitle

‎tests/test_video.py

+29
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
import os
55
from datetime import datetime, timedelta, timezone
6+
from importlib.metadata import version as get_version
67
from typing import TYPE_CHECKING
78
from unittest.mock import Mock
89

910
import pytest
11+
from cattrs import structure, unstructure
12+
from packaging.version import Version
1013

1114
from subliminal.utils import sanitize, timestamp
1215
from subliminal.video import Episode, Movie, Video
@@ -209,3 +212,29 @@ def test_episode_fromname(episodes: dict[str, Episode]) -> None:
209212
assert video.title is None
210213
assert video.year is None
211214
assert video.tvdb_id is None
215+
216+
217+
@pytest.mark.skipif(
218+
Version(get_version('babelfish')) <= Version('0.6.1'),
219+
reason='babelfish.Language needs to be a hashable dataclass',
220+
)
221+
def test_serialize_movie(movies: dict[str, Movie]) -> None:
222+
video = movies['man_of_steel']
223+
224+
ser = unstructure(video)
225+
new_video = structure(ser, Movie)
226+
227+
assert video == new_video
228+
229+
230+
@pytest.mark.skipif(
231+
Version(get_version('babelfish')) <= Version('0.6.1'),
232+
reason='babelfish.Language needs to be a hashable dataclass',
233+
)
234+
def test_serialize_episode(episodes: dict[str, Episode]) -> None:
235+
video = episodes['bbt_s07e05']
236+
237+
ser = unstructure(video)
238+
new_video = structure(ser, Episode)
239+
240+
assert video == new_video

0 commit comments

Comments
 (0)
Please sign in to comment.