Ejemplo n.º 1
0
def test_is_properties():
    t = Type()
    assert t._is_ok and t.is_void
    t = Type('i')
    assert t._is_ok and t.is_atomic
    t = Type('ij')
    assert t._is_ok and t.is_atomic
    t = Type_fromstring('ij')
    assert t._is_ok and t.is_atomic
    t = Type_fromstring('i,j')
    assert t._is_ok and t.is_atomic  # !
    t = Type_fromstring('i  *')
    assert t._is_ok and t.is_pointer
    t = Type_fromstring('*')
    assert t._is_ok and t.is_pointer
    t = Type_fromstring('i* * ')
    assert t._is_ok and t.is_pointer
    t = Type_fromstring('i(j)')
    assert t._is_ok and t.is_function
    t = Type_fromstring('(j)')
    assert t._is_ok and t.is_function
    t = Type_fromstring('()')
    assert t._is_ok and t.is_function
    t = Type_fromstring('{i, j}')
    assert t._is_ok and t.is_struct

    with pytest.raises(ValueError,
                       match=r'attempt to create an invalid Type object from'):
        Type('a', 'b')
Ejemplo n.º 2
0
 def __typesystem_type__(self):
     element_type = self[0][0]
     ptrs_t = element_type.pointer().pointer().params(name='ptrs')
     length_t = Type.fromstring('int64 length')
     size_t = Type.fromstring('int64 size')
     return Type(ptrs_t, length_t, size_t).params(
         NumbaPointerType=OmnisciColumnListNumbaType).pointer()
Ejemplo n.º 3
0
def test_is_properties(target_info):
    t = Type()
    assert t._is_ok and t.is_void
    t = Type('i')
    assert t._is_ok and t.is_atomic
    t = Type('ij')
    assert t._is_ok and t.is_atomic
    t = Type.fromstring('ij')
    assert t._is_ok and t.is_atomic
    t = Type.fromstring('i,j')
    assert t._is_ok and t.is_atomic  # !
    t = Type.fromstring('i  *')
    assert t._is_ok and t.is_pointer
    t = Type.fromstring('*')
    assert t._is_ok and t.is_atomic  # !
    t = Type.fromstring('*i')
    assert t._is_ok and t.is_atomic  # !
    t = Type.fromstring('i* * ')
    assert t._is_ok and t.is_pointer
    t = Type.fromstring('i(j)')
    assert t._is_ok and t.is_function and t.name == ''
    t = Type.fromstring('(j)')
    assert t._is_ok and t.is_function and t.name == ''
    t = Type.fromstring('()')
    assert t._is_ok and t.is_function and t.name == ''
    t = Type.fromstring('i f(j)')
    assert t._is_ok and t.is_function and t.name == 'f'
    t = Type.fromstring('void f(j)')
    assert t._is_ok and t.is_function and t.name == 'f'
    t = Type.fromstring('void f()')
    assert t._is_ok and t.is_function and t.name == 'f'
    t = Type.fromstring('i(j) f')
    assert t._is_ok and t.is_function and t.name == 'f'
    t = Type.fromstring('(j) f')
    assert t._is_ok and t.is_function and t.name == 'f'
    t = Type.fromstring('() f')
    assert t._is_ok and t.is_function and t.name == 'f'
    t = Type.fromstring('{i, j}')
    assert t._is_ok and t.is_struct
    t = Type.fromstring('A<i>')
    assert t._is_ok and t.is_custom

    with pytest.raises(ValueError,
                       match=r'attempt to create an invalid Type object from'):
        Type('a', 'b')
Ejemplo n.º 4
0
 def __typesystem_type__(self):
     ptr_t = Type.fromstring("int8 ptr")
     return Type(ptr_t).params(NumbaPointerType=OmnisciTableFunctionManagerNumbaType).pointer()
Ejemplo n.º 5
0
def test_fromstring():
    assert Type_fromstring('void') == Type()
    assert Type_fromstring('') == Type()
    assert Type_fromstring('none') == Type()
    assert Type_fromstring('i') == Type('int32')
    assert Type_fromstring('i*') == Type(Type('int32'), '*')
    assert Type_fromstring('*') == Type(Type(), '*')
    assert Type_fromstring('void*') == Type(Type(), '*')
    assert Type_fromstring('{i,j}') == Type(Type('int32'), Type('j'))
    assert Type_fromstring('i(j)') == Type(Type('int32'), (Type('j'), ))
    assert Type_fromstring('i(j , k)') == Type(Type('int32'),
                                               (Type('j'), Type('k')))
    assert Type_fromstring('  (j , k) ') == Type(Type(),
                                                 (Type('j'), Type('k')))
    assert Type_fromstring('void(j,k)') == Type(Type(), (Type('j'), Type('k')))

    assert Type_fromstring('i a') == Type('int32', name='a')
    assert Type_fromstring('i* a') == Type(Type('int32'), '*', name='a')
    assert Type_fromstring('{i,j} a') == Type(Type('int32'),
                                              Type('j'),
                                              name='a')
    assert Type_fromstring('i(j) a') == Type(Type('int32'), (Type('j'), ),
                                             name='a')
    assert Type_fromstring('i a*') == Type(Type('int32', name='a'), '*')
    assert Type_fromstring('{i a,j b} c') == Type(Type('int32', name='a'),
                                                  Type('j', name='b'),
                                                  name='c')

    with pytest.raises(ValueError, match=r'failed to find lparen index in'):
        Type_fromstring('a)')

    with pytest.raises(ValueError, match=r'failed to comma-split'):
        Type_fromstring('a((b)')

    with pytest.raises(ValueError, match=r'failed to comma-split'):
        Type_fromstring('a((b)')

    with pytest.raises(ValueError, match=r'mismatching curly parenthesis in'):
        Type_fromstring('ab}')