Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Sep 23, 2024
1 parent 109b297 commit 4802854
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 166 deletions.
4 changes: 2 additions & 2 deletions subliminal/matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def title_matches(video: Video, *, title: str | None = None, episode_title: str
return video.title is not None and sanitize(episode_title) == sanitize(video.title)
if isinstance(video, Movie):
return video.title is not None and sanitize(title) == sanitize(video.title)
return False
return False # pragma: no cover


def season_matches(video: Video, *, season: int | None = None, **kwargs: Any) -> bool:
Expand Down Expand Up @@ -142,7 +142,7 @@ def country_matches(video: Video, *, country: Country | None = None, partial: bo
if isinstance(video, Movie):
# count "no country" as an information
return video.country is None and country is None
return False
return False # pragma: no cover


def release_group_matches(video: Video, *, release_group: str | None = None, **kwargs: Any) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions subliminal/refiners/omdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from subliminal import __short_version__
from subliminal.cache import REFINER_EXPIRATION_TIME, region
from subliminal.utils import decorate_imdb_id, sanitize_id
from subliminal.utils import decorate_imdb_id, matches_title, sanitize_id
from subliminal.video import Episode, Movie, Video

if TYPE_CHECKING:
Expand Down Expand Up @@ -220,7 +220,7 @@ def refine_episode(client: OMDBClient, video: Episode, *, force: bool = False, *

# filter the results, only if multiple results
if len(results) > 1:
results = [r for r in results if video.matches(r['Title'])]
results = [r for r in results if matches_title(r['Title'], video.series, video.alternative_series)]
if not results:
logger.warning('No matching series found')
return
Expand Down Expand Up @@ -261,7 +261,7 @@ def refine_movie(client: OMDBClient, video: Movie, *, force: bool = False, **kwa

# filter the results, only if multiple results
if len(results) > 1:
results = [r for r in results if video.matches(r['Title'])]
results = [r for r in results if matches_title(r['Title'], video.title, video.alternative_titles)]
if not results:
logger.warning('No matching movie found')
return
Expand Down
28 changes: 5 additions & 23 deletions subliminal/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from importlib.util import find_spec
from typing import TYPE_CHECKING, Any

from .utils import clip
from .video import Episode, Movie

if TYPE_CHECKING:
Expand Down Expand Up @@ -96,25 +97,6 @@ def __call__(self, subtitle: Subtitle, video: Video, *, hearing_impaired: bool |
equivalent_release_groups = ({'LOL', 'DIMENSION'}, {'ASAP', 'IMMERSE', 'FLEET'}, {'AVS', 'SVA'})


def clip(value: float, minimum: float | None, maximum: float | None) -> float:
"""Clip the value between a minimum and maximum.
Cheap replacement for the numpy.clip function.
:param float value: the value to clip (float or int).
:param (float | None) minimum: the minimum value (no minimum if None).
:param (float | None) maximum: the maximum value (no maximum if None).
:return: the clipped value.
:rtype: float
"""
if maximum is not None:
value = min(value, maximum)
if minimum is not None:
value = max(value, minimum)
return value


def get_equivalent_release_groups(release_group: str) -> set[str]:
"""Get all the equivalents of the given release group.
Expand Down Expand Up @@ -147,7 +129,7 @@ def get_scores(video: Video) -> dict[str, Any]:
return movie_scores

msg = 'video must be an instance of Episode or Movie' # pragma: no-cover
raise ValueError(msg)
raise ValueError(msg) # pragma: no-cover


def match_hearing_impaired(subtitle: Subtitle, *, hearing_impaired: bool | None = None) -> bool:
Expand Down Expand Up @@ -206,7 +188,7 @@ def compute_score(subtitle: Subtitle, video: Video, *, hearing_impaired: bool |
if 'series_tvdb_id' in matches:
logger.debug('Adding series_tvdb_id match equivalents')
matches |= {'series', 'year', 'country'}
elif isinstance(video, Movie):
elif isinstance(video, Movie): # pragma: no branch
if 'imdb_id' in matches:
logger.debug('Adding imdb_id match equivalents')
matches |= {'title', 'year', 'country'}
Expand All @@ -222,14 +204,14 @@ def compute_score(subtitle: Subtitle, video: Video, *, hearing_impaired: bool |

# ensure score is within valid bounds
max_score = scores['hash'] + scores['hearing_impaired']
if not (0 <= score <= max_score):
if not (0 <= score <= max_score): # pragma: no cover
logger.info('Clip score between 0 and %d: %d', max_score, score)
score = int(clip(score, 0, max_score))

return score


if WITH_SYMPY:
if WITH_SYMPY: # pragma: no cover
from sympy import Eq, Symbol, solve, symbols # type: ignore[import-untyped]

def solve_episode_equations() -> dict[Symbol, int]:
Expand Down
Loading

0 comments on commit 4802854

Please sign in to comment.