Example #1
0
def test_overload_selection_with_arrays_of_generic_types():
    """Check overload selection using arrays of generic types."""
    from Python.Test import ISayHello1, InterfaceTest, ShortEnum
    from Python.Test import MethodTest, GenericWrapper

    inst = InterfaceTest()

    gtype = GenericWrapper[System.Boolean]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(True), gtype(True)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value is True
    assert value.Length == 2

    gtype = GenericWrapper[bool]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(True), gtype(True)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value is True
    assert value.Length == 2

    gtype = GenericWrapper[System.Byte]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(255), gtype(255)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 255
    assert value.Length == 2

    gtype = GenericWrapper[System.SByte]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(127), gtype(127)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 127
    assert value.Length == 2

    gtype = GenericWrapper[System.Char]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(u'A'), gtype(u'A')])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == u'A'
    assert value.Length == 2

    gtype = GenericWrapper[System.Char]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(65535), gtype(65535)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == chr(65535)
    assert value.Length == 2

    gtype = GenericWrapper[System.Int16]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(32767), gtype(32767)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 32767
    assert value.Length == 2

    gtype = GenericWrapper[System.Int32]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(2147483647), gtype(2147483647)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 2147483647
    assert value.Length == 2

    gtype = GenericWrapper[int]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(2147483647), gtype(2147483647)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 2147483647
    assert value.Length == 2

    gtype = GenericWrapper[System.Int64]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(9223372036854775807),
                    gtype(9223372036854775807)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 9223372036854775807
    assert value.Length == 2

    gtype = GenericWrapper[System.UInt16]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(65000), gtype(65000)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 65000
    assert value.Length == 2

    gtype = GenericWrapper[System.UInt32]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(4294967295), gtype(4294967295)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 4294967295
    assert value.Length == 2

    gtype = GenericWrapper[System.UInt64]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(18446744073709551615),
                    gtype(18446744073709551615)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 18446744073709551615
    assert value.Length == 2

    gtype = GenericWrapper[System.Single]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(3.402823e38), gtype(3.402823e38)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == System.Single(3.402823e38)
    assert value.Length == 2

    gtype = GenericWrapper[System.Double]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(1.7976931348623157e308),
                    gtype(1.7976931348623157e308)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 1.7976931348623157e308
    assert value.Length == 2

    gtype = GenericWrapper[float]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(1.7976931348623157e308),
                    gtype(1.7976931348623157e308)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 1.7976931348623157e308
    assert value.Length == 2

    gtype = GenericWrapper[System.Decimal]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(System.Decimal.One),
                    gtype(System.Decimal.One)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == System.Decimal.One
    assert value.Length == 2

    gtype = GenericWrapper[System.String]
    vtype = System.Array[gtype]
    input_ = vtype([gtype("spam"), gtype("spam")])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == "spam"
    assert value.Length == 2

    gtype = GenericWrapper[str]
    vtype = System.Array[gtype]
    input_ = vtype([gtype("spam"), gtype("spam")])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == "spam"
    assert value.Length == 2

    gtype = GenericWrapper[ShortEnum]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(ShortEnum.Zero), gtype(ShortEnum.Zero)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == ShortEnum.Zero
    assert value.Length == 2

    gtype = GenericWrapper[System.Object]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(inst), gtype(inst)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value.__class__ == inst.__class__
    assert value.Length == 2

    gtype = GenericWrapper[InterfaceTest]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(inst), gtype(inst)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value.__class__ == inst.__class__
    assert value.Length == 2

    iface_class = ISayHello1(inst).__class__
    gtype = GenericWrapper[ISayHello1]
    vtype = System.Array[gtype]
    input_ = vtype([gtype(inst), gtype(inst)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value.__class__ == iface_class
    assert value.Length == 2
Example #2
0
def test_method_overload_selection_with_generic_types():
    """Check method overload selection using generic types."""
    from Python.Test import ISayHello1, InterfaceTest, ShortEnum
    from Python.Test import MethodTest, GenericWrapper

    inst = InterfaceTest()

    vtype = GenericWrapper[System.Boolean]
    input_ = vtype(True)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value is True

    vtype = GenericWrapper[bool]
    input_ = vtype(True)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value is True

    vtype = GenericWrapper[System.Byte]
    input_ = vtype(255)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 255

    vtype = GenericWrapper[System.SByte]
    input_ = vtype(127)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 127

    vtype = GenericWrapper[System.Char]
    input_ = vtype(u'A')
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == u'A'

    vtype = GenericWrapper[System.Char]
    input_ = vtype(65535)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == chr(65535)

    vtype = GenericWrapper[System.Int16]
    input_ = vtype(32767)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 32767

    vtype = GenericWrapper[System.Int32]
    input_ = vtype(2147483647)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 2147483647

    vtype = GenericWrapper[int]
    input_ = vtype(2147483647)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 2147483647

    vtype = GenericWrapper[System.Int64]
    input_ = vtype(9223372036854775807)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 9223372036854775807

    vtype = GenericWrapper[System.UInt16]
    input_ = vtype(65000)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 65000

    vtype = GenericWrapper[System.UInt32]
    input_ = vtype(4294967295)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 4294967295

    vtype = GenericWrapper[System.UInt64]
    input_ = vtype(18446744073709551615)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 18446744073709551615

    vtype = GenericWrapper[System.Single]
    input_ = vtype(3.402823e38)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == System.Single(3.402823e38)

    vtype = GenericWrapper[System.Double]
    input_ = vtype(1.7976931348623157e308)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 1.7976931348623157e308

    vtype = GenericWrapper[float]
    input_ = vtype(1.7976931348623157e308)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == 1.7976931348623157e308

    vtype = GenericWrapper[System.Decimal]
    input_ = vtype(System.Decimal.One)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == System.Decimal.One

    vtype = GenericWrapper[System.String]
    input_ = vtype("spam")
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == "spam"

    vtype = GenericWrapper[str]
    input_ = vtype("spam")
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == "spam"

    vtype = GenericWrapper[ShortEnum]
    input_ = vtype(ShortEnum.Zero)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value == ShortEnum.Zero

    vtype = GenericWrapper[System.Object]
    input_ = vtype(inst)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value.__class__ == inst.__class__

    vtype = GenericWrapper[InterfaceTest]
    input_ = vtype(inst)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value.__class__ == inst.__class__

    iface_class = ISayHello1(inst).__class__
    vtype = GenericWrapper[ISayHello1]
    input_ = vtype(inst)
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value.value.__class__ == iface_class

    vtype = System.Array[GenericWrapper[int]]
    input_ = vtype([GenericWrapper[int](0), GenericWrapper[int](1)])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].value == 0
    assert value[1].value == 1
Example #3
0
def test_overload_selection_with_array_types():
    """Check overload selection using array types."""
    from Python.Test import ISayHello1, InterfaceTest, ShortEnum
    from System import Array

    inst = InterfaceTest()

    vtype = Array[System.Boolean]
    input_ = vtype([True, True])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] is True
    assert value[1] is True

    vtype = Array[bool]
    input_ = vtype([True, True])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] is True
    assert value[1] is True

    vtype = Array[System.Byte]
    input_ = vtype([0, 255])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 255

    vtype = Array[System.SByte]
    input_ = vtype([0, 127])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 127

    vtype = Array[System.Char]
    input_ = vtype([u'A', u'Z'])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == u'A'
    assert value[1] == u'Z'

    vtype = Array[System.Char]
    input_ = vtype([0, 65535])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == chr(0)
    assert value[1] == chr(65535)

    vtype = Array[System.Int16]
    input_ = vtype([0, 32767])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 32767

    vtype = Array[System.Int32]
    input_ = vtype([0, 2147483647])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 2147483647

    vtype = Array[int]
    input_ = vtype([0, 2147483647])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 2147483647

    vtype = Array[System.Int64]
    input_ = vtype([0, 9223372036854775807])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 9223372036854775807

    vtype = Array[System.UInt16]
    input_ = vtype([0, 65000])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 65000

    vtype = Array[System.UInt32]
    input_ = vtype([0, 4294967295])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 4294967295

    vtype = Array[System.UInt64]
    input_ = vtype([0, 18446744073709551615])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0
    assert value[1] == 18446744073709551615

    vtype = Array[System.Single]
    input_ = vtype([0.0, 3.402823e38])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0.0
    assert value[1] == 3.402823e38

    vtype = Array[System.Double]
    input_ = vtype([0.0, 1.7976931348623157e308])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0.0
    assert value[1] == 1.7976931348623157e308

    vtype = Array[float]
    input_ = vtype([0.0, 1.7976931348623157e308])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == 0.0
    assert value[1] == 1.7976931348623157e308

    vtype = Array[System.Decimal]
    input_ = vtype([System.Decimal.Zero, System.Decimal.One])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == System.Decimal.Zero
    assert value[1] == System.Decimal.One

    vtype = Array[System.String]
    input_ = vtype(["one", "two"])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == "one"
    assert value[1] == "two"

    vtype = Array[str]
    input_ = vtype(["one", "two"])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == "one"
    assert value[1] == "two"

    vtype = Array[ShortEnum]
    input_ = vtype([ShortEnum.Zero, ShortEnum.One])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0] == ShortEnum.Zero
    assert value[1] == ShortEnum.One

    vtype = Array[System.Object]
    input_ = vtype([inst, inst])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].__class__ == inst.__class__
    assert value[1].__class__ == inst.__class__

    vtype = Array[InterfaceTest]
    input_ = vtype([inst, inst])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].__class__ == inst.__class__
    assert value[1].__class__ == inst.__class__

    iface_class = ISayHello1(inst).__class__
    vtype = Array[ISayHello1]
    input_ = vtype([inst, inst])
    value = MethodTest.Overloaded.__overloads__[vtype](input_)
    assert value[0].__class__ == iface_class
    assert value[1].__class__ == iface_class
Example #4
0
def test_special_array_creation():
    """Test using the Array[<type>] syntax for creating arrays."""
    from Python.Test import ISayHello1, InterfaceTest, ShortEnum
    from System import Array
    inst = InterfaceTest()

    value = Array[System.Boolean]([True, True])
    assert value[0] is True
    assert value[1] is True
    assert value.Length == 2

    value = Array[bool]([True, True])
    assert value[0] is True
    assert value[1] is True
    assert value.Length == 2

    value = Array[System.Byte]([0, 255])
    assert value[0] == 0
    assert value[1] == 255
    assert value.Length == 2

    value = Array[System.SByte]([0, 127])
    assert value[0] == 0
    assert value[1] == 127
    assert value.Length == 2

    value = Array[System.Char]([u'A', u'Z'])
    assert value[0] == u'A'
    assert value[1] == u'Z'
    assert value.Length == 2

    value = Array[System.Char]([0, 65535])
    assert value[0] == chr(0)
    assert value[1] == chr(65535)
    assert value.Length == 2

    value = Array[System.Int16]([0, 32767])
    assert value[0] == 0
    assert value[1] == 32767
    assert value.Length == 2

    value = Array[System.Int32]([0, 2147483647])
    assert value[0] == 0
    assert value[1] == 2147483647
    assert value.Length == 2

    value = Array[int]([0, 2147483647])
    assert value[0] == 0
    assert value[1] == 2147483647
    assert value.Length == 2

    value = Array[System.Int64]([0, 9223372036854775807])
    assert value[0] == 0
    assert value[1] == 9223372036854775807
    assert value.Length == 2

    value = Array[System.UInt16]([0, 65000])
    assert value[0] == 0
    assert value[1] == 65000
    assert value.Length == 2

    value = Array[System.UInt32]([0, 4294967295])
    assert value[0] == 0
    assert value[1] == 4294967295
    assert value.Length == 2

    value = Array[System.UInt64]([0, 18446744073709551615])
    assert value[0] == 0
    assert value[1] == 18446744073709551615
    assert value.Length == 2

    value = Array[System.Single]([0.0, 3.402823e38])
    assert value[0] == 0.0
    assert value[1] == System.Single(3.402823e38)
    assert value.Length == 2

    value = Array[System.Double]([0.0, 1.7976931348623157e308])
    assert value[0] == 0.0
    assert value[1] == 1.7976931348623157e308
    assert value.Length == 2

    value = Array[float]([0.0, 1.7976931348623157e308])
    assert value[0] == 0.0
    assert value[1] == 1.7976931348623157e308
    assert value.Length == 2

    value = Array[System.Decimal]([System.Decimal.Zero, System.Decimal.One])
    assert value[0] == System.Decimal.Zero
    assert value[1] == System.Decimal.One
    assert value.Length == 2

    value = Array[System.String](["one", "two"])
    assert value[0] == "one"
    assert value[1] == "two"
    assert value.Length == 2

    value = Array[str](["one", "two"])
    assert value[0] == "one"
    assert value[1] == "two"
    assert value.Length == 2

    value = Array[ShortEnum]([ShortEnum.Zero, ShortEnum.One])
    assert value[0] == ShortEnum.Zero
    assert value[1] == ShortEnum.One
    assert value.Length == 2

    value = Array[System.Object]([inst, inst])
    assert value[0].__class__ == inst.__class__
    assert value[1].__class__ == inst.__class__
    assert value.Length == 2

    value = Array[InterfaceTest]([inst, inst])
    assert value[0].__class__ == inst.__class__
    assert value[1].__class__ == inst.__class__
    assert value.Length == 2

    iface_class = ISayHello1(inst).__class__
    value = Array[ISayHello1]([inst, inst])
    assert value[0].__class__ == iface_class
    assert value[1].__class__ == iface_class
    assert value.Length == 2

    inst = System.Exception("badness")
    value = Array[System.Exception]([inst, inst])
    assert value[0].__class__ == inst.__class__
    assert value[1].__class__ == inst.__class__
    assert value.Length == 2
Example #5
0
def test_explicit_overload_selection():
    """Check explicit overload selection using [] syntax."""
    from Python.Test import ISayHello1, InterfaceTest, ShortEnum
    from System import Array

    inst = InterfaceTest()

    value = MethodTest.Overloaded.__overloads__[System.Boolean](True)
    assert value is True

    value = MethodTest.Overloaded.__overloads__[bool](True)
    assert value is True

    value = MethodTest.Overloaded.__overloads__[System.Byte](255)
    assert value == 255

    value = MethodTest.Overloaded.__overloads__[System.SByte](127)
    assert value == 127

    value = MethodTest.Overloaded.__overloads__[System.Char](u'A')
    assert value == u'A'

    value = MethodTest.Overloaded.__overloads__[System.Char](65535)
    assert value == chr(65535)

    value = MethodTest.Overloaded.__overloads__[System.Int16](32767)
    assert value == 32767

    value = MethodTest.Overloaded.__overloads__[System.Int32](2147483647)
    assert value == 2147483647

    value = MethodTest.Overloaded.__overloads__[int](2147483647)
    assert value == 2147483647

    value = MethodTest.Overloaded.__overloads__[System.Int64](
        9223372036854775807)
    assert value == 9223372036854775807

    value = MethodTest.Overloaded.__overloads__[System.UInt16](65000)
    assert value == 65000

    value = MethodTest.Overloaded.__overloads__[System.UInt32](4294967295)
    assert value == 4294967295

    value = MethodTest.Overloaded.__overloads__[System.UInt64](
        18446744073709551615)
    assert value == 18446744073709551615

    value = MethodTest.Overloaded.__overloads__[System.Single](3.402823e38)
    assert value == 3.402823e38

    value = MethodTest.Overloaded.__overloads__[System.Double](
        1.7976931348623157e308)
    assert value == 1.7976931348623157e308

    value = MethodTest.Overloaded.__overloads__[float](1.7976931348623157e308)
    assert value == 1.7976931348623157e308

    value = MethodTest.Overloaded.__overloads__[System.Decimal](
        System.Decimal.One)
    assert value == System.Decimal.One

    value = MethodTest.Overloaded.__overloads__[System.String]("spam")
    assert value == "spam"

    value = MethodTest.Overloaded.__overloads__[str]("spam")
    assert value == "spam"

    value = MethodTest.Overloaded.__overloads__[ShortEnum](ShortEnum.Zero)
    assert value == ShortEnum.Zero

    value = MethodTest.Overloaded.__overloads__[System.Object](inst)
    assert value.__class__ == inst.__class__

    value = MethodTest.Overloaded.__overloads__[InterfaceTest](inst)
    assert value.__class__ == inst.__class__

    iface_class = ISayHello1(InterfaceTest()).__class__
    value = MethodTest.Overloaded.__overloads__[ISayHello1](inst)
    assert value.__class__ != inst.__class__
    assert value.__class__ == iface_class

    atype = Array[System.Object]
    value = MethodTest.Overloaded.__overloads__[str, int,
                                                atype]("one", 1,
                                                       atype([1, 2, 3]))
    assert value == 3

    value = MethodTest.Overloaded.__overloads__[str, int]("one", 1)
    assert value == 1

    value = MethodTest.Overloaded.__overloads__[int, str](1, "one")
    assert value == 1