diff --git a/src/ffmpeg/common/schema.py b/src/ffmpeg/common/schema.py index e8dfb673..fc7970c8 100644 --- a/src/ffmpeg/common/schema.py +++ b/src/ffmpeg/common/schema.py @@ -107,6 +107,7 @@ class FFMpegFilter: formula_typings_input: str | None = None formula_typings_output: str | None = None + pre: tuple[tuple[str, str], ...] = () options: tuple[FFMpegFilterOption, ...] = () @property diff --git a/src/scripts/cache.py b/src/scripts/cache.py index 2b7178b5..63f11f4a 100644 --- a/src/scripts/cache.py +++ b/src/scripts/cache.py @@ -23,3 +23,9 @@ def save(obj: T, id: str) -> None: with (schema_path / f"{id}.json").open("w") as ofile: ofile.write(dumps(obj)) + + +def list_all(cls: type[T]) -> list[T]: + path = cache_path / f"{cls.__name__}" + + return [loads(i.read_text()) for i in path.glob("*.json")] diff --git a/src/scripts/manual/schema.py b/src/scripts/manual/schema.py index c258a5a9..1cc2dc4f 100644 --- a/src/scripts/manual/schema.py +++ b/src/scripts/manual/schema.py @@ -1,6 +1,12 @@ from dataclasses import dataclass +@dataclass(kw_only=True, frozen=True) +class FFMpegFilterManuallyDefinedHook: + name: str + function: str + + @dataclass(kw_only=True) class FFMpegFilterManuallyDefined: name: str @@ -8,4 +14,4 @@ class FFMpegFilterManuallyDefined: formula_typings_input: str | None = None formula_typings_output: str | None = None - pre: dict[str, str] = {} + pre: tuple[tuple[str, str], ...] = () diff --git a/src/scripts/tests/__snapshots__/test_cache.ambr b/src/scripts/tests/__snapshots__/test_cache.ambr new file mode 100644 index 00000000..2c80fb1c --- /dev/null +++ b/src/scripts/tests/__snapshots__/test_cache.ambr @@ -0,0 +1,6 @@ +# serializer version: 1 +# name: test_save_and_load + list([ + FFMpegFilter(id=None, name='foo', description='bar', ref=None, is_support_slice_threading=None, is_support_timeline=None, is_support_framesync=None, is_support_command=None, is_filter_sink=None, is_filter_source=None, is_dynamic_input=False, is_dynamic_output=False, stream_typings_input=(), stream_typings_output=(), formula_typings_input=None, formula_typings_output=None, pre=(), options=()), + ]) +# --- diff --git a/src/scripts/tests/test_cache.py b/src/scripts/tests/test_cache.py index aa78a6b5..3eae55cf 100644 --- a/src/scripts/tests/test_cache.py +++ b/src/scripts/tests/test_cache.py @@ -1,10 +1,14 @@ +from syrupy.assertion import SnapshotAssertion + from ffmpeg.common.schema import FFMpegFilter -from ..cache import load, save +from ..cache import list_all, load, save -def test_save_and_load() -> None: +def test_save_and_load(snapshot: SnapshotAssertion) -> None: ffmpeg_filter = FFMpegFilter(name="foo", description="bar") save(ffmpeg_filter, ffmpeg_filter.name) assert load(FFMpegFilter, ffmpeg_filter.name) == ffmpeg_filter + + assert snapshot == list_all(FFMpegFilter)