コード例 #1
0
def test_transform_value_in_cascading_dropdown():
    valuespec = vs.CascadingDropdown(choices=[
        ("a", "Title a", vs.TextAscii()),
        ("b", "Title b",
         vs.Transform(
             vs.TextAscii(),
             forth=lambda x: x if x == "lala" else x.upper(),
             back=lambda x: x + "aaa",
         )),
    ])

    assert valuespec.transform_value(("a", "abc")) == ("a", "abc")
    assert valuespec.transform_value(("b", "lala")) == ("b", "lalaaaa")
    assert valuespec.transform_value(("b", "AAA")) == ("b", "AAAaaa")
コード例 #2
0
def test_transform_value_in_tuple():
    valuespec = vs.Tuple(elements=[
        vs.Transform(
            vs.TextAscii(),
            forth=lambda x: x if x == "lala" else x.upper(),
            back=lambda x: x + "aaa",
        ),
        vs.Transform(
            vs.TextAscii(),
            forth=lambda x: x if x == "lala" else x.upper(),
            back=lambda x: x + "aaa",
        ),
    ])

    assert valuespec.transform_value(("lala", "AAA")) == ("lalaaaa", "AAAaaa")
コード例 #3
0
def test_transform_value_with_transform_vs():
    valuespec = vs.Transform(
        vs.TextAscii(),
        forth=lambda x: x if x == "lala" else x.upper(),
        back=lambda x: x + "aaa",
    )

    assert valuespec.transform_value("lala") == "lalaaaa"
    assert valuespec.transform_value("AAA") == "AAAaaa"
コード例 #4
0
def test_transform_value_in_dict():
    valuespec = vs.Dictionary(elements=[
        ("a",
         vs.Transform(
             vs.TextAscii(),
             forth=lambda x: x if x == "lala" else x.upper(),
             back=lambda x: x + "aaa",
         )),
    ])

    assert valuespec.transform_value({"a": "lala"}) == {"a": "lalaaaa"}
    assert valuespec.transform_value({"a": "AAA"}) == {"a": "AAAaaa"}
コード例 #5
0
def test_transform_value_dict():
    valuespec = vs.Dictionary(elements=[
        ("a", vs.TextAscii()),
    ])
    assert valuespec.transform_value({"a": "lala"}) == {"a": "lala"}
コード例 #6
0
def test_transform_value_no_transform_vs():
    valuespec = vs.TextAscii()
    assert valuespec.transform_value("lala") == "lala"
    assert valuespec.transform_value("AAA") == "AAA"