<s> import os <EOL> from babelfish import Language <EOL> import pytest <EOL> from vcr import VCR <EOL> from subliminal . providers . podnapisi import PodnapisiProvider , PodnapisiSubtitle <EOL> vcr = VCR ( path_transformer = lambda path : path + '<STR_LIT>' , <EOL> record_mode = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> cassette_library_dir = os . path . join ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_get_matches_movie ( movies ) : <EOL> subtitle_releases = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> subtitle = PodnapisiSubtitle ( Language ( '<STR_LIT>' ) , True , None , '<STR_LIT>' , subtitle_releases , '<STR_LIT>' , None , None , <EOL> <NUM_LIT> ) <EOL> matches = subtitle . get_matches ( movies [ '<STR_LIT>' ] ) <EOL> assert matches == { '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' } <EOL> def test_get_matches_episode ( episodes ) : <EOL> subtitle_releases = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> subtitle = PodnapisiSubtitle ( Language ( '<STR_LIT>' ) , False , None , '<STR_LIT>' , subtitle_releases , '<STR_LIT>' , <NUM_LIT:7> , <NUM_LIT:5> , <EOL> <NUM_LIT> ) <EOL> matches = subtitle . get_matches ( episodes [ '<STR_LIT>' ] ) <EOL> assert matches == { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' } <EOL> def test_get_matches_no_match ( episodes ) : <EOL> subtitle_releases = [ '<STR_LIT>' ] <EOL> subtitle = PodnapisiSubtitle ( Language ( '<STR_LIT>' ) , False , None , '<STR_LIT>' , subtitle_releases , '<STR_LIT>' , <NUM_LIT:7> , <NUM_LIT:5> , <EOL> <NUM_LIT> ) <EOL> matches = subtitle . get_matches ( episodes [ '<STR_LIT>' ] , hearing_impaired = True ) <EOL> assert matches == { '<STR_LIT>' } <EOL> @ pytest . mark . integration <EOL> @ vcr . use_cassette <EOL> def test_query_movie ( movies ) : <EOL> video = movies [ '<STR_LIT>' ] <EOL> language = Language ( '<STR_LIT>' ) <EOL> expected_subtitles = { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' } <EOL> with PodnapisiProvider ( ) as provider : <EOL> subtitles = provider . query ( language , video . title , year = video . year ) <EOL> assert { subtitle . pid for subtitle in subtitles } == expected_subtitles <EOL> assert { subtitle . language for subtitle in subtitles } == { language } <EOL> @ pytest . mark . integration <EOL> @ vcr . use_cassette <EOL> def test_query_episode ( episodes ) : <EOL> video = episodes [ '<STR_LIT>' ] <EOL> language = Language ( '<STR_LIT>' ) <EOL> expected_subtitles = { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' } <EOL> with PodnapisiProvider ( ) as provider : <EOL> subtitles = provider . query ( language , video . series , season = video . season , episode = video . episode , <EOL> year = video . year ) <EOL> assert { subtitle . pid for subtitle in subtitles } == expected_subtitles <EOL> assert { subtitle . language for subtitle in subtitles } == { language } <EOL> @ pytest . mark . integration <EOL> @ vcr . use_cassette <EOL> def test_list_subtitles_movie ( movies ) : <EOL> video = movies [ '<STR_LIT>' ] <EOL> languages = { Language ( '<STR_LIT>' ) , Language ( '<STR_LIT>' ) } <EOL> expected_subtitles = { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' } <EOL> with PodnapisiProvider ( ) as provider : <EOL> subtitles = provider . list_subtitles ( video , languages ) <EOL> assert { subtitle . pid for subtitle in subtitles } == expected_subtitles <EOL> assert { subtitle . language for subtitle in subtitles } == languages <EOL> @ pytest . mark . integration <EOL> @ vcr . use_cassette <EOL> def test_list_subtitles_episode ( episodes ) : <EOL> video = episodes [ '<STR_LIT>' ] <EOL> languages = { Language ( '<STR_LIT>' ) , Language ( '<STR_LIT>' ) } <EOL> expected_subtitles = { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' } <EOL> with PodnapisiProvider ( ) as provider : <EOL> subtitles = provider . list_subtitles ( video , languages ) <EOL> assert { subtitle . pid for subtitle in subtitles } == expected_subtitles <EOL> assert { subtitle . language for subtitle in subtitles } == languages <EOL> @ pytest . mark . integration <EOL> @ vcr . use_cassette <EOL> def test_download_subtitle ( movies ) : <EOL> video = movies [ '<STR_LIT>' ] <EOL> languages = { Language ( '<STR_LIT>' ) , Language ( '<STR_LIT>' ) } <EOL> with PodnapisiProvider ( ) as provider : <EOL> subtitles = provider . list_subtitles ( video , languages ) <EOL> subtitle = [ s for s in subtitles if s . pid == '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> provider . download_subtitle ( subtitle ) <EOL> assert subtitle . content is not None <EOL> assert subtitle . is_valid ( ) is True </s>
