Exemplo n.º 1
0
def test_structEquality():
    a = TopLevelStruct(required='bye', second_level=SecondLevelStruct(deeper_required_prop='ciao'))
    b = TopLevelStruct(required='hello', second_level=1),
    c = TopLevelStruct(required='hello', second_level=1),
    d = SecondLevelStruct(deeper_required_prop='exists')

    assert a != b
    assert b == c
    assert a != 5
    assert a != d
Exemplo n.º 2
0
def test_structEquality():
    a = TopLevelStruct(
        required="bye", second_level=SecondLevelStruct(deeper_required_prop="ciao")
    )
    b = (TopLevelStruct(required="hello", second_level=1),)
    c = (TopLevelStruct(required="hello", second_level=1),)
    d = SecondLevelStruct(deeper_required_prop="exists")

    assert a != b
    assert b == c
    assert a != 5
    assert a != d
Exemplo n.º 3
0
def test_passStructsInVariadic():
    output = StructPassing.how_many_var_args_did_i_pass(
        123, TopLevelStruct(required='hello', second_level=1),
        TopLevelStruct(
            required='bye',
            second_level=SecondLevelStruct(deeper_required_prop='ciao')))
    assert output == 2
Exemplo n.º 4
0
def test_passStructsInVariadic():
    output = StructPassing.how_many_var_args_did_i_pass(
        123,
        TopLevelStruct(required="hello", second_level=1),
        TopLevelStruct(
            required="bye", second_level=SecondLevelStruct(deeper_required_prop="ciao")
        ),
    )
    assert output == 2
Exemplo n.º 5
0
def test_passNestedStruct():
    output = StructPassing.round_trip(123,
            required='hello',
            second_level=SecondLevelStruct(deeper_required_prop='exists'))

    assert output.required == 'hello'
    assert output.optional is None
    assert output.second_level.deeper_required_prop == 'exists'

    # Test stringification
    # Dicts are ordered in Python 3.7+, so this is fine: https://mail.python.org/pipermail/python-dev/2017-December/151283.html
    assert str(output) == "TopLevelStruct(required='hello', second_level=SecondLevelStruct(deeper_required_prop='exists'))"