Ejemplo n.º 1
0
def _():
    MyClass1 = type(native_string('Element'), (object, ), {})  # pylint: disable=invalid-name
    MyClass2 = type(native_string('Element'), (object, ), {})  # pylint: disable=invalid-name

    class MyRecord(Record):
        elems = dict_of(int, MyClass1)

    with assert_raises(FieldTypeError):
        MyRecord(elems={9: MyClass2()})
Ejemplo n.º 2
0
def _():
    MyClass1 = type(native_string('Element'), (object, ), {})  # pylint: disable=invalid-name
    MyClass2 = type(native_string('Element'), (object, ), {})  # pylint: disable=invalid-name

    class Record1(Record):
        elems = seq_of(MyClass1)

    class Record2(Record):
        elems = seq_of(MyClass2)

    r1 = Record1(elems=[MyClass1()])
    r2 = Record2(elems=[MyClass2()])
    assert_eq(r1.elems.__class__.__name__, 'ElementSeq')
    assert_eq(r2.elems.__class__.__name__, 'ElementSeq')
    assert r1.elems.__class__ is not r2.elems.__class__
Ejemplo n.º 3
0
def _():
    MyClass1 = type(native_string('Element'), (object, ), {})  # pylint: disable=invalid-name
    MyClass2 = type(native_string('Element'), (object, ), {})  # pylint: disable=invalid-name

    class Record1(Record):
        elems = dict_of(int, MyClass1)

    class Record2(Record):
        elems = dict_of(int, MyClass2)

    r1 = Record1(elems={9: MyClass1()})
    r2 = Record2(elems={9: MyClass2()})
    assert_eq(r1.elems.__class__.__name__, 'IntToElementDict')
    assert_eq(r2.elems.__class__.__name__, 'IntToElementDict')
    assert r1.elems.__class__ is not r2.elems.__class__
Ejemplo n.º 4
0
def _():
    MyType = ABCMeta(  # pylint: disable=invalid-name
        native_string('MyType'),
        (object, ),
        {},
    )
    MyType.register(int)

    class MyRecord(Record):
        value = MyType

    assert_eq(
        MyRecord(value=42).value,
        42,
    )