File: test_score.py

package info (click to toggle)
subliminal 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,972 kB
  • sloc: python: 10,243; makefile: 166
file content (142 lines) | stat: -rw-r--r-- 4,328 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from __future__ import annotations

from babelfish import Language  # type: ignore[import-untyped]
from subliminal.providers.addic7ed import Addic7edSubtitle
from subliminal.providers.opensubtitles import OpenSubtitlesSubtitle
from subliminal.providers.podnapisi import PodnapisiSubtitle
from subliminal.score import compute_score, episode_scores, movie_scores, solve_episode_equations, solve_movie_equations


def test_episode_equations():
    expected_scores = {}
    for symbol, score in solve_episode_equations().items():
        expected_scores[str(symbol)] = score

    assert episode_scores == expected_scores


def test_movie_equations():
    expected_scores = {}
    for symbol, score in solve_movie_equations().items():
        expected_scores[str(symbol)] = score

    assert movie_scores == expected_scores


def test_compute_score(episodes):
    video = episodes['bbt_s07e05']
    subtitle = Addic7edSubtitle(
        language=Language('eng'),
        subtitle_id='',
        hearing_impaired=True,
        page_link=None,
        series='the big BANG theory',
        season=6,
        episode=4,
        title=None,
        year=None,
        release_group='1080p',
    )
    expected_score = episode_scores['series'] + episode_scores['year'] + episode_scores['country']
    assert compute_score(subtitle, video) == expected_score


def test_get_score_cap(movies):
    video = movies['man_of_steel']
    subtitle = OpenSubtitlesSubtitle(
        language=Language('eng'),
        subtitle_id='1',
        hearing_impaired=True,
        page_link=None,
        matched_by='hash',
        movie_kind='movie',
        moviehash='5b8f8f4e41ccb21e',
        movie_name='Man of Steel',
        movie_release_name='man.of.steel.2013.720p.bluray.x264-felony.mkv',
        movie_year=2013,
        movie_imdb_id='tt770828',
        series_season=None,
        series_episode=None,
        filename='',
        encoding='utf-8',
    )
    assert compute_score(subtitle, video) == movie_scores['hash']


def test_compute_score_episode_imdb_id(movies):
    video = movies['man_of_steel']
    subtitle = OpenSubtitlesSubtitle(
        language=Language('eng'),
        subtitle_id='1',
        hearing_impaired=True,
        page_link=None,
        matched_by='hash',
        movie_kind='movie',
        moviehash=None,
        movie_name='Man of Steel',
        movie_release_name='man.of.steel.2013.720p.bluray.x264-felony.mkv',
        movie_year=2013,
        movie_imdb_id='tt770828',
        series_season=None,
        series_episode=None,
        filename='',
        encoding='utf-8',
    )
    assert compute_score(subtitle, video) == sum(
        movie_scores.get(m, 0)
        for m in ('imdb_id', 'title', 'year', 'country', 'release_group', 'source', 'resolution', 'video_codec')
    )


def test_compute_score_episode_title(episodes):
    video = episodes['bbt_s07e05']
    subtitle = PodnapisiSubtitle(
        language=Language('eng'),
        subtitle_id='1',
        hearing_impaired=True,
        page_link=None,
        releases=['The.Big.Bang.Theory.S07E05.The.Workplace.Proximity.720p.HDTV.x264-DIMENSION.mkv'],
        title=None,
        season=7,
        episode=5,
        year=None,
    )
    assert compute_score(subtitle, video) == sum(
        episode_scores.get(m, 0)
        for m in (
            'series',
            'year',
            'country',
            'season',
            'episode',
            'release_group',
            'source',
            'resolution',
            'video_codec',
            'title',
        )
    )


def test_compute_score_hash_hearing_impaired(movies):
    video = movies['man_of_steel']
    subtitle = OpenSubtitlesSubtitle(
        language=Language('eng'),
        subtitle_id='1',
        hearing_impaired=True,
        page_link=None,
        matched_by='hash',
        movie_kind='movie',
        moviehash='5b8f8f4e41ccb21e',
        movie_name='Man of Steel',
        movie_release_name='man.of.steel.2013.720p.bluray.x264-felony.mkv',
        movie_year=2013,
        movie_imdb_id='tt770828',
        series_season=None,
        series_episode=None,
        filename='',
        encoding='utf-8',
    )
    assert compute_score(subtitle, video, hearing_impaired=True) == (
        movie_scores['hash'] + movie_scores['hearing_impaired']
    )