Misc Opts
This commit is contained in:
@@ -99,6 +99,43 @@ class CliLazyImportTests(unittest.TestCase):
|
||||
result["modules"],
|
||||
)
|
||||
|
||||
def test_lightweight_setup_command_stays_light(self):
|
||||
result = self.run_python(
|
||||
textwrap.dedent(
|
||||
f"""
|
||||
import json
|
||||
import sys
|
||||
from click.testing import CliRunner
|
||||
|
||||
sys.path.insert(0, {str(SRC_ROOT)!r})
|
||||
|
||||
import ffx.cli
|
||||
|
||||
runner = CliRunner()
|
||||
invoke_result = runner.invoke(
|
||||
ffx.cli.ffx,
|
||||
["--dry-run", "setup", "--check", "--with-tests"],
|
||||
)
|
||||
if invoke_result.exit_code != 0:
|
||||
raise SystemExit(invoke_result.output)
|
||||
|
||||
print(json.dumps({{
|
||||
"output": invoke_result.output,
|
||||
"modules": {{
|
||||
module_name: module_name in sys.modules
|
||||
for module_name in {HEAVY_MODULES!r}
|
||||
}},
|
||||
}}))
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self.assertIn("tools/setup.sh --check --with-tests", result["output"])
|
||||
self.assertTrue(
|
||||
all(not is_loaded for is_loaded in result["modules"].values()),
|
||||
result["modules"],
|
||||
)
|
||||
|
||||
def test_convert_help_describes_absolute_and_percent_cpu_limits(self):
|
||||
result = self.run_python(
|
||||
textwrap.dedent(
|
||||
|
||||
@@ -4,6 +4,7 @@ import json
|
||||
import logging
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -106,6 +107,69 @@ class FilePropertiesProbeTests(unittest.TestCase):
|
||||
+ ["/tmp/example_s01e01.mkv"]
|
||||
)
|
||||
|
||||
def test_cropdetect_uses_configured_window_and_caches_results(self):
|
||||
file_properties_module = self.import_module()
|
||||
file_properties_module.FileProperties._clear_cropdetect_cache()
|
||||
|
||||
cropdetect_stderr = "\n".join(
|
||||
[
|
||||
"[Parsed_cropdetect_0] crop=1440:1080:240:0",
|
||||
"[Parsed_cropdetect_0] crop=1440:1080:240:0",
|
||||
"[Parsed_cropdetect_0] crop=1438:1080:242:0",
|
||||
]
|
||||
)
|
||||
context = self.make_context()
|
||||
context["cropdetect"] = {"seek_seconds": 15, "duration_seconds": 45}
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
file_properties_module.os,
|
||||
"stat",
|
||||
return_value=SimpleNamespace(st_mtime_ns=1234, st_size=5678),
|
||||
),
|
||||
patch.object(file_properties_module, "PatternController", DummyPatternController),
|
||||
patch.object(
|
||||
file_properties_module,
|
||||
"executeProcess",
|
||||
return_value=("", cropdetect_stderr, 0),
|
||||
) as mocked_execute,
|
||||
):
|
||||
file_properties = file_properties_module.FileProperties(
|
||||
context,
|
||||
"/tmp/example_s01e01.mkv",
|
||||
)
|
||||
|
||||
first = file_properties.findCropArguments()
|
||||
second = file_properties.findCropArguments()
|
||||
|
||||
self.assertEqual(first, second)
|
||||
self.assertEqual(
|
||||
{
|
||||
"output_width": "1440",
|
||||
"output_height": "1080",
|
||||
"x_offset": "240",
|
||||
"y_offset": "0",
|
||||
},
|
||||
first,
|
||||
)
|
||||
mocked_execute.assert_called_once_with(
|
||||
list(file_properties_module.FFMPEG_COMMAND_TOKENS)
|
||||
+ [
|
||||
"-ss",
|
||||
"15",
|
||||
"-i",
|
||||
"/tmp/example_s01e01.mkv",
|
||||
"-t",
|
||||
"45",
|
||||
"-vf",
|
||||
"cropdetect",
|
||||
]
|
||||
+ list(file_properties_module.FFMPEG_NULL_OUTPUT_TOKENS),
|
||||
context=context,
|
||||
)
|
||||
|
||||
file_properties_module.FileProperties._clear_cropdetect_cache()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
86
tests/unit/test_screen_support.py
Normal file
86
tests/unit/test_screen_support.py
Normal file
@@ -0,0 +1,86 @@
|
||||
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 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,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user