diff --git a/tests/resources.py b/tests/resources.py index d1bece8d..339dd3e5 100644 --- a/tests/resources.py +++ b/tests/resources.py @@ -5,7 +5,7 @@ from pathlib import Path from typing import Dict DISABLE_YOUTUBE_TESTS: bool = True -REGENERATE_FIXTURES: bool = True +REGENERATE_FIXTURES: bool = False RESOURCE_PATH: Path = Path("tests") / "resources" _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 -def assert_expected_json(input_json: Dict, json_name: str) -> None: +def expected_json(input_json: Dict, json_name: str) -> Dict: if REGENERATE_FIXTURES: 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) - return + + return input_json with open(_EXPECTED_JSON_PATH / json_name, "r", encoding="utf-8") as 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: diff --git a/tests/resources/expected_json/inspect_built_in_unresolvable_all.json b/tests/resources/expected_json/inspect_built_in_unresolvable_all.json index 65d250e3..13881c4a 100644 --- a/tests/resources/expected_json/inspect_built_in_unresolvable_all.json +++ b/tests/resources/expected_json/inspect_built_in_unresolvable_all.json @@ -237,8 +237,8 @@ "tv_show_content_rating_sanitized": "TV-14", "tv_show_date_range_type": "upload_date", "tv_show_date_range_type_sanitized": "upload_date", - "tv_show_directory": "/var/folders/rw/hl1xmkmj68zdl2kjx3l0dwzc0000gn/T/tmploqww2jl", - "tv_show_directory_sanitized": "\u29f8var\u29f8folders\u29f8rw\u29f8hl1xmkmj68zdl2kjx3l0dwzc0000gn\u29f8T\u29f8tmploqww2jl", + "tv_show_directory": "tv_show_directory_path", + "tv_show_directory_sanitized": "tv_show_directory_path", "tv_show_fanart_file_name": "fanart.jpg", "tv_show_fanart_file_name_sanitized": "fanart.jpg", "tv_show_genre": "Documentaries", diff --git a/tests/resources/expected_json/inspect_built_in_unresolvable_overrides.json b/tests/resources/expected_json/inspect_built_in_unresolvable_overrides.json index 63d9f791..4d432017 100644 --- a/tests/resources/expected_json/inspect_built_in_unresolvable_overrides.json +++ b/tests/resources/expected_json/inspect_built_in_unresolvable_overrides.json @@ -45,7 +45,7 @@ "tv_show_content_rating": "TV-14", "tv_show_content_rating_default": "TV-14", "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_genre": "Documentaries", "tv_show_genre_default": "ytdl-sub", diff --git a/tests/resources/expected_json/inspect_unresolvable_all.json b/tests/resources/expected_json/inspect_unresolvable_all.json index 1f708fb0..828e7b7d 100644 --- a/tests/resources/expected_json/inspect_unresolvable_all.json +++ b/tests/resources/expected_json/inspect_unresolvable_all.json @@ -45,7 +45,7 @@ "tv_show_content_rating": "TV-14", "tv_show_content_rating_default": "TV-14", "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_genre": "Documentaries", "tv_show_genre_default": "ytdl-sub", diff --git a/tests/resources/expected_json/inspect_unresolvable_overrides.json b/tests/resources/expected_json/inspect_unresolvable_overrides.json index 1c610a13..392bbe53 100644 --- a/tests/resources/expected_json/inspect_unresolvable_overrides.json +++ b/tests/resources/expected_json/inspect_unresolvable_overrides.json @@ -237,8 +237,8 @@ "tv_show_content_rating_sanitized": "TV-14", "tv_show_date_range_type": "upload_date", "tv_show_date_range_type_sanitized": "upload_date", - "tv_show_directory": "/var/folders/rw/hl1xmkmj68zdl2kjx3l0dwzc0000gn/T/tmpl8oa7o5c", - "tv_show_directory_sanitized": "\u29f8var\u29f8folders\u29f8rw\u29f8hl1xmkmj68zdl2kjx3l0dwzc0000gn\u29f8T\u29f8tmpl8oa7o5c", + "tv_show_directory": "tv_show_directory_path", + "tv_show_directory_sanitized": "tv_show_directory_path", "tv_show_fanart_file_name": "fanart.jpg", "tv_show_fanart_file_name_sanitized": "fanart.jpg", "tv_show_genre": "Documentaries", diff --git a/tests/unit/config/test_subscription_inspect.py b/tests/unit/config/test_subscription_inspect.py index 3b66ce62..1de312ee 100644 --- a/tests/unit/config/test_subscription_inspect.py +++ b/tests/unit/config/test_subscription_inspect.py @@ -1,6 +1,6 @@ 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.entries.script.variable_definitions import VARIABLES @@ -8,7 +8,7 @@ from ytdl_sub.subscriptions.subscription import Subscription 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( config=ConfigFile.from_file_path("docker/root/defaults/config.yaml"), 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.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) out = { @@ -30,14 +35,14 @@ def test_built_in_unresolvable(docker_default_subscription_path: Path, output_di 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 = { name: ScriptUtils.to_native_script(partial_script._variables[name]) 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): @@ -52,7 +57,12 @@ def test_bare_minimum_unresolvable(docker_default_subscription_path: Path, outpu unresolvable.add("entry_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) out = { @@ -61,11 +71,11 @@ def test_bare_minimum_unresolvable(docker_default_subscription_path: Path, outpu if not name.startswith("%") } - assert_expected_json(out, "inspect_unresolvable_all.json") + assert out == expected_json(out, "inspect_unresolvable_all.json") out = { name: ScriptUtils.to_native_script(partial_script._variables[name]) for name in script.variable_names } - assert_expected_json(out, "inspect_unresolvable_overrides.json") + assert out == expected_json(out, "inspect_unresolvable_overrides.json")