test_numconv.py 1.05 KB
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
29
30
31
32
33
34
35
36
37
38
import itertools
import unittest
from numba.core.compiler import compile_isolated
from numba.core import types


def template(fromty, toty):
    def closure(self):
        def cast(x):
            y = x
            return y

        cres = compile_isolated(cast, args=[fromty], return_type=toty)
        self.assertAlmostEqual(cres.entry_point(1), 1)

    return closure


class TestNumberConversion(unittest.TestCase):
    """
    Test all int/float numeric conversion to ensure we have all the external
    dependencies to perform these conversions.
    """
    # NOTE: more implicit tests are in test_numberctor

    @classmethod
    def automatic_populate(cls):
        tys = types.integer_domain | types.real_domain
        for fromty, toty in itertools.permutations(tys, r=2):
            test_name = "test_{fromty}_to_{toty}".format(fromty=fromty,
                                                         toty=toty)
            setattr(cls, test_name, template(fromty, toty))


TestNumberConversion.automatic_populate()

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