aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bazarr/app/test_get_providers.py45
-rw-r--r--tests/bazarr/conftest.py1
-rw-r--r--tests/bazarr/test_app_get_providers.py115
-rw-r--r--tests/bazarr/test_subtitles_pool.py10
-rw-r--r--tests/subliminal_patch/test_core.py96
5 files changed, 222 insertions, 45 deletions
diff --git a/tests/bazarr/app/test_get_providers.py b/tests/bazarr/app/test_get_providers.py
deleted file mode 100644
index caafa17d9..000000000
--- a/tests/bazarr/app/test_get_providers.py
+++ /dev/null
@@ -1,45 +0,0 @@
-import pytest
-
-import inspect
-
-from bazarr.app import get_providers
-
-
-def test_get_providers_auth():
- for val in get_providers.get_providers_auth().values():
- assert isinstance(val, dict)
-
-
-def test_get_providers_auth_with_provider_registry():
- """Make sure all providers will be properly initialized with bazarr
- configs"""
- from subliminal_patch.extensions import provider_registry
-
- auths = get_providers.get_providers_auth()
- for key, val in auths.items():
- provider = provider_registry[key]
- sign = inspect.signature(provider.__init__)
- for sub_key in val.keys():
- if sub_key not in sign.parameters:
- raise ValueError(f"'{sub_key}' parameter not present in {provider}")
-
- assert sign.parameters[sub_key] is not None
-
-
-def test_get_providers_auth_embeddedsubtitles():
- item = get_providers.get_providers_auth()["embeddedsubtitles"]
- assert isinstance(item["included_codecs"], list)
- assert isinstance(item["hi_fallback"], bool)
- assert isinstance(item["cache_dir"], str)
- assert isinstance(item["ffprobe_path"], str)
- assert isinstance(item["ffmpeg_path"], str)
- assert isinstance(item["timeout"], str)
- assert isinstance(item["unknown_as_english"], bool)
-
-
-def test_get_providers_auth_karagarga():
- item = get_providers.get_providers_auth()["karagarga"]
- assert item["username"] is not None
- assert item["password"] is not None
- assert item["f_username"] is not None
- assert item["f_password"] is not None
diff --git a/tests/bazarr/conftest.py b/tests/bazarr/conftest.py
index 865b92767..d4bc23974 100644
--- a/tests/bazarr/conftest.py
+++ b/tests/bazarr/conftest.py
@@ -3,5 +3,6 @@ import logging
os.environ["NO_CLI"] = "true"
os.environ["SZ_USER_AGENT"] = "test"
+os.environ["BAZARR_VERSION"] = "test" # fixme
logging.getLogger("rebulk").setLevel(logging.WARNING)
diff --git a/tests/bazarr/test_app_get_providers.py b/tests/bazarr/test_app_get_providers.py
new file mode 100644
index 000000000..e6a31a39f
--- /dev/null
+++ b/tests/bazarr/test_app_get_providers.py
@@ -0,0 +1,115 @@
+import inspect
+
+import pytest
+from subliminal_patch.core import Language
+
+from bazarr.app import get_providers
+
+
+def test_get_providers_auth():
+ for val in get_providers.get_providers_auth().values():
+ assert isinstance(val, dict)
+
+
+def test_get_providers_auth_with_provider_registry():
+ """Make sure all providers will be properly initialized with bazarr
+ configs"""
+ from subliminal_patch.extensions import provider_registry
+
+ auths = get_providers.get_providers_auth()
+ for key, val in auths.items():
+ provider = provider_registry[key]
+ sign = inspect.signature(provider.__init__)
+ for sub_key in val.keys():
+ if sub_key not in sign.parameters:
+ raise ValueError(f"'{sub_key}' parameter not present in {provider}")
+
+ assert sign.parameters[sub_key] is not None
+
+
+def test_get_providers_auth_embeddedsubtitles():
+ item = get_providers.get_providers_auth()["embeddedsubtitles"]
+ assert isinstance(item["included_codecs"], list)
+ assert isinstance(item["hi_fallback"], bool)
+ assert isinstance(item["cache_dir"], str)
+ assert isinstance(item["ffprobe_path"], str)
+ assert isinstance(item["ffmpeg_path"], str)
+ assert isinstance(item["timeout"], str)
+ assert isinstance(item["unknown_as_english"], bool)
+
+
+def test_get_providers_auth_karagarga():
+ item = get_providers.get_providers_auth()["karagarga"]
+ assert item["username"] is not None
+ assert item["password"] is not None
+ assert item["f_username"] is not None
+ assert item["f_password"] is not None
+
+
+def test_get_language_equals_default_settings():
+ assert isinstance(get_providers.get_language_equals(), list)
+
+
+def test_get_language_equals_injected_settings_invalid():
+ config = get_providers.settings
+ config.set("general", "language_equals", '["invalid"]')
+ assert not get_providers.get_language_equals(config)
+
+
+def test_get_language_equals_injected_settings_valid():
+ config = get_providers.settings
+ config.set("general", "language_equals", '["spa:spa-MX"]')
+
+ result = get_providers.get_language_equals(config)
+ assert result == [(Language("spa"), Language("spa", "MX"))]
+
+
+ "config_value,expected",
+ [
+ ('["spa:spl"]', (Language("spa"), Language("spa", "MX"))),
+ ('["por:pob"]', (Language("por"), Language("por", "BR"))),
+ ('["zho:zht"]', (Language("zho"), Language("zho", "TW"))),
+ ],
+)
+def test_get_language_equals_injected_settings_custom_lang_alpha3(
+ config_value, expected
+):
+ config = get_providers.settings
+
+ config.set("general", "language_equals", config_value)
+
+ result = get_providers.get_language_equals(config)
+ assert result == [expected]
+
+
+def test_get_language_equals_injected_settings_multiple():
+ config = get_providers.settings
+
+ config.set(
+ "general",
+ "language_equals",
+ "['eng@hi:eng', 'spa:spl', 'spa@hi:spl', 'spl@hi:spl']",
+ )
+
+ result = get_providers.get_language_equals(config)
+ assert len(result) == 4
+
+
+def test_get_language_equals_injected_settings_valid_multiple():
+ config = get_providers.settings
+ config.set("general", "language_equals", '["spa:spa-MX", "spa-MX:spa"]')
+
+ result = get_providers.get_language_equals(config)
+ assert result == [
+ (Language("spa"), Language("spa", "MX")),
+ (Language("spa", "MX"), Language("spa")),
+ ]
+
+
+def test_get_language_equals_injected_settings_hi():
+ config = get_providers.settings
+ config.set("general", "language_equals", '["eng@hi:eng"]')
+
+ result = get_providers.get_language_equals(config)
+ assert result == [(Language("eng", hi=True), Language("eng"))]
diff --git a/tests/bazarr/test_subtitles_pool.py b/tests/bazarr/test_subtitles_pool.py
new file mode 100644
index 000000000..862c6d493
--- /dev/null
+++ b/tests/bazarr/test_subtitles_pool.py
@@ -0,0 +1,10 @@
+from bazarr.subtitles import pool
+
+
+def test_init_pool():
+ assert pool._init_pool("movie")
+
+
+def test_pool_update():
+ pool_ = pool._init_pool("movie")
+ assert pool._pool_update(pool_, "movie")
diff --git a/tests/subliminal_patch/test_core.py b/tests/subliminal_patch/test_core.py
index d6481ee16..fadf4e493 100644
--- a/tests/subliminal_patch/test_core.py
+++ b/tests/subliminal_patch/test_core.py
@@ -70,3 +70,99 @@ def test_pool_update_discarded_providers_2(pool_instance):
# Provider should not disappear from discarded providers
assert pool_instance.discarded_providers == {"argenteam"}
+
+
+def test_language_equals_init():
+ assert core._LanguageEquals([(core.Language("spa"), core.Language("spa", "MX"))])
+
+
+def test_language_equals_init_invalid():
+ with pytest.raises(ValueError):
+ assert core._LanguageEquals([(core.Language("spa", "MX"),)])
+
+
+def test_language_equals_init_empty_list_gracefully():
+ assert core._LanguageEquals([]) == []
+
+
+ "langs",
+ [
+ [(core.Language("spa"), core.Language("spa", "MX"))],
+ [(core.Language("por"), core.Language("por", "BR"))],
+ [(core.Language("zho"), core.Language("zho", "TW"))],
+ ],
+)
+def test_language_equals_check_set(langs):
+ equals = core._LanguageEquals(langs)
+ lang_set = {langs[0]}
+ assert equals.check_set(lang_set) == set(langs)
+
+
+def test_language_equals_check_set_do_nothing():
+ equals = core._LanguageEquals([(core.Language("eng"), core.Language("spa"))])
+ lang_set = {core.Language("spa")}
+ assert equals.check_set(lang_set) == {core.Language("spa")}
+
+
+def test_language_equals_check_set_do_nothing_w_forced():
+ equals = core._LanguageEquals(
+ [(core.Language("spa", forced=True), core.Language("spa", "MX"))]
+ )
+ lang_set = {core.Language("spa")}
+ assert equals.check_set(lang_set) == {core.Language("spa")}
+
+
+def language_equals_pool_intance():
+ equals = [(core.Language("spa"), core.Language("spa", "MX"))]
+ yield core.SZProviderPool({"subdivx"}, language_equals=equals)
+
+
+def test_language_equals_pool_intance_list_subtitles(
+ language_equals_pool_intance, movies
+):
+ subs = language_equals_pool_intance.list_subtitles(
+ movies["dune"], {core.Language("spa")}
+ )
+ assert subs
+ assert all(sub.language == core.Language("spa", "MX") for sub in subs)
+
+
+def test_language_equals_pool_intance_list_subtitles_reversed(movies):
+ equals = [(core.Language("spa", "MX"), core.Language("spa"))]
+ language_equals_pool_intance = core.SZProviderPool(
+ {"subdivx"}, language_equals=equals
+ )
+ subs = language_equals_pool_intance.list_subtitles(
+ movies["dune"], {core.Language("spa")}
+ )
+ assert subs
+ assert all(sub.language == core.Language("spa") for sub in subs)
+
+
+def test_language_equals_pool_intance_list_subtitles_empty_lang_equals(movies):
+ language_equals_pool_intance = core.SZProviderPool(
+ {"subdivx"}, language_equals=None
+ )
+ subs = language_equals_pool_intance.list_subtitles(
+ movies["dune"], {core.Language("spa")}
+ )
+ assert subs
+ assert not all(sub.language == core.Language("spa", "MX") for sub in subs)
+
+
+def test_language_equals_pool_intance_list_subtitles_return_nothing(movies):
+ equals = [
+ (core.Language("spa", "MX"), core.Language("eng")),
+ (core.Language("spa"), core.Language("eng")),
+ ]
+ language_equals_pool_intance = core.SZProviderPool(
+ {"subdivx"}, language_equals=equals
+ )
+ subs = language_equals_pool_intance.list_subtitles(
+ movies["dune"], {core.Language("spa")}
+ )
+ assert not language_equals_pool_intance.download_best_subtitles(
+ subs, movies["dune"], {core.Language("spa")}
+ )