128 lines
3.7 KiB
Python
128 lines
3.7 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
|
|
SRC_ROOT = Path(__file__).resolve().parents[2] / "src"
|
|
|
|
if str(SRC_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(SRC_ROOT))
|
|
|
|
|
|
from ffx import screen_support # noqa: E402
|
|
|
|
|
|
class StaticConfig:
|
|
def __init__(self, data):
|
|
self._data = data
|
|
|
|
def getData(self):
|
|
return self._data
|
|
|
|
|
|
class FakeTagTable:
|
|
def __init__(self):
|
|
self.rows = {}
|
|
self._next_index = 0
|
|
|
|
def clear(self):
|
|
self.rows.clear()
|
|
|
|
def add_row(self, *values):
|
|
row_key = f"row-{self._next_index}"
|
|
self._next_index += 1
|
|
self.rows[row_key] = tuple(values)
|
|
return row_key
|
|
|
|
|
|
class ScreenSupportTests(unittest.TestCase):
|
|
def make_context(self):
|
|
return {
|
|
"config": StaticConfig(
|
|
{
|
|
"metadata": {
|
|
"signature": {"RECODED_WITH": "FFX"},
|
|
"remove": ["VERSION-eng"],
|
|
"ignore": ["ENCODER"],
|
|
"streams": {
|
|
"remove": ["BPS"],
|
|
"ignore": ["language"],
|
|
},
|
|
}
|
|
}
|
|
),
|
|
"database": {"session": object()},
|
|
}
|
|
|
|
def test_build_screen_bootstrap_extracts_metadata_filters(self):
|
|
context = self.make_context()
|
|
|
|
bootstrap = screen_support.build_screen_bootstrap(context)
|
|
|
|
self.assertIs(context, bootstrap.context)
|
|
self.assertEqual({"RECODED_WITH": "FFX"}, bootstrap.signature_tags)
|
|
self.assertEqual(["VERSION-eng"], bootstrap.remove_global_keys)
|
|
self.assertEqual(["ENCODER"], bootstrap.ignore_global_keys)
|
|
self.assertEqual(["BPS"], bootstrap.remove_track_keys)
|
|
self.assertEqual(["language"], bootstrap.ignore_track_keys)
|
|
|
|
def test_build_screen_controllers_only_creates_requested_instances(self):
|
|
context = self.make_context()
|
|
|
|
with (
|
|
patch.object(screen_support, "PatternController", side_effect=lambda context: ("pattern", context)),
|
|
patch.object(screen_support, "ShowController", side_effect=lambda context: ("show", context)),
|
|
patch.object(screen_support, "TmdbController", side_effect=lambda: "tmdb"),
|
|
patch.object(screen_support, "ShiftedSeasonController", side_effect=lambda context: ("shifted", context)),
|
|
):
|
|
controllers = screen_support.build_screen_controllers(
|
|
context,
|
|
pattern=True,
|
|
show=True,
|
|
tmdb=True,
|
|
shifted_season=True,
|
|
)
|
|
|
|
self.assertEqual(
|
|
{
|
|
"pattern": ("pattern", context),
|
|
"show": ("show", context),
|
|
"tmdb": "tmdb",
|
|
"shifted_season": ("shifted", context),
|
|
},
|
|
controllers,
|
|
)
|
|
|
|
def test_populate_tag_table_keeps_raw_values_outside_display_labels(self):
|
|
table = FakeTagTable()
|
|
|
|
row_data = screen_support.populate_tag_table(
|
|
table,
|
|
{"BPS": 4835, "KEEP": "plain"},
|
|
ignore_keys=["KEEP"],
|
|
remove_keys=["BPS"],
|
|
)
|
|
|
|
self.assertEqual(
|
|
{
|
|
"row-0": ("BPS", "4835"),
|
|
"row-1": ("KEEP", "plain"),
|
|
},
|
|
row_data,
|
|
)
|
|
self.assertEqual(
|
|
("[red]BPS[/red]", "[red]4835[/red]"),
|
|
table.rows["row-0"],
|
|
)
|
|
self.assertEqual(
|
|
("[blue]KEEP[/blue]", "[blue]plain[/blue]"),
|
|
table.rows["row-1"],
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|