From 6c103ec19e5c6f344abdaaf4f456e08ffbe64398 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Sat, 16 Dec 2023 22:43:30 -0800 Subject: [PATCH] more tests --- .../script/functions/test_json_functions.py | 31 +++++++++++++++++++ .../functions/test_numeric_functions.py | 14 +++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/unit/script/functions/test_json_functions.py diff --git a/tests/unit/script/functions/test_json_functions.py b/tests/unit/script/functions/test_json_functions.py new file mode 100644 index 00000000..b2477ac5 --- /dev/null +++ b/tests/unit/script/functions/test_json_functions.py @@ -0,0 +1,31 @@ +import json + +import pytest +from unit.script.conftest import single_variable_output + + +class TestJsonFunctions: + @pytest.mark.parametrize("str_token", ["'''", '"""']) + def test_from_json(self, str_token: str): + json_dict = { + "string": "value", + "quotes": "has '' and \"\"", + "int": 1, + "bool": True, + "list": [1, 2, 3], + "dict": {"a": 1, "b": 2}, + "float": 3.14, + "nested_dict": { + "string": "value", + "int": 1, + "bool": True, + "list": [1, 2, 3], + "dict": {"a": 1, "b": 2}, + "float": 3.14, + }, + } + + output = single_variable_output( + f"{{ %from_json({str_token}{json.dumps(json_dict)}{str_token}) }}" + ) + assert output == json_dict diff --git a/tests/unit/script/functions/test_numeric_functions.py b/tests/unit/script/functions/test_numeric_functions.py index bbd2879d..c41f4c59 100644 --- a/tests/unit/script/functions/test_numeric_functions.py +++ b/tests/unit/script/functions/test_numeric_functions.py @@ -1,8 +1,6 @@ import pytest from unit.script.conftest import single_variable_output -from ytdl_sub.script.script import Script - class TestNumericFunctions: @pytest.mark.parametrize( @@ -66,3 +64,15 @@ class TestNumericFunctions: def test_min(self, values: str, expected_output: int): output = single_variable_output(f"{{%min({values})}}") assert output == expected_output + + @pytest.mark.parametrize( + "values, expected_output", + [ + ("2, 2", 2**2), + ("9, 0.5", 9**0.5), + ("4.4, 2.2", 4.4**2.2), + ], + ) + def test_pow(self, values: str, expected_output: float): + output = single_variable_output(f"{{ %pow({values}) }}") + assert output == expected_output