ytdl-sub/tests/unit/script/functions/test_conditional_functions.py
Jesse Bannon e92b1cd12a
[BACKEND][HUGE] Function Support in variable syntax (#838)
A complete gutting of the internals of ytdl-sub to support functions in our variable syntax, in addition to being able to access a yt-dlp entry's .info.json fields using functions. Functionally, ytdl-sub should still look and behave the same from a user-perspective.

With so many lines of code changed (+8927, -2708), no doubt there will be new issues. Please make a GH issue or reach out on Discord if your config/subscriptions break in any way/shape/form.

Details on how to use function support will come soon in the form of proper documentation in our readthedocs.
2023-12-18 16:08:15 -08:00

35 lines
1,006 B
Python

import pytest
from ytdl_sub.script.script import Script
class TestConditionalFunction:
@pytest.mark.parametrize(
"function_str, expected_output",
[
("{%if(True, True, False)}", True),
("{%if(False, True, False)}", False),
],
)
def test_if_function(self, function_str: str, expected_output: bool):
output = Script({"output": function_str}).resolve(update=True).get("output").native
assert output == expected_output
def test_nested_if_function(self):
function_str = """{
%if(
True,
%if(
True,
%if(
True,
"winner",
True
),
True
),
True
)
}"""
output = Script({"output": function_str}).resolve(update=True).get("output").native
assert output == "winner"