Skip to content

Commit

Permalink
fix default for subtitle_id
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Oct 22, 2024
1 parent 7782f49 commit 2c2951d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 68 deletions.
2 changes: 1 addition & 1 deletion subliminal/providers/subtitulamos.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SubtitulamosSubtitle(Subtitle):
def __init__(
self,
language: Language,
subtitle_id: str,
subtitle_id: str = '',
hearing_impaired: bool | None = None,
page_link: str | None = None,
series: str | None = None,
Expand Down
143 changes: 76 additions & 67 deletions tests/providers/test_subtitulamos.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_converter_reverse_name_converter():
def test_get_matches_episode(episodes):
subtitle = SubtitulamosSubtitle(
language=Language('spa'),
subtitle_id='',
hearing_impaired=True,
page_link=None,
series='The Big Bang Theory',
Expand All @@ -73,6 +74,32 @@ def test_get_matches_episode(episodes):
assert matches == {'release_group', 'series', 'year', 'country', 'episode', 'season', 'title'}


@pytest.mark.integration()
@vcr.use_cassette
def test_login():
provider = SubtitulamosProvider()
assert provider.session is None
provider.initialize()
assert provider.session is not None


@pytest.mark.integration()
@vcr.use_cassette
def test_logout():
provider = SubtitulamosProvider()
provider.initialize()
provider.terminate()
assert provider.session is None


@pytest.mark.integration()
def test_logout_without_initialization():
provider = SubtitulamosProvider()
with pytest.raises(NotInitializedProviderError):
provider.terminate()


@pytest.mark.integration()
def test_list_subtitles_without_initialization(episodes):
video = episodes['bbt_s11e16']
languages = {Language('eng'), Language('spa')}
Expand All @@ -82,6 +109,7 @@ def test_list_subtitles_without_initialization(episodes):
provider.list_subtitles(video, languages)


@pytest.mark.integration()
def test_list_subtitles_no_video_type():
video = {} # type: ignore[var-annotated]
languages = {Language('spa')}
Expand All @@ -93,27 +121,49 @@ def test_list_subtitles_no_video_type():

@pytest.mark.integration()
@vcr.use_cassette
def test_login():
provider = SubtitulamosProvider()
assert provider.session is None
provider.initialize()
assert provider.session is not None
def test_list_subtitles_not_exist_series(caplog, episodes):
with caplog.at_level(logging.DEBUG, logger=logger_name), SubtitulamosProvider() as provider:
video = episodes['fake_show_s13e03']
languages = {Language('spa')}

subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) == 0
assert caplog.records[-1].message.endswith('Series not found')


@pytest.mark.integration()
@vcr.use_cassette
def test_logout():
provider = SubtitulamosProvider()
provider.initialize()
provider.terminate()
assert provider.session is None
def test_list_subtitles_not_exist_season(caplog, episodes):
with caplog.at_level(logging.DEBUG, logger=logger_name), SubtitulamosProvider() as provider:
video = episodes['bbt_s07e05']
languages = {Language('eng'), Language('spa')}

subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) == 0
assert caplog.records[-1].message.endswith('Season not found')


@pytest.mark.integration()
def test_logout_without_initialization():
provider = SubtitulamosProvider()
with pytest.raises(NotInitializedProviderError):
provider.terminate()
@vcr.use_cassette
def test_list_subtitles_not_exist_episode(caplog, episodes):
with caplog.at_level(logging.DEBUG, logger=logger_name), SubtitulamosProvider() as provider:
video = episodes['fear_walking_dead_s03e10']
languages = {Language('eng'), Language('spa')}

subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) == 0
assert caplog.records[-1].message.endswith('Episode not found')


@pytest.mark.integration()
@vcr.use_cassette
def test_list_subtitles_not_exist_language(caplog, episodes):
with caplog.at_level(logging.DEBUG, logger=logger_name), SubtitulamosProvider() as provider:
video = episodes['dw_s13e03']
languages = {Language('spa', 'MX')}

subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) == 0


@pytest.mark.integration()
Expand Down Expand Up @@ -151,9 +201,10 @@ def test_download_subtitle_year(episodes):
def test_download_subtitle_last_season(episodes):
video = episodes['dw_s13e03']
languages = {Language('eng'), Language('spa')}
with SubtitulamosProvider() as provider, patch.object(
SubtitulamosProvider, '_read_series', wraps=provider._read_series
) as mock:
with (
SubtitulamosProvider() as provider,
patch.object(SubtitulamosProvider, '_read_series', wraps=provider._read_series) as mock,
):
subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) >= 1
subtitle = subtitles[0]
Expand All @@ -171,9 +222,10 @@ def test_download_subtitle_last_season(episodes):
def test_download_subtitle_first_episode(episodes):
video = episodes['charmed_s01e01']
languages = {Language('eng')}
with SubtitulamosProvider() as provider, patch.object(
SubtitulamosProvider, '_read_series', wraps=provider._read_series
) as mock:
with (
SubtitulamosProvider() as provider,
patch.object(SubtitulamosProvider, '_read_series', wraps=provider._read_series) as mock,
):
subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) >= 1
subtitle = subtitles[0]
Expand Down Expand Up @@ -201,9 +253,11 @@ def test_download_subtitle_foo(episodes):
assert subtitle.is_valid() is True


@pytest.mark.integration()
def test_download_subtitle_missing_download_link():
subtitle = SubtitulamosSubtitle(
language=Language('spa'),
subtitle_id='',
hearing_impaired=True,
page_link=None,
series='The Big Bang Theory',
Expand All @@ -220,9 +274,11 @@ def test_download_subtitle_missing_download_link():
assert subtitle.is_valid() is False


@pytest.mark.integration()
def test_download_subtitle_without_initialization():
subtitle = SubtitulamosSubtitle(
language=Language('spa'),
subtitle_id='',
hearing_impaired=True,
page_link=None,
series='The Big Bang Theory',
Expand All @@ -236,50 +292,3 @@ def test_download_subtitle_without_initialization():
provider = SubtitulamosProvider()
with pytest.raises(NotInitializedProviderError):
provider.download_subtitle(subtitle)


@pytest.mark.integration()
@vcr.use_cassette
def test_list_subtitles_not_exist_series(caplog, episodes):
with caplog.at_level(logging.DEBUG, logger=logger_name), SubtitulamosProvider() as provider:
video = episodes['fake_show_s13e03']
languages = {Language('spa')}

subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) == 0
assert caplog.records[-1].message.endswith('Series not found')


@pytest.mark.integration()
@vcr.use_cassette
def test_list_subtitles_not_exist_season(caplog, episodes):
with caplog.at_level(logging.DEBUG, logger=logger_name), SubtitulamosProvider() as provider:
video = episodes['bbt_s07e05']
languages = {Language('eng'), Language('spa')}

subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) == 0
assert caplog.records[-1].message.endswith('Season not found')


@pytest.mark.integration()
@vcr.use_cassette
def test_list_subtitles_not_exist_episode(caplog, episodes):
with caplog.at_level(logging.DEBUG, logger=logger_name), SubtitulamosProvider() as provider:
video = episodes['fear_walking_dead_s03e10']
languages = {Language('eng'), Language('spa')}

subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) == 0
assert caplog.records[-1].message.endswith('Episode not found')


@pytest.mark.integration()
@vcr.use_cassette
def test_list_subtitles_not_exist_language(caplog, episodes):
with caplog.at_level(logging.DEBUG, logger=logger_name), SubtitulamosProvider() as provider:
video = episodes['dw_s13e03']
languages = {Language('spa', 'MX')}

subtitles = provider.list_subtitles(video, languages)
assert len(subtitles) == 0

0 comments on commit 2c2951d

Please sign in to comment.