test_errormodels.py 585 Bytes
Newer Older
dugupeiwen's avatar
dugupeiwen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Test setting/overriding error models
"""

from numba import jit
import unittest


class TestErrorModel(unittest.TestCase):

    def test_div_by_zero_python(self):
        @jit   # python model is the default
        def model_python(val):
            return 1 / val

        with self.assertRaises(ZeroDivisionError):
            model_python(0)

    def test_div_by_zero_numpy(self):
        @jit(error_model='numpy')
        def model_numpy(val):
            return 1 / val

        self.assertEqual(model_numpy(0), float('inf'))


if __name__ == '__main__':
    unittest.main()