Skip to content

Commit

Permalink
add list-all utils in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemia committed Mar 15, 2024
1 parent 122c1b4 commit 07b2cc8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ffmpeg/common/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
8 changes: 7 additions & 1 deletion src/scripts/manual/schema.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from dataclasses import dataclass


@dataclass(kw_only=True, frozen=True)
class FFMpegFilterManuallyDefinedHook:
name: str
function: str


@dataclass(kw_only=True)
class FFMpegFilterManuallyDefined:
name: str

formula_typings_input: str | None = None
formula_typings_output: str | None = None

pre: dict[str, str] = {}
pre: tuple[tuple[str, str], ...] = ()
6 changes: 6 additions & 0 deletions src/scripts/tests/__snapshots__/test_cache.ambr
Original file line number Diff line number Diff line change
@@ -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=()),
])
# ---
8 changes: 6 additions & 2 deletions src/scripts/tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 07b2cc8

Please sign in to comment.