func does not exist test
This commit is contained in:
parent
5f049fbfb4
commit
b6670c96b3
4 changed files with 21 additions and 1 deletions
|
|
@ -23,6 +23,7 @@ from ytdl_sub.script.types.variable import FunctionArgument
|
||||||
from ytdl_sub.script.types.variable import Variable
|
from ytdl_sub.script.types.variable import Variable
|
||||||
from ytdl_sub.script.types.variable_dependency import VariableDependency
|
from ytdl_sub.script.types.variable_dependency import VariableDependency
|
||||||
from ytdl_sub.script.utils.exception_formatters import FunctionArgumentsExceptionFormatter
|
from ytdl_sub.script.utils.exception_formatters import FunctionArgumentsExceptionFormatter
|
||||||
|
from ytdl_sub.script.utils.exceptions import FunctionDoesNotExist
|
||||||
from ytdl_sub.script.utils.exceptions import FunctionRuntimeException
|
from ytdl_sub.script.utils.exceptions import FunctionRuntimeException
|
||||||
from ytdl_sub.script.utils.exceptions import UserThrownRuntimeError
|
from ytdl_sub.script.utils.exceptions import UserThrownRuntimeError
|
||||||
from ytdl_sub.script.utils.type_checking import FunctionInputSpec
|
from ytdl_sub.script.utils.type_checking import FunctionInputSpec
|
||||||
|
|
@ -101,7 +102,9 @@ class CustomFunction(Function):
|
||||||
custom_functions=custom_functions,
|
custom_functions=custom_functions,
|
||||||
)
|
)
|
||||||
|
|
||||||
raise StringFormattingException(f"Custom function {self.name} does not exist")
|
raise FunctionDoesNotExist(
|
||||||
|
f"Function %{self.name} does not exist as a built-in or custom function."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BuiltInFunction(Function, TypeHintedFunctionType):
|
class BuiltInFunction(Function, TypeHintedFunctionType):
|
||||||
|
|
|
||||||
5
src/ytdl_sub/script/types/lambda.py
Normal file
5
src/ytdl_sub/script/types/lambda.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
from ytdl_sub.script.types.resolvable import ArgumentType
|
||||||
|
|
||||||
|
|
||||||
|
class Lambda(ArgumentType):
|
||||||
|
function_name: str
|
||||||
|
|
@ -15,6 +15,10 @@ class IncompatibleFunctionArguments(UserException):
|
||||||
"""Function has invalid arguments"""
|
"""Function has invalid arguments"""
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionDoesNotExist(UserException):
|
||||||
|
"""Tried to use a function that does not exist"""
|
||||||
|
|
||||||
|
|
||||||
class FunctionRuntimeException(ValueError):
|
class FunctionRuntimeException(ValueError):
|
||||||
"""Exception thrown when a ytdl-sub function has an error occur at runtime"""
|
"""Exception thrown when a ytdl-sub function has an error occur at runtime"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import pytest
|
||||||
from ytdl_sub.script.script import Script
|
from ytdl_sub.script.script import Script
|
||||||
from ytdl_sub.script.types.resolvable import Boolean
|
from ytdl_sub.script.types.resolvable import Boolean
|
||||||
from ytdl_sub.script.types.resolvable import String
|
from ytdl_sub.script.types.resolvable import String
|
||||||
|
from ytdl_sub.script.utils.exceptions import FunctionDoesNotExist
|
||||||
from ytdl_sub.script.utils.exceptions import FunctionRuntimeException
|
from ytdl_sub.script.utils.exceptions import FunctionRuntimeException
|
||||||
from ytdl_sub.script.utils.exceptions import IncompatibleFunctionArguments
|
from ytdl_sub.script.utils.exceptions import IncompatibleFunctionArguments
|
||||||
from ytdl_sub.script.utils.exceptions import UserThrownRuntimeError
|
from ytdl_sub.script.utils.exceptions import UserThrownRuntimeError
|
||||||
|
|
@ -97,3 +98,10 @@ class TestFunction:
|
||||||
def test_user_assert(self):
|
def test_user_assert(self):
|
||||||
with pytest.raises(UserThrownRuntimeError, match=re.escape("test this error message")):
|
with pytest.raises(UserThrownRuntimeError, match=re.escape("test this error message")):
|
||||||
Script({"throw_error": "{%assert(False, 'test this error message')}"}).resolve()
|
Script({"throw_error": "{%assert(False, 'test this error message')}"}).resolve()
|
||||||
|
|
||||||
|
def test_function_does_not_exist(self):
|
||||||
|
with pytest.raises(
|
||||||
|
FunctionDoesNotExist,
|
||||||
|
match=re.escape("Function %lolnope does not exist as a built-in or custom function."),
|
||||||
|
):
|
||||||
|
Script({"dne": "{%lolnope(False, 'test this error message')}"}).resolve()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue