dummy variable helper
This commit is contained in:
parent
9d4398ed7a
commit
f080554ff6
4 changed files with 29 additions and 26 deletions
|
|
@ -184,13 +184,7 @@ class Preset(_PresetShell):
|
|||
script = ScriptBuilder(
|
||||
Scriptable.add_sanitized_variables(self.overrides.dict_with_format_strings)
|
||||
)
|
||||
script.add(
|
||||
Scriptable.add_sanitized_variables(
|
||||
{source_var: "dummy_string" for source_var in self._source_variables}
|
||||
)
|
||||
)
|
||||
# updates any resolved variables
|
||||
_ = script.partial_build()
|
||||
script.add_resolved(Scriptable.add_dummy_variables(self._source_variables))
|
||||
return script
|
||||
|
||||
@functools.cached_property
|
||||
|
|
@ -198,10 +192,8 @@ class Preset(_PresetShell):
|
|||
"""
|
||||
Contains actualized script which should hold all Override variables
|
||||
"""
|
||||
return self._script_builder.add(
|
||||
Scriptable.add_sanitized_variables(
|
||||
{source_var: "dummy_string" for source_var in self._added_variables}
|
||||
)
|
||||
return self._script_builder.add_resolved(
|
||||
Scriptable.add_dummy_variables(self._added_variables)
|
||||
).partial_build()
|
||||
|
||||
def __validate_and_get_plugins(self) -> PresetPlugins:
|
||||
|
|
@ -221,10 +213,8 @@ class Preset(_PresetShell):
|
|||
def __validate_added_variables(self):
|
||||
script_builder = copy.deepcopy(self._script_builder)
|
||||
self.downloader_options.validate_with_variables(script=script_builder.partial_build())
|
||||
script_builder.add(
|
||||
Scriptable.add_sanitized_variables(
|
||||
{name: "dummy_string" for name in self.downloader_options.added_source_variables()}
|
||||
)
|
||||
script_builder.add_resolved(
|
||||
Scriptable.add_dummy_variables(self.downloader_options.added_source_variables())
|
||||
)
|
||||
|
||||
for _, plugin_options in sorted(
|
||||
|
|
@ -232,13 +222,8 @@ class Preset(_PresetShell):
|
|||
):
|
||||
# Validate current plugin using source + added plugin variables
|
||||
plugin_options.validate_with_variables(script=script_builder.partial_build())
|
||||
script_builder.add(
|
||||
Scriptable.add_sanitized_variables(
|
||||
{
|
||||
name: "dummy_string"
|
||||
for name in self.downloader_options.added_source_variables()
|
||||
}
|
||||
)
|
||||
script_builder.add_resolved(
|
||||
Scriptable.add_dummy_variables(self.downloader_options.added_source_variables())
|
||||
)
|
||||
|
||||
@functools.cache
|
||||
|
|
|
|||
|
|
@ -439,6 +439,12 @@ class ScriptBuilder:
|
|||
)
|
||||
return self
|
||||
|
||||
def add_resolved(self, variables: Dict[str, Resolvable]) -> "ScriptBuilder":
|
||||
for variable_name, resolvable in variables.items():
|
||||
self._variables[variable_name] = SyntaxTree(ast=[resolvable])
|
||||
|
||||
return self
|
||||
|
||||
@property
|
||||
def _missing_metadata(self) -> Tuple[Dict[str, Set[str]], Dict[str, Set[str]]]:
|
||||
variables_missing_metadata: Dict[str, Set[str]] = defaultdict(set)
|
||||
|
|
|
|||
|
|
@ -3,14 +3,26 @@ import json
|
|||
from abc import ABC
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import Iterable
|
||||
from typing import Set
|
||||
|
||||
from ytdl_sub.entries.script.variable_scripts import UNRESOLVED_VARIABLES
|
||||
from ytdl_sub.entries.script.variable_scripts import VARIABLE_SCRIPTS
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.resolvable import Resolvable
|
||||
from ytdl_sub.script.types.resolvable import String
|
||||
|
||||
|
||||
class Scriptable(ABC):
|
||||
@classmethod
|
||||
def add_dummy_variables(cls, variables: Iterable[str]) -> Dict[str, Resolvable]:
|
||||
dummy_variables: Dict[str, Resolvable] = {}
|
||||
for var in variables:
|
||||
dummy_variables[var] = String("dummy_string")
|
||||
dummy_variables[f"{var}_sanitized"] = String("dummy_string")
|
||||
|
||||
return dummy_variables
|
||||
|
||||
@classmethod
|
||||
def add_sanitized_variables(cls, variables: Dict[str, str]) -> Dict[str, str]:
|
||||
sanitized_variables = {
|
||||
|
|
|
|||
|
|
@ -153,8 +153,8 @@ class TestPrebuiltTVShowPresets:
|
|||
is_youtube_channel: bool,
|
||||
is_many_urls: bool,
|
||||
):
|
||||
yappi.set_clock_type("wall") # Use set_clock_type("wall") for wall time
|
||||
yappi.start()
|
||||
# yappi.set_clock_type("wall") # Use set_clock_type("wall") for wall time
|
||||
# yappi.start()
|
||||
|
||||
expected_summary_name = "unit/{}/{}/is_yt_{}{}".format(
|
||||
media_player_preset,
|
||||
|
|
@ -225,8 +225,8 @@ class TestPrebuiltTVShowPresets:
|
|||
)
|
||||
|
||||
reformatted_transaction_log = reformatted_subscription.update_with_info_json(dry_run=False)
|
||||
yappi.get_func_stats().print_all()
|
||||
|
||||
# yappi.get_func_stats().print_all()
|
||||
#
|
||||
assert_transaction_log_matches(
|
||||
output_directory=output_directory,
|
||||
transaction_log=reformatted_transaction_log,
|
||||
|
|
|
|||
Loading…
Reference in a new issue