perhaps fixedd

This commit is contained in:
Jesse Bannon 2025-12-29 23:11:22 -08:00
parent 0afc7ee64a
commit 6b6031b77e
4 changed files with 38 additions and 29 deletions

View file

@ -50,7 +50,7 @@ def _add_dummy_overrides(overrides: Overrides) -> Dict[str, str]:
try:
# Attempt to get the resolved version, which will only happen
# if it does not have any dependencies to the entry
value = ScriptUtils.to_script(overrides.script.get(override_name).native)
value = f'{{%string("""{overrides.script.get(override_name).native}""")}}'
except RuntimeException:
value = to_variable_dependency_format_string(
script=overrides.script,

View file

@ -52,7 +52,10 @@ class StringFormatterValidator(StringValidator):
def __init__(self, name, value: str):
super().__init__(name=name, value=value)
try:
_ = parse(str(value))
self._parsed = parse(
text=str(value),
name=self.leaf_name,
)
except UserException as exc:
raise self._validation_exception(exc) from exc
@ -66,6 +69,11 @@ class StringFormatterValidator(StringValidator):
"""
return self._value
@property
@final
def parsed(self) -> SyntaxTree:
return self._parsed
def post_process(self, resolved: str) -> str:
"""
Returns
@ -218,9 +226,7 @@ def _validate_formatter(
is_static_formatter = True
unresolvable = unresolved_variables.union({VARIABLES.entry_metadata.variable_name})
parsed = parse(
text=formatter_validator.format_string,
)
parsed = formatter_validator.parsed
variable_names = {var.name for var in parsed.variables}
custom_function_names = {f"%{func.name}" for func in parsed.custom_functions}

View file

@ -340,27 +340,3 @@ class TestPreset:
"output_options": {"output_directory": "dir", "file_name": "acjk"},
},
)
def test_preset_error_override_name_conflicts_with_plugin(self, config_file, output_options):
with pytest.raises(
ValidationException,
match=re.escape(
"Override variable with name throttle_protection cannot be used since it is the "
"name of a plugin. Perhaps you meant to define it as a plugin? If so, indent it "
"left to make it at the same level as overrides."
),
):
_ = Preset(
config=config_file,
name="test",
value={
"download": {
"url": "youtube.com/watch?v=123abc",
},
"subtitles": {
"embed_subtitles": True,
},
"output_options": {"output_directory": "dir", "file_name": "acjk"},
"overrides": {"throttle_protection": "nope"},
},
)

View file

@ -143,3 +143,30 @@ class TestSubscriptionValidation:
),
config=config_file,
)
def test_preset_error_override_name_conflicts_with_plugin(self, config_file, output_options):
with pytest.raises(
ValidationException,
match=re.escape(
"Override variable with name throttle_protection cannot be used since it is the "
"name of a plugin. Perhaps you meant to define it as a plugin? If so, indent it "
"left to make it at the same level as overrides."
),
):
_ = Subscription.from_preset(
preset=Preset(
config=config_file,
name="test",
value={
"download": {
"url": "youtube.com/watch?v=123abc",
},
"subtitles": {
"embed_subtitles": True,
},
"output_options": {"output_directory": "dir", "file_name": "acjk"},
"overrides": {"throttle_protection": "nope"},
},
),
config=config_file,
)