コード例 #1
0
def test_python_only_u32():
    def return_true():
        return True

    def return_false():
        return False

    def return_non_zero():
        return 3

    def return_string():
        return "string"

    # U32 datatype creation from boolean forms
    assert U32Value(True).value == 1
    assert U32Value(return_true()).value == 1
    assert U32Value(not return_false()).value == 1
    assert U32Value(U32Value(True)).value == 1
    assert U32Value(U32Value(True).value).value == 1
    assert U32Value(U32Value(return_true())).value == 1
    assert U32Value(False).value == 0
    assert U32Value(return_false()).value == 0
    assert U32Value(not return_true()).value == 0
    assert U32Value(U32Value(False)).value == 0
    assert U32Value(U32Value(False).value).value == 0
    assert U32Value(U32Value(return_false())).value == 0

    # U32 datatype creation from numeric forms
    assert U32Value(3).value == 3
    assert U32Value(3.3).value == 3
    assert U32Value(DoubleValue(3.3)).value == 3
    assert U32Value(return_non_zero()).value == return_non_zero()
    assert U32Value(U32Value(3)).value == 3
    assert U32Value(U32Value(3).value).value == 3

    # U32 datatype creation from expression
    assert U32Value(2 + 1).value == 3
    assert U32Value(False and True).value == 0
    assert U32Value(5 < 10).value == 1
    assert U32Value(return_non_zero() > 1).value == 1

    # U32 datatype creation from array
    assert U32Value(U32ValueArray([1, 3])[0]).value == 1
    assert U32Value([1, 3][1]).value == 3

    # U32 datatype creation that should fail
    with pytest.raises(TypeError):
        U32Value('3')
    with pytest.raises(TypeError):
        U32Value('string')
    with pytest.raises(TypeError):
        U32Value(object())
    with pytest.raises(TypeError):
        U32Value([])
    with pytest.raises(TypeError):
        U32Value(U32ValueArray([1]))
コード例 #2
0
def uint32_array_overflow():
    a = U32ValueArray([0x800000001, 0x80000000])
    return a.value
コード例 #3
0
def uint32_array_negative_values():
    a = U32ValueArray(
        [-5, -1])  # noqa: F841 it's ok for this variable to never be used
コード例 #4
0
def uint32_array_invalid_type1():
    a = U32ValueArray(
        [5, '5'])  # noqa: F841 it's ok for this variable to never be used
コード例 #5
0
def uint32_array_type_run():
    a = U32ValueArray([0, 1, 5])
    return a[2].value
コード例 #6
0
def uint32_array_one_element_run():
    a = U32ValueArray([1])
    return a[0].value
コード例 #7
0
def uint32_array_empty():
    a = U32ValueArray(
        [])  # noqa: F841 it's ok for this variable to never be used
コード例 #8
0
def uint32_array_type():
    a = U32ValueArray(
        [0, 1, 5])  # noqa: F841 it's ok for this variable to never be used
コード例 #9
0
def uint32_array_one_element():
    a = U32ValueArray(
        [1])  # noqa: F841 it's ok for this variable to never be used