perhaps fixedd
This commit is contained in:
parent
0afc7ee64a
commit
6b6031b77e
4 changed files with 38 additions and 29 deletions
|
|
@ -50,7 +50,7 @@ def _add_dummy_overrides(overrides: Overrides) -> Dict[str, str]:
|
||||||
try:
|
try:
|
||||||
# Attempt to get the resolved version, which will only happen
|
# Attempt to get the resolved version, which will only happen
|
||||||
# if it does not have any dependencies to the entry
|
# 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:
|
except RuntimeException:
|
||||||
value = to_variable_dependency_format_string(
|
value = to_variable_dependency_format_string(
|
||||||
script=overrides.script,
|
script=overrides.script,
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,10 @@ class StringFormatterValidator(StringValidator):
|
||||||
def __init__(self, name, value: str):
|
def __init__(self, name, value: str):
|
||||||
super().__init__(name=name, value=value)
|
super().__init__(name=name, value=value)
|
||||||
try:
|
try:
|
||||||
_ = parse(str(value))
|
self._parsed = parse(
|
||||||
|
text=str(value),
|
||||||
|
name=self.leaf_name,
|
||||||
|
)
|
||||||
except UserException as exc:
|
except UserException as exc:
|
||||||
raise self._validation_exception(exc) from exc
|
raise self._validation_exception(exc) from exc
|
||||||
|
|
||||||
|
|
@ -66,6 +69,11 @@ class StringFormatterValidator(StringValidator):
|
||||||
"""
|
"""
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
|
@property
|
||||||
|
@final
|
||||||
|
def parsed(self) -> SyntaxTree:
|
||||||
|
return self._parsed
|
||||||
|
|
||||||
def post_process(self, resolved: str) -> str:
|
def post_process(self, resolved: str) -> str:
|
||||||
"""
|
"""
|
||||||
Returns
|
Returns
|
||||||
|
|
@ -218,9 +226,7 @@ def _validate_formatter(
|
||||||
is_static_formatter = True
|
is_static_formatter = True
|
||||||
unresolvable = unresolved_variables.union({VARIABLES.entry_metadata.variable_name})
|
unresolvable = unresolved_variables.union({VARIABLES.entry_metadata.variable_name})
|
||||||
|
|
||||||
parsed = parse(
|
parsed = formatter_validator.parsed
|
||||||
text=formatter_validator.format_string,
|
|
||||||
)
|
|
||||||
variable_names = {var.name for var in parsed.variables}
|
variable_names = {var.name for var in parsed.variables}
|
||||||
custom_function_names = {f"%{func.name}" for func in parsed.custom_functions}
|
custom_function_names = {f"%{func.name}" for func in parsed.custom_functions}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -340,27 +340,3 @@ class TestPreset:
|
||||||
"output_options": {"output_directory": "dir", "file_name": "acjk"},
|
"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"},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -143,3 +143,30 @@ class TestSubscriptionValidation:
|
||||||
),
|
),
|
||||||
config=config_file,
|
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,
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue