as_bool
This commit is contained in:
parent
c6173ec14b
commit
c7b41a48ae
5 changed files with 59 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||||
from ytdl_sub.script.parser import ArgumentParser
|
from ytdl_sub.script.parser import ArgumentParser
|
||||||
from ytdl_sub.script.script import Script
|
from ytdl_sub.script.script import Script
|
||||||
from ytdl_sub.script.types.array import ResolvedArray
|
from ytdl_sub.script.types.array import ResolvedArray
|
||||||
|
from ytdl_sub.script.types.resolvable import Boolean
|
||||||
from ytdl_sub.script.types.resolvable import Float
|
from ytdl_sub.script.types.resolvable import Float
|
||||||
from ytdl_sub.script.types.resolvable import String
|
from ytdl_sub.script.types.resolvable import String
|
||||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||||
|
|
@ -23,6 +24,18 @@ class TestArray:
|
||||||
"array": String('str: ["a", 3.14]')
|
"array": String('str: ["a", 3.14]')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"array, expected_bool",
|
||||||
|
[
|
||||||
|
("{%bool([])}", False),
|
||||||
|
("{%bool([False])}", True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_return_as_bool(self, array: str, expected_bool: bool):
|
||||||
|
assert Script({"array_as_bool": array}).resolve() == {
|
||||||
|
"array_as_bool": Boolean(expected_bool)
|
||||||
|
}
|
||||||
|
|
||||||
def test_nested_array(self):
|
def test_nested_array(self):
|
||||||
assert Script(
|
assert Script(
|
||||||
{"array": "{['level1', ['level2', ['level3', 'level3'], 'level2'], 'level1']}"}
|
{"array": "{['level1', ['level2', ['level3', 'level3'], 'level2'], 'level1']}"}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||||
from ytdl_sub.script.parser import ArgumentParser
|
from ytdl_sub.script.parser import ArgumentParser
|
||||||
from ytdl_sub.script.script import Script
|
from ytdl_sub.script.script import Script
|
||||||
from ytdl_sub.script.types.array import ResolvedArray
|
from ytdl_sub.script.types.array import ResolvedArray
|
||||||
|
from ytdl_sub.script.types.resolvable import Boolean
|
||||||
from ytdl_sub.script.types.resolvable import Float
|
from ytdl_sub.script.types.resolvable import Float
|
||||||
from ytdl_sub.script.types.resolvable import Integer
|
from ytdl_sub.script.types.resolvable import Integer
|
||||||
from ytdl_sub.script.types.resolvable import String
|
from ytdl_sub.script.types.resolvable import String
|
||||||
|
|
@ -49,6 +50,16 @@ class TestFloat:
|
||||||
"as_string": String(str(expected_float)),
|
"as_string": String(str(expected_float)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"float_, expected_bool",
|
||||||
|
[
|
||||||
|
("{%bool(0.0)}", False),
|
||||||
|
("{%bool(0.1)}", True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_return_as_bool(self, float_: str, expected_bool: bool):
|
||||||
|
assert Script({"as_bool": float_}).resolve() == {"as_bool": Boolean(expected_bool)}
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"float_",
|
"float_",
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||||
from ytdl_sub.script.parser import ArgumentParser
|
from ytdl_sub.script.parser import ArgumentParser
|
||||||
from ytdl_sub.script.script import Script
|
from ytdl_sub.script.script import Script
|
||||||
from ytdl_sub.script.types.array import ResolvedArray
|
from ytdl_sub.script.types.array import ResolvedArray
|
||||||
|
from ytdl_sub.script.types.resolvable import Boolean
|
||||||
from ytdl_sub.script.types.resolvable import Float
|
from ytdl_sub.script.types.resolvable import Float
|
||||||
from ytdl_sub.script.types.resolvable import Integer
|
from ytdl_sub.script.types.resolvable import Integer
|
||||||
from ytdl_sub.script.types.resolvable import String
|
from ytdl_sub.script.types.resolvable import String
|
||||||
|
|
@ -49,6 +50,16 @@ class TestInteger:
|
||||||
"as_string": String(str(expected_integer)),
|
"as_string": String(str(expected_integer)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"integer, expected_bool",
|
||||||
|
[
|
||||||
|
("{%bool(0)}", False),
|
||||||
|
("{%bool(1)}", True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_return_as_bool(self, integer: str, expected_bool: bool):
|
||||||
|
assert Script({"as_bool": integer}).resolve() == {"as_bool": Boolean(expected_bool)}
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"integer",
|
"integer",
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||||
from ytdl_sub.script.parser import ArgumentParser
|
from ytdl_sub.script.parser import ArgumentParser
|
||||||
from ytdl_sub.script.script import Script
|
from ytdl_sub.script.script import Script
|
||||||
from ytdl_sub.script.types.map import ResolvedMap
|
from ytdl_sub.script.types.map import ResolvedMap
|
||||||
|
from ytdl_sub.script.types.resolvable import Boolean
|
||||||
from ytdl_sub.script.types.resolvable import Float
|
from ytdl_sub.script.types.resolvable import Float
|
||||||
from ytdl_sub.script.types.resolvable import String
|
from ytdl_sub.script.types.resolvable import String
|
||||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||||
|
|
@ -27,6 +28,16 @@ class TestMap:
|
||||||
"map": String('json: {"a": 3.14}')
|
"map": String('json: {"a": 3.14}')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"map_, expected_bool",
|
||||||
|
[
|
||||||
|
("{%bool({})}", False),
|
||||||
|
("{%bool({'key': 'value'})}", True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_return_as_bool(self, map_: str, expected_bool: bool):
|
||||||
|
assert Script({"as_bool": map_}).resolve() == {"as_bool": Boolean(expected_bool)}
|
||||||
|
|
||||||
def test_nested_map(self):
|
def test_nested_map(self):
|
||||||
map_str = """{
|
map_str = """{
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||||
from ytdl_sub.script.parser import ArgumentParser
|
from ytdl_sub.script.parser import ArgumentParser
|
||||||
from ytdl_sub.script.script import Script
|
from ytdl_sub.script.script import Script
|
||||||
from ytdl_sub.script.types.array import ResolvedArray
|
from ytdl_sub.script.types.array import ResolvedArray
|
||||||
|
from ytdl_sub.script.types.resolvable import Boolean
|
||||||
from ytdl_sub.script.types.resolvable import Float
|
from ytdl_sub.script.types.resolvable import Float
|
||||||
from ytdl_sub.script.types.resolvable import Integer
|
from ytdl_sub.script.types.resolvable import Integer
|
||||||
from ytdl_sub.script.types.resolvable import String
|
from ytdl_sub.script.types.resolvable import String
|
||||||
|
|
@ -37,6 +38,8 @@ class TestString:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"string, expected_string",
|
"string, expected_string",
|
||||||
[
|
[
|
||||||
|
("{%string('')}", ""),
|
||||||
|
('{%string("")}', ""),
|
||||||
("{%string('323')}", "323"),
|
("{%string('323')}", "323"),
|
||||||
('{%string( "4253" )}', "4253"),
|
('{%string( "4253" )}', "4253"),
|
||||||
('{%string("hi")}', "hi"),
|
('{%string("hi")}', "hi"),
|
||||||
|
|
@ -55,6 +58,16 @@ class TestString:
|
||||||
def test_string(self, string: str, expected_string: str):
|
def test_string(self, string: str, expected_string: str):
|
||||||
assert Script({"string": string}).resolve() == {"string": String(expected_string)}
|
assert Script({"string": string}).resolve() == {"string": String(expected_string)}
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"string, expected_bool",
|
||||||
|
[
|
||||||
|
("{%bool('')}", False),
|
||||||
|
("{%bool('false')}", True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_return_as_bool(self, string: str, expected_bool: bool):
|
||||||
|
assert Script({"as_bool": string}).resolve() == {"as_bool": Boolean(expected_bool)}
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"string",
|
"string",
|
||||||
[
|
[
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue