fixed test

This commit is contained in:
Jesse Bannon 2026-01-11 20:29:42 -08:00
parent cd35621191
commit e9e8ea19c1
6 changed files with 29 additions and 18 deletions

View file

@ -5,7 +5,7 @@ from pathlib import Path
from typing import Dict from typing import Dict
DISABLE_YOUTUBE_TESTS: bool = True DISABLE_YOUTUBE_TESTS: bool = True
REGENERATE_FIXTURES: bool = True REGENERATE_FIXTURES: bool = False
RESOURCE_PATH: Path = Path("tests") / "resources" RESOURCE_PATH: Path = Path("tests") / "resources"
_FILE_FIXTURE_PATH: Path = RESOURCE_PATH / "file_fixtures" _FILE_FIXTURE_PATH: Path = RESOURCE_PATH / "file_fixtures"
@ -16,16 +16,17 @@ def file_fixture_path(fixture_name: str) -> Path:
return _FILE_FIXTURE_PATH / fixture_name return _FILE_FIXTURE_PATH / fixture_name
def assert_expected_json(input_json: Dict, json_name: str) -> None: def expected_json(input_json: Dict, json_name: str) -> Dict:
if REGENERATE_FIXTURES: if REGENERATE_FIXTURES:
with open(_EXPECTED_JSON_PATH / json_name, "w", encoding="utf-8") as json_file: with open(_EXPECTED_JSON_PATH / json_name, "w", encoding="utf-8") as json_file:
json.dump(input_json, json_file, sort_keys=True, indent=2) json.dump(input_json, json_file, sort_keys=True, indent=2)
return
return input_json
with open(_EXPECTED_JSON_PATH / json_name, "r", encoding="utf-8") as json_file: with open(_EXPECTED_JSON_PATH / json_name, "r", encoding="utf-8") as json_file:
expected_json = json.load(json_file) expected_json = json.load(json_file)
assert input_json == expected_json return expected_json
def copy_file_fixture(fixture_name: str, output_file_path: Path) -> None: def copy_file_fixture(fixture_name: str, output_file_path: Path) -> None:

View file

@ -237,8 +237,8 @@
"tv_show_content_rating_sanitized": "TV-14", "tv_show_content_rating_sanitized": "TV-14",
"tv_show_date_range_type": "upload_date", "tv_show_date_range_type": "upload_date",
"tv_show_date_range_type_sanitized": "upload_date", "tv_show_date_range_type_sanitized": "upload_date",
"tv_show_directory": "/var/folders/rw/hl1xmkmj68zdl2kjx3l0dwzc0000gn/T/tmploqww2jl", "tv_show_directory": "tv_show_directory_path",
"tv_show_directory_sanitized": "\u29f8var\u29f8folders\u29f8rw\u29f8hl1xmkmj68zdl2kjx3l0dwzc0000gn\u29f8T\u29f8tmploqww2jl", "tv_show_directory_sanitized": "tv_show_directory_path",
"tv_show_fanart_file_name": "fanart.jpg", "tv_show_fanart_file_name": "fanart.jpg",
"tv_show_fanart_file_name_sanitized": "fanart.jpg", "tv_show_fanart_file_name_sanitized": "fanart.jpg",
"tv_show_genre": "Documentaries", "tv_show_genre": "Documentaries",

View file

@ -45,7 +45,7 @@
"tv_show_content_rating": "TV-14", "tv_show_content_rating": "TV-14",
"tv_show_content_rating_default": "TV-14", "tv_show_content_rating_default": "TV-14",
"tv_show_date_range_type": "upload_date", "tv_show_date_range_type": "upload_date",
"tv_show_directory": "/var/folders/rw/hl1xmkmj68zdl2kjx3l0dwzc0000gn/T/tmploqww2jl", "tv_show_directory": "tv_show_directory_path",
"tv_show_fanart_file_name": "fanart.jpg", "tv_show_fanart_file_name": "fanart.jpg",
"tv_show_genre": "Documentaries", "tv_show_genre": "Documentaries",
"tv_show_genre_default": "ytdl-sub", "tv_show_genre_default": "ytdl-sub",

View file

@ -45,7 +45,7 @@
"tv_show_content_rating": "TV-14", "tv_show_content_rating": "TV-14",
"tv_show_content_rating_default": "TV-14", "tv_show_content_rating_default": "TV-14",
"tv_show_date_range_type": "upload_date", "tv_show_date_range_type": "upload_date",
"tv_show_directory": "/var/folders/rw/hl1xmkmj68zdl2kjx3l0dwzc0000gn/T/tmpl8oa7o5c", "tv_show_directory": "tv_show_directory_path",
"tv_show_fanart_file_name": "fanart.jpg", "tv_show_fanart_file_name": "fanart.jpg",
"tv_show_genre": "Documentaries", "tv_show_genre": "Documentaries",
"tv_show_genre_default": "ytdl-sub", "tv_show_genre_default": "ytdl-sub",

View file

@ -237,8 +237,8 @@
"tv_show_content_rating_sanitized": "TV-14", "tv_show_content_rating_sanitized": "TV-14",
"tv_show_date_range_type": "upload_date", "tv_show_date_range_type": "upload_date",
"tv_show_date_range_type_sanitized": "upload_date", "tv_show_date_range_type_sanitized": "upload_date",
"tv_show_directory": "/var/folders/rw/hl1xmkmj68zdl2kjx3l0dwzc0000gn/T/tmpl8oa7o5c", "tv_show_directory": "tv_show_directory_path",
"tv_show_directory_sanitized": "\u29f8var\u29f8folders\u29f8rw\u29f8hl1xmkmj68zdl2kjx3l0dwzc0000gn\u29f8T\u29f8tmpl8oa7o5c", "tv_show_directory_sanitized": "tv_show_directory_path",
"tv_show_fanart_file_name": "fanart.jpg", "tv_show_fanart_file_name": "fanart.jpg",
"tv_show_fanart_file_name_sanitized": "fanart.jpg", "tv_show_fanart_file_name_sanitized": "fanart.jpg",
"tv_show_genre": "Documentaries", "tv_show_genre": "Documentaries",

View file

@ -1,6 +1,6 @@
from pathlib import Path from pathlib import Path
from resources import assert_expected_json from resources import expected_json
from ytdl_sub.config.config_file import ConfigFile from ytdl_sub.config.config_file import ConfigFile
from ytdl_sub.entries.script.variable_definitions import VARIABLES from ytdl_sub.entries.script.variable_definitions import VARIABLES
@ -8,7 +8,7 @@ from ytdl_sub.subscriptions.subscription import Subscription
from ytdl_sub.utils.script import ScriptUtils from ytdl_sub.utils.script import ScriptUtils
def test_built_in_unresolvable(docker_default_subscription_path: Path, output_directory: str): def test_built_in_unresolvable(docker_default_subscription_path: Path):
sub = Subscription.from_file_path( sub = Subscription.from_file_path(
config=ConfigFile.from_file_path("docker/root/defaults/config.yaml"), config=ConfigFile.from_file_path("docker/root/defaults/config.yaml"),
subscription_path=docker_default_subscription_path, subscription_path=docker_default_subscription_path,
@ -21,7 +21,12 @@ def test_built_in_unresolvable(docker_default_subscription_path: Path, output_di
unresolvable.add("sibling_metadata") unresolvable.add("sibling_metadata")
unresolvable.update(VARIABLES.scripts().keys()) unresolvable.update(VARIABLES.scripts().keys())
script = sub.overrides.script script = sub.overrides.script.add(
{
"tv_show_directory": "tv_show_directory_path",
"tv_show_directory_sanitized": "tv_show_directory_path",
}
)
partial_script = script.resolve_partial(unresolvable=unresolvable) partial_script = script.resolve_partial(unresolvable=unresolvable)
out = { out = {
@ -30,14 +35,14 @@ def test_built_in_unresolvable(docker_default_subscription_path: Path, output_di
if not name.startswith("%") if not name.startswith("%")
} }
assert_expected_json(out, "inspect_built_in_unresolvable_overrides.json") assert out == expected_json(out, "inspect_built_in_unresolvable_overrides.json")
out = { out = {
name: ScriptUtils.to_native_script(partial_script._variables[name]) name: ScriptUtils.to_native_script(partial_script._variables[name])
for name in script.variable_names for name in script.variable_names
} }
assert_expected_json(out, "inspect_built_in_unresolvable_all.json") assert out == expected_json(out, "inspect_built_in_unresolvable_all.json")
def test_bare_minimum_unresolvable(docker_default_subscription_path: Path, output_directory: str): def test_bare_minimum_unresolvable(docker_default_subscription_path: Path, output_directory: str):
@ -52,7 +57,12 @@ def test_bare_minimum_unresolvable(docker_default_subscription_path: Path, outpu
unresolvable.add("entry_metadata") unresolvable.add("entry_metadata")
unresolvable.add("sibling_metadata") unresolvable.add("sibling_metadata")
script = sub.overrides.script script = sub.overrides.script.add(
{
"tv_show_directory": "tv_show_directory_path",
"tv_show_directory_sanitized": "tv_show_directory_path",
}
)
partial_script = script.resolve_partial(unresolvable=unresolvable) partial_script = script.resolve_partial(unresolvable=unresolvable)
out = { out = {
@ -61,11 +71,11 @@ def test_bare_minimum_unresolvable(docker_default_subscription_path: Path, outpu
if not name.startswith("%") if not name.startswith("%")
} }
assert_expected_json(out, "inspect_unresolvable_all.json") assert out == expected_json(out, "inspect_unresolvable_all.json")
out = { out = {
name: ScriptUtils.to_native_script(partial_script._variables[name]) name: ScriptUtils.to_native_script(partial_script._variables[name])
for name in script.variable_names for name in script.variable_names
} }
assert_expected_json(out, "inspect_unresolvable_overrides.json") assert out == expected_json(out, "inspect_unresolvable_overrides.json")