more tests

This commit is contained in:
Jesse Bannon 2023-12-16 22:43:30 -08:00
parent e3ab942389
commit 6c103ec19e
2 changed files with 43 additions and 2 deletions

View file

@ -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

View file

@ -1,8 +1,6 @@
import pytest import pytest
from unit.script.conftest import single_variable_output from unit.script.conftest import single_variable_output
from ytdl_sub.script.script import Script
class TestNumericFunctions: class TestNumericFunctions:
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -66,3 +64,15 @@ class TestNumericFunctions:
def test_min(self, values: str, expected_output: int): def test_min(self, values: str, expected_output: int):
output = single_variable_output(f"{{%min({values})}}") output = single_variable_output(f"{{%min({values})}}")
assert output == expected_output 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