Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add test for user exception in @unbox
  • Loading branch information
AlexanderKalistratov committed Jan 5, 2020
commit 1aa9bc31fa166aad12ca13e117e30782ebddccb9
53 changes: 51 additions & 2 deletions sdc/tests/test_hpat_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import pandas as pd
from sdc import *
from numba.typed import Dict
from numba.extending import (overload_method, overload, models, register_model, intrinsic)
from numba.extending import (overload_method, overload, models, register_model,
intrinsic, unbox, typeof_impl, make_attribute_wrapper,
NativeValue)
from numba.special import literally
from numba.typing import signature
from numba import cgutils
Expand Down Expand Up @@ -488,7 +490,54 @@ def test_impl(a):
return d.lit(a)

jtest = numba.njit(test_impl)
test_impl(5)
self.assertEqual(jtest(5), 5)

@unittest.expectedFailure
def test_unbox_with_exception(self):
class Dummy:
def __init__(self, a=0):
self.a = a

class DummyType(numba.types.Type):
def __init__(self):
super().__init__(name="dummy")

@register_model(DummyType)
class DummyTypeModel(models.StructModel):
def __init__(self, dmm, fe_type):
members = [('a', numba.types.int64)]
super().__init__(dmm, fe_type, members)

@unbox(DummyType)
def unbox_dummy(typ, val, c):
context = c.context
builder = c.builder

a_obj = c.pyapi.object_getattr_string(val, "a")
a_value = c.pyapi.long_as_longlong(a_obj)

dmm = cgutils.create_struct_proxy(typ)(context, builder)

with builder.if_then(a_value):
context.call_conv.return_user_exc(
builder, ValueError,
("exception!",)
)

dmm.a = a_value
return NativeValue(dmm._getvalue())

make_attribute_wrapper(DummyType, 'a', 'a')

def test_impl(d):
return d.a

@typeof_impl.register(Dummy)
def typeof_dummy(val, c):
return DummyType()

jtest = numba.njit(test_impl)
print(jtest(Dummy(0)))


if __name__ == "__main__":
Expand Down