mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-26 02:36:10 +00:00
fix linting
This commit is contained in:
parent
ca49333887
commit
6cde7a1141
1 changed files with 202 additions and 112 deletions
|
@ -5,22 +5,24 @@ import pytest
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_play_utils():
|
def mock_play_utils():
|
||||||
with patch('jellyfin_kodi.helper.playutils.PlayUtils') as MockPlayUtils:
|
with patch("jellyfin_kodi.helper.playutils.PlayUtils") as MockPlayUtils:
|
||||||
mock_instance = MockPlayUtils.return_value
|
mock_instance = MockPlayUtils.return_value
|
||||||
mock_instance.get_transcoding_video_codec.return_value = ""
|
mock_instance.get_transcoding_video_codec.return_value = ""
|
||||||
yield mock_instance
|
yield mock_instance
|
||||||
|
|
||||||
|
|
||||||
def test_hevc_transcoding_scenario(mock_play_utils):
|
def test_hevc_transcoding_scenario(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
# Scenario 1: Force Transcode enabled, Transcode HEVC disabled
|
# Scenario 1: Force Transcode enabled, Transcode HEVC disabled
|
||||||
mock_settings.side_effect = [
|
mock_settings.side_effect = [
|
||||||
True, # transcode_h265 = True (Transcode HEVC disabled)
|
True, # transcode_h265 = True (Transcode HEVC disabled)
|
||||||
"", # videoPreferredCodec = "" (no preference)
|
"", # videoPreferredCodec = "" (no preference)
|
||||||
False, # transcode_mpeg2 = False
|
False, # transcode_mpeg2 = False
|
||||||
False # transcode_vc1 = False
|
False, # transcode_vc1 = False
|
||||||
]
|
]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = "h264,mpeg4,mpeg2video,vc1"
|
mock_play_utils.get_transcoding_video_codec.return_value = (
|
||||||
|
"h264,mpeg4,mpeg2video,vc1"
|
||||||
|
)
|
||||||
result_1 = mock_play_utils.get_transcoding_video_codec()
|
result_1 = mock_play_utils.get_transcoding_video_codec()
|
||||||
|
|
||||||
# Scenario 2: Force Transcode enabled, Transcode HEVC enabled
|
# Scenario 2: Force Transcode enabled, Transcode HEVC enabled
|
||||||
|
@ -28,26 +30,42 @@ def test_hevc_transcoding_scenario(mock_play_utils):
|
||||||
False, # transcode_h265 = False (Transcode HEVC enabled)
|
False, # transcode_h265 = False (Transcode HEVC enabled)
|
||||||
"", # videoPreferredCodec = "" (no preference)
|
"", # videoPreferredCodec = "" (no preference)
|
||||||
False, # transcode_mpeg2 = False
|
False, # transcode_mpeg2 = False
|
||||||
False # transcode_vc1 = False
|
False, # transcode_vc1 = False
|
||||||
]
|
]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = "h264,mpeg4,mpeg2video,vc1,hevc"
|
mock_play_utils.get_transcoding_video_codec.return_value = (
|
||||||
|
"h264,mpeg4,mpeg2video,vc1,hevc"
|
||||||
|
)
|
||||||
result_2 = mock_play_utils.get_transcoding_video_codec()
|
result_2 = mock_play_utils.get_transcoding_video_codec()
|
||||||
|
|
||||||
# Assertions
|
# Assertions
|
||||||
assert "hevc" not in result_1, "HEVC should not be in codec list when Transcode HEVC is disabled"
|
assert (
|
||||||
assert "hevc" in result_2, "HEVC should be in codec list when Transcode HEVC is enabled"
|
"hevc" not in result_1
|
||||||
|
), "HEVC should not be in codec list when Transcode HEVC is disabled"
|
||||||
|
assert (
|
||||||
|
"hevc" in result_2
|
||||||
|
), "HEVC should be in codec list when Transcode HEVC is enabled"
|
||||||
|
|
||||||
# Ensure other codecs are present in both scenarios
|
# Ensure other codecs are present in both scenarios
|
||||||
for codec in ["h264", "mpeg4", "mpeg2video", "vc1"]:
|
for codec in ["h264", "mpeg4", "mpeg2video", "vc1"]:
|
||||||
assert codec in result_1, f"{codec} should be in codec list regardless of HEVC setting"
|
assert (
|
||||||
assert codec in result_2, f"{codec} should be in codec list regardless of HEVC setting"
|
codec in result_1
|
||||||
|
), f"{codec} should be in codec list regardless of HEVC setting"
|
||||||
|
assert (
|
||||||
|
codec in result_2
|
||||||
|
), f"{codec} should be in codec list regardless of HEVC setting"
|
||||||
|
|
||||||
# Ensure the order is correct in both scenarios
|
# Ensure the order is correct in both scenarios
|
||||||
assert result_1 == "h264,mpeg4,mpeg2video,vc1", "Codec order incorrect when HEVC is disabled"
|
assert (
|
||||||
assert result_2 == "h264,mpeg4,mpeg2video,vc1,hevc", "Codec order incorrect when HEVC is enabled"
|
result_1 == "h264,mpeg4,mpeg2video,vc1"
|
||||||
|
), "Codec order incorrect when HEVC is disabled"
|
||||||
|
assert (
|
||||||
|
result_2 == "h264,mpeg4,mpeg2video,vc1,hevc"
|
||||||
|
), "Codec order incorrect when HEVC is enabled"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("transcode_h265, preferred_codec, expected_result", [
|
@pytest.mark.parametrize(
|
||||||
|
"transcode_h265, preferred_codec, expected_result",
|
||||||
|
[
|
||||||
(False, "", "h264,mpeg4,mpeg2video,vc1,hevc"),
|
(False, "", "h264,mpeg4,mpeg2video,vc1,hevc"),
|
||||||
(True, "", "h264,mpeg4,mpeg2video,vc1"),
|
(True, "", "h264,mpeg4,mpeg2video,vc1"),
|
||||||
(False, "H265/HEVC", "hevc,h264,mpeg4,mpeg2video,vc1"),
|
(False, "H265/HEVC", "hevc,h264,mpeg4,mpeg2video,vc1"),
|
||||||
|
@ -56,38 +74,53 @@ def test_hevc_transcoding_scenario(mock_play_utils):
|
||||||
(True, "H264", "h264,mpeg4,mpeg2video,vc1"),
|
(True, "H264", "h264,mpeg4,mpeg2video,vc1"),
|
||||||
(False, "MPEG4", "mpeg4,h264,mpeg2video,vc1,hevc"),
|
(False, "MPEG4", "mpeg4,h264,mpeg2video,vc1,hevc"),
|
||||||
(True, "MPEG4", "mpeg4,h264,mpeg2video,vc1"),
|
(True, "MPEG4", "mpeg4,h264,mpeg2video,vc1"),
|
||||||
])
|
],
|
||||||
def test_get_transcoding_video_codec_settings(mock_play_utils, transcode_h265, preferred_codec, expected_result):
|
)
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
def test_get_transcoding_video_codec_settings(
|
||||||
|
mock_play_utils, transcode_h265, preferred_codec, expected_result
|
||||||
|
):
|
||||||
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [transcode_h265, preferred_codec]
|
mock_settings.side_effect = [transcode_h265, preferred_codec]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = expected_result
|
mock_play_utils.get_transcoding_video_codec.return_value = expected_result
|
||||||
result = mock_play_utils.get_transcoding_video_codec()
|
result = mock_play_utils.get_transcoding_video_codec()
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("transcode_mpeg2, transcode_vc1, expected_result", [
|
@pytest.mark.parametrize(
|
||||||
|
"transcode_mpeg2, transcode_vc1, expected_result",
|
||||||
|
[
|
||||||
(False, False, "h264,mpeg4,mpeg2video,vc1,hevc"),
|
(False, False, "h264,mpeg4,mpeg2video,vc1,hevc"),
|
||||||
(True, False, "h264,mpeg4,vc1,hevc"),
|
(True, False, "h264,mpeg4,vc1,hevc"),
|
||||||
(False, True, "h264,mpeg4,mpeg2video,hevc"),
|
(False, True, "h264,mpeg4,mpeg2video,hevc"),
|
||||||
(True, True, "h264,mpeg4,hevc"),
|
(True, True, "h264,mpeg4,hevc"),
|
||||||
])
|
],
|
||||||
def test_get_transcoding_video_codec_transcode_options(mock_play_utils, transcode_mpeg2, transcode_vc1, expected_result):
|
)
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
def test_get_transcoding_video_codec_transcode_options(
|
||||||
|
mock_play_utils, transcode_mpeg2, transcode_vc1, expected_result
|
||||||
|
):
|
||||||
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [False, "", transcode_mpeg2, transcode_vc1]
|
mock_settings.side_effect = [False, "", transcode_mpeg2, transcode_vc1]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = expected_result
|
mock_play_utils.get_transcoding_video_codec.return_value = expected_result
|
||||||
result = mock_play_utils.get_transcoding_video_codec()
|
result = mock_play_utils.get_transcoding_video_codec()
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("preferred_codec, expected_first, expected_second", [
|
@pytest.mark.parametrize(
|
||||||
|
"preferred_codec, expected_first, expected_second",
|
||||||
|
[
|
||||||
("H265/HEVC", "hevc", "h264"),
|
("H265/HEVC", "hevc", "h264"),
|
||||||
("H264", "h264", "hevc"),
|
("H264", "h264", "hevc"),
|
||||||
("MPEG4", "mpeg4", "h264"),
|
("MPEG4", "mpeg4", "h264"),
|
||||||
])
|
],
|
||||||
def test_get_transcoding_video_codec_order(mock_play_utils, preferred_codec, expected_first, expected_second):
|
)
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
def test_get_transcoding_video_codec_order(
|
||||||
|
mock_play_utils, preferred_codec, expected_first, expected_second
|
||||||
|
):
|
||||||
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [False, preferred_codec]
|
mock_settings.side_effect = [False, preferred_codec]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = f"{expected_first},{expected_second},mpeg2video,vc1"
|
mock_play_utils.get_transcoding_video_codec.return_value = (
|
||||||
|
f"{expected_first},{expected_second},mpeg2video,vc1"
|
||||||
|
)
|
||||||
result = mock_play_utils.get_transcoding_video_codec()
|
result = mock_play_utils.get_transcoding_video_codec()
|
||||||
assert result.startswith(expected_first)
|
assert result.startswith(expected_first)
|
||||||
assert expected_second in result
|
assert expected_second in result
|
||||||
|
@ -95,9 +128,11 @@ def test_get_transcoding_video_codec_order(mock_play_utils, preferred_codec, exp
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_video_codec_no_duplicates(mock_play_utils):
|
def test_get_transcoding_video_codec_no_duplicates(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [False, ""]
|
mock_settings.side_effect = [False, ""]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = "h264,mpeg4,mpeg2video,vc1,hevc"
|
mock_play_utils.get_transcoding_video_codec.return_value = (
|
||||||
|
"h264,mpeg4,mpeg2video,vc1,hevc"
|
||||||
|
)
|
||||||
result = mock_play_utils.get_transcoding_video_codec()
|
result = mock_play_utils.get_transcoding_video_codec()
|
||||||
assert result.count("hevc") == 1
|
assert result.count("hevc") == 1
|
||||||
assert result.count("h264") == 1
|
assert result.count("h264") == 1
|
||||||
|
@ -107,7 +142,7 @@ def test_get_transcoding_video_codec_no_duplicates(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_video_codec_empty_result(mock_play_utils):
|
def test_get_transcoding_video_codec_empty_result(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [True, ""]
|
mock_settings.side_effect = [True, ""]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = ""
|
mock_play_utils.get_transcoding_video_codec.return_value = ""
|
||||||
result = mock_play_utils.get_transcoding_video_codec()
|
result = mock_play_utils.get_transcoding_video_codec()
|
||||||
|
@ -115,7 +150,7 @@ def test_get_transcoding_video_codec_empty_result(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_video_codec_single_codec(mock_play_utils):
|
def test_get_transcoding_video_codec_single_codec(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [True, "H264"]
|
mock_settings.side_effect = [True, "H264"]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = "h264"
|
mock_play_utils.get_transcoding_video_codec.return_value = "h264"
|
||||||
result = mock_play_utils.get_transcoding_video_codec()
|
result = mock_play_utils.get_transcoding_video_codec()
|
||||||
|
@ -123,27 +158,46 @@ def test_get_transcoding_video_codec_single_codec(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_video_codec_unknown_preferred(mock_play_utils):
|
def test_get_transcoding_video_codec_unknown_preferred(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [False, "UNKNOWN"]
|
mock_settings.side_effect = [False, "UNKNOWN"]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = "h264,mpeg4,mpeg2video,vc1,hevc"
|
mock_play_utils.get_transcoding_video_codec.return_value = (
|
||||||
|
"h264,mpeg4,mpeg2video,vc1,hevc"
|
||||||
|
)
|
||||||
result = mock_play_utils.get_transcoding_video_codec()
|
result = mock_play_utils.get_transcoding_video_codec()
|
||||||
assert result == "h264,mpeg4,mpeg2video,vc1,hevc"
|
assert result == "h264,mpeg4,mpeg2video,vc1,hevc"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("transcode_h265, preferred_codec, transcode_mpeg2, transcode_vc1, expected_result", [
|
@pytest.mark.parametrize(
|
||||||
|
"transcode_h265, preferred_codec, transcode_mpeg2, transcode_vc1, expected_result",
|
||||||
|
[
|
||||||
(True, "H264", True, True, "h264,mpeg4"),
|
(True, "H264", True, True, "h264,mpeg4"),
|
||||||
(False, "H265/HEVC", False, False, "hevc,h264,mpeg4,mpeg2video,vc1"),
|
(False, "H265/HEVC", False, False, "hevc,h264,mpeg4,mpeg2video,vc1"),
|
||||||
(True, "MPEG4", True, False, "mpeg4,h264,vc1"),
|
(True, "MPEG4", True, False, "mpeg4,h264,vc1"),
|
||||||
])
|
],
|
||||||
def test_get_transcoding_video_codec_combined_settings(mock_play_utils, transcode_h265, preferred_codec, transcode_mpeg2, transcode_vc1, expected_result):
|
)
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
def test_get_transcoding_video_codec_combined_settings(
|
||||||
mock_settings.side_effect = [transcode_h265, preferred_codec, transcode_mpeg2, transcode_vc1]
|
mock_play_utils,
|
||||||
|
transcode_h265,
|
||||||
|
preferred_codec,
|
||||||
|
transcode_mpeg2,
|
||||||
|
transcode_vc1,
|
||||||
|
expected_result,
|
||||||
|
):
|
||||||
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
|
mock_settings.side_effect = [
|
||||||
|
transcode_h265,
|
||||||
|
preferred_codec,
|
||||||
|
transcode_mpeg2,
|
||||||
|
transcode_vc1,
|
||||||
|
]
|
||||||
mock_play_utils.get_transcoding_video_codec.return_value = expected_result
|
mock_play_utils.get_transcoding_video_codec.return_value = expected_result
|
||||||
result = mock_play_utils.get_transcoding_video_codec()
|
result = mock_play_utils.get_transcoding_video_codec()
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("transcode_h265, preferred_codec, expected_result", [
|
@pytest.mark.parametrize(
|
||||||
|
"transcode_h265, preferred_codec, expected_result",
|
||||||
|
[
|
||||||
(False, "", "h264,mpeg4,mpeg2video,vc1,hevc"),
|
(False, "", "h264,mpeg4,mpeg2video,vc1,hevc"),
|
||||||
(True, "", "h264,mpeg4,mpeg2video,vc1"),
|
(True, "", "h264,mpeg4,mpeg2video,vc1"),
|
||||||
(False, "H265/HEVC", "hevc,h264,mpeg4,mpeg2video,vc1"),
|
(False, "H265/HEVC", "hevc,h264,mpeg4,mpeg2video,vc1"),
|
||||||
|
@ -152,23 +206,31 @@ def test_get_transcoding_video_codec_combined_settings(mock_play_utils, transcod
|
||||||
(True, "H264", "h264,mpeg4,mpeg2video,vc1"),
|
(True, "H264", "h264,mpeg4,mpeg2video,vc1"),
|
||||||
(False, "MPEG4", "mpeg4,h264,mpeg2video,vc1,hevc"),
|
(False, "MPEG4", "mpeg4,h264,mpeg2video,vc1,hevc"),
|
||||||
(True, "MPEG4", "mpeg4,h264,mpeg2video,vc1"),
|
(True, "MPEG4", "mpeg4,h264,mpeg2video,vc1"),
|
||||||
])
|
],
|
||||||
def test_get_directplay_video_codec(mock_play_utils, transcode_h265, preferred_codec, expected_result):
|
)
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
def test_get_directplay_video_codec(
|
||||||
|
mock_play_utils, transcode_h265, preferred_codec, expected_result
|
||||||
|
):
|
||||||
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [transcode_h265, preferred_codec]
|
mock_settings.side_effect = [transcode_h265, preferred_codec]
|
||||||
mock_play_utils.get_directplay_video_codec.return_value = expected_result
|
mock_play_utils.get_directplay_video_codec.return_value = expected_result
|
||||||
result = mock_play_utils.get_directplay_video_codec()
|
result = mock_play_utils.get_directplay_video_codec()
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("transcode_mpeg2, transcode_vc1, expected_result", [
|
@pytest.mark.parametrize(
|
||||||
|
"transcode_mpeg2, transcode_vc1, expected_result",
|
||||||
|
[
|
||||||
(False, False, "h264,mpeg4,mpeg2video,vc1,hevc"),
|
(False, False, "h264,mpeg4,mpeg2video,vc1,hevc"),
|
||||||
(True, False, "h264,mpeg4,vc1,hevc"),
|
(True, False, "h264,mpeg4,vc1,hevc"),
|
||||||
(False, True, "h264,mpeg4,mpeg2video,hevc"),
|
(False, True, "h264,mpeg4,mpeg2video,hevc"),
|
||||||
(True, True, "h264,mpeg4,hevc"),
|
(True, True, "h264,mpeg4,hevc"),
|
||||||
])
|
],
|
||||||
def test_get_directplay_video_codec_transcode_options(mock_play_utils, transcode_mpeg2, transcode_vc1, expected_result):
|
)
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
def test_get_directplay_video_codec_transcode_options(
|
||||||
|
mock_play_utils, transcode_mpeg2, transcode_vc1, expected_result
|
||||||
|
):
|
||||||
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [False, "", transcode_mpeg2, transcode_vc1]
|
mock_settings.side_effect = [False, "", transcode_mpeg2, transcode_vc1]
|
||||||
mock_play_utils.get_directplay_video_codec.return_value = expected_result
|
mock_play_utils.get_directplay_video_codec.return_value = expected_result
|
||||||
result = mock_play_utils.get_directplay_video_codec()
|
result = mock_play_utils.get_directplay_video_codec()
|
||||||
|
@ -176,9 +238,11 @@ def test_get_directplay_video_codec_transcode_options(mock_play_utils, transcode
|
||||||
|
|
||||||
|
|
||||||
def test_get_directplay_video_codec_no_duplicates(mock_play_utils):
|
def test_get_directplay_video_codec_no_duplicates(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [False, ""]
|
mock_settings.side_effect = [False, ""]
|
||||||
mock_play_utils.get_directplay_video_codec.return_value = "h264,mpeg4,mpeg2video,vc1,hevc"
|
mock_play_utils.get_directplay_video_codec.return_value = (
|
||||||
|
"h264,mpeg4,mpeg2video,vc1,hevc"
|
||||||
|
)
|
||||||
result = mock_play_utils.get_directplay_video_codec()
|
result = mock_play_utils.get_directplay_video_codec()
|
||||||
assert result.count("hevc") == 1
|
assert result.count("hevc") == 1
|
||||||
assert result.count("h264") == 1
|
assert result.count("h264") == 1
|
||||||
|
@ -188,7 +252,7 @@ def test_get_directplay_video_codec_no_duplicates(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_directplay_video_codec_empty_result(mock_play_utils):
|
def test_get_directplay_video_codec_empty_result(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [True, ""]
|
mock_settings.side_effect = [True, ""]
|
||||||
mock_play_utils.get_directplay_video_codec.return_value = ""
|
mock_play_utils.get_directplay_video_codec.return_value = ""
|
||||||
result = mock_play_utils.get_directplay_video_codec()
|
result = mock_play_utils.get_directplay_video_codec()
|
||||||
|
@ -196,7 +260,7 @@ def test_get_directplay_video_codec_empty_result(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_directplay_video_codec_single_codec(mock_play_utils):
|
def test_get_directplay_video_codec_single_codec(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [True, "H264"]
|
mock_settings.side_effect = [True, "H264"]
|
||||||
mock_play_utils.get_directplay_video_codec.return_value = "h264"
|
mock_play_utils.get_directplay_video_codec.return_value = "h264"
|
||||||
result = mock_play_utils.get_directplay_video_codec()
|
result = mock_play_utils.get_directplay_video_codec()
|
||||||
|
@ -204,27 +268,46 @@ def test_get_directplay_video_codec_single_codec(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_directplay_video_codec_unknown_preferred(mock_play_utils):
|
def test_get_directplay_video_codec_unknown_preferred(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = [False, "UNKNOWN"]
|
mock_settings.side_effect = [False, "UNKNOWN"]
|
||||||
mock_play_utils.get_directplay_video_codec.return_value = "h264,mpeg4,mpeg2video,vc1,hevc"
|
mock_play_utils.get_directplay_video_codec.return_value = (
|
||||||
|
"h264,mpeg4,mpeg2video,vc1,hevc"
|
||||||
|
)
|
||||||
result = mock_play_utils.get_directplay_video_codec()
|
result = mock_play_utils.get_directplay_video_codec()
|
||||||
assert result == "h264,mpeg4,mpeg2video,vc1,hevc"
|
assert result == "h264,mpeg4,mpeg2video,vc1,hevc"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("transcode_h265, preferred_codec, transcode_mpeg2, transcode_vc1, expected_result", [
|
@pytest.mark.parametrize(
|
||||||
|
"transcode_h265, preferred_codec, transcode_mpeg2, transcode_vc1, expected_result",
|
||||||
|
[
|
||||||
(True, "H264", True, True, "h264,mpeg4"),
|
(True, "H264", True, True, "h264,mpeg4"),
|
||||||
(False, "H265/HEVC", False, False, "hevc,h264,mpeg4,mpeg2video,vc1"),
|
(False, "H265/HEVC", False, False, "hevc,h264,mpeg4,mpeg2video,vc1"),
|
||||||
(True, "MPEG4", True, False, "mpeg4,h264,vc1"),
|
(True, "MPEG4", True, False, "mpeg4,h264,vc1"),
|
||||||
])
|
],
|
||||||
def test_get_directplay_video_codec_combined_settings(mock_play_utils, transcode_h265, preferred_codec, transcode_mpeg2, transcode_vc1, expected_result):
|
)
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
def test_get_directplay_video_codec_combined_settings(
|
||||||
mock_settings.side_effect = [transcode_h265, preferred_codec, transcode_mpeg2, transcode_vc1]
|
mock_play_utils,
|
||||||
|
transcode_h265,
|
||||||
|
preferred_codec,
|
||||||
|
transcode_mpeg2,
|
||||||
|
transcode_vc1,
|
||||||
|
expected_result,
|
||||||
|
):
|
||||||
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
|
mock_settings.side_effect = [
|
||||||
|
transcode_h265,
|
||||||
|
preferred_codec,
|
||||||
|
transcode_mpeg2,
|
||||||
|
transcode_vc1,
|
||||||
|
]
|
||||||
mock_play_utils.get_directplay_video_codec.return_value = expected_result
|
mock_play_utils.get_directplay_video_codec.return_value = expected_result
|
||||||
result = mock_play_utils.get_directplay_video_codec()
|
result = mock_play_utils.get_directplay_video_codec()
|
||||||
assert result == expected_result
|
assert result == expected_result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("preferred_codec, expected_result", [
|
@pytest.mark.parametrize(
|
||||||
|
"preferred_codec, expected_result",
|
||||||
|
[
|
||||||
("", "aac,mp3,ac3,opus,flac,vorbis"),
|
("", "aac,mp3,ac3,opus,flac,vorbis"),
|
||||||
("AAC", "aac,mp3,ac3,opus,flac,vorbis"),
|
("AAC", "aac,mp3,ac3,opus,flac,vorbis"),
|
||||||
("MP3", "mp3,aac,ac3,opus,flac,vorbis"),
|
("MP3", "mp3,aac,ac3,opus,flac,vorbis"),
|
||||||
|
@ -233,9 +316,10 @@ def test_get_directplay_video_codec_combined_settings(mock_play_utils, transcode
|
||||||
("FLAC", "flac,aac,mp3,ac3,opus,vorbis"),
|
("FLAC", "flac,aac,mp3,ac3,opus,vorbis"),
|
||||||
("VORBIS", "vorbis,aac,mp3,ac3,opus,flac"),
|
("VORBIS", "vorbis,aac,mp3,ac3,opus,flac"),
|
||||||
("UNKNOWN", "aac,mp3,ac3,opus,flac,vorbis"),
|
("UNKNOWN", "aac,mp3,ac3,opus,flac,vorbis"),
|
||||||
])
|
],
|
||||||
|
)
|
||||||
def test_get_transcoding_audio_codec(mock_play_utils, preferred_codec, expected_result):
|
def test_get_transcoding_audio_codec(mock_play_utils, preferred_codec, expected_result):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.return_value = preferred_codec
|
mock_settings.return_value = preferred_codec
|
||||||
mock_play_utils.get_transcoding_audio_codec.return_value = expected_result
|
mock_play_utils.get_transcoding_audio_codec.return_value = expected_result
|
||||||
result = mock_play_utils.get_transcoding_audio_codec()
|
result = mock_play_utils.get_transcoding_audio_codec()
|
||||||
|
@ -243,17 +327,21 @@ def test_get_transcoding_audio_codec(mock_play_utils, preferred_codec, expected_
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_audio_codec_case_insensitive(mock_play_utils):
|
def test_get_transcoding_audio_codec_case_insensitive(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.return_value = "aAc"
|
mock_settings.return_value = "aAc"
|
||||||
mock_play_utils.get_transcoding_audio_codec.return_value = "aac,mp3,ac3,opus,flac,vorbis"
|
mock_play_utils.get_transcoding_audio_codec.return_value = (
|
||||||
|
"aac,mp3,ac3,opus,flac,vorbis"
|
||||||
|
)
|
||||||
result = mock_play_utils.get_transcoding_audio_codec()
|
result = mock_play_utils.get_transcoding_audio_codec()
|
||||||
assert result == "aac,mp3,ac3,opus,flac,vorbis"
|
assert result == "aac,mp3,ac3,opus,flac,vorbis"
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_audio_codec_no_duplicates(mock_play_utils):
|
def test_get_transcoding_audio_codec_no_duplicates(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.return_value = ""
|
mock_settings.return_value = ""
|
||||||
mock_play_utils.get_transcoding_audio_codec.return_value = "aac,mp3,ac3,opus,flac,vorbis"
|
mock_play_utils.get_transcoding_audio_codec.return_value = (
|
||||||
|
"aac,mp3,ac3,opus,flac,vorbis"
|
||||||
|
)
|
||||||
result = mock_play_utils.get_transcoding_audio_codec()
|
result = mock_play_utils.get_transcoding_audio_codec()
|
||||||
assert result.count("aac") == 1
|
assert result.count("aac") == 1
|
||||||
assert result.count("mp3") == 1
|
assert result.count("mp3") == 1
|
||||||
|
@ -264,7 +352,7 @@ def test_get_transcoding_audio_codec_no_duplicates(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_audio_codec_empty_result(mock_play_utils):
|
def test_get_transcoding_audio_codec_empty_result(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.return_value = ""
|
mock_settings.return_value = ""
|
||||||
mock_play_utils.get_transcoding_audio_codec.return_value = ""
|
mock_play_utils.get_transcoding_audio_codec.return_value = ""
|
||||||
result = mock_play_utils.get_transcoding_audio_codec()
|
result = mock_play_utils.get_transcoding_audio_codec()
|
||||||
|
@ -272,7 +360,7 @@ def test_get_transcoding_audio_codec_empty_result(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_audio_codec_single_codec(mock_play_utils):
|
def test_get_transcoding_audio_codec_single_codec(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.return_value = "AAC"
|
mock_settings.return_value = "AAC"
|
||||||
mock_play_utils.get_transcoding_audio_codec.return_value = "aac"
|
mock_play_utils.get_transcoding_audio_codec.return_value = "aac"
|
||||||
result = mock_play_utils.get_transcoding_audio_codec()
|
result = mock_play_utils.get_transcoding_audio_codec()
|
||||||
|
@ -280,20 +368,22 @@ def test_get_transcoding_audio_codec_single_codec(mock_play_utils):
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_audio_codec_preserve_order(mock_play_utils):
|
def test_get_transcoding_audio_codec_preserve_order(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.return_value = ""
|
mock_settings.return_value = ""
|
||||||
mock_play_utils.get_transcoding_audio_codec.return_value = "aac,mp3,ac3,opus,flac,vorbis"
|
mock_play_utils.get_transcoding_audio_codec.return_value = (
|
||||||
|
"aac,mp3,ac3,opus,flac,vorbis"
|
||||||
|
)
|
||||||
result = mock_play_utils.get_transcoding_audio_codec()
|
result = mock_play_utils.get_transcoding_audio_codec()
|
||||||
assert result == "aac,mp3,ac3,opus,flac,vorbis"
|
assert result == "aac,mp3,ac3,opus,flac,vorbis"
|
||||||
|
|
||||||
|
|
||||||
def test_get_transcoding_audio_codec_multiple_calls(mock_play_utils):
|
def test_get_transcoding_audio_codec_multiple_calls(mock_play_utils):
|
||||||
with patch('jellyfin_kodi.helper.playutils.settings') as mock_settings:
|
with patch("jellyfin_kodi.helper.playutils.settings") as mock_settings:
|
||||||
mock_settings.side_effect = ["AAC", "MP3", "FLAC"]
|
mock_settings.side_effect = ["AAC", "MP3", "FLAC"]
|
||||||
mock_play_utils.get_transcoding_audio_codec.side_effect = [
|
mock_play_utils.get_transcoding_audio_codec.side_effect = [
|
||||||
"aac,mp3,ac3,opus,flac,vorbis",
|
"aac,mp3,ac3,opus,flac,vorbis",
|
||||||
"mp3,aac,ac3,opus,flac,vorbis",
|
"mp3,aac,ac3,opus,flac,vorbis",
|
||||||
"flac,aac,mp3,ac3,opus,vorbis"
|
"flac,aac,mp3,ac3,opus,vorbis",
|
||||||
]
|
]
|
||||||
result1 = mock_play_utils.get_transcoding_audio_codec()
|
result1 = mock_play_utils.get_transcoding_audio_codec()
|
||||||
result2 = mock_play_utils.get_transcoding_audio_codec()
|
result2 = mock_play_utils.get_transcoding_audio_codec()
|
||||||
|
|
Loading…
Reference in a new issue