test_interface.py 1.92 KB
Newer Older
Jait Dixit's avatar
Jait Dixit committed
1
2
3
4
import unittest
import numpy as np

from itertools import product
Jait Dixit's avatar
Jait Dixit committed
5
6
7
from d2o import distributed_data_object
from types import LambdaType
from numpy.testing import assert_, assert_raises, assert_equal
Jait Dixit's avatar
Jait Dixit committed
8
from nifty import RGSpace, LMSpace, GLSpace, HPSpace
Jait Dixit's avatar
Jait Dixit committed
9
from nifty.config import dependency_injector as di
Jait Dixit's avatar
Jait Dixit committed
10
11
12
from test.common import expand


Jait Dixit's avatar
Jait Dixit committed
13
14
def generate_spaces():
    spaces = [RGSpace(4)]
Jait Dixit's avatar
Jait Dixit committed
15

Jait Dixit's avatar
Jait Dixit committed
16
17
18
19
20
21
    if 'healpy' in di:
        spaces.append(HPSpace(4))
    if 'libsharp_wrapper_gl' in di:
        spaces.append(GLSpace(4))
    if 'healpy' in di or 'libsharp_wrapper_gl' in di:
        spaces.append(LMSpace(5))
Jait Dixit's avatar
Jait Dixit committed
22

Jait Dixit's avatar
Jait Dixit committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    return spaces


class SpaceInterfaceTests(unittest.TestCase):
    def test_dependency_handling(self):
        if 'healpy' not in di and 'libsharp_wrapper_gl' not in di:
            with assert_raises(ImportError):
                LMSpace(5)
        elif 'healpy' not in di:
            with assert_raises(ImportError):
                HPSpace(4)
        elif 'libsharp_wrapper_gl' not in di:
            with assert_raises(ImportError):
                GLSpace(4)

    @expand(product(generate_spaces(), [['dtype', np.dtype],
                    ['harmonic', bool],
                    ['shape', tuple],
                    ['dim', int],
                    ['total_volume', np.float]]))
    def test_property_ret_type(self, space, attr_expected_type):
        assert_(
            isinstance(getattr(
                space,
                attr_expected_type[0]
            ), attr_expected_type[1])
        )

    @expand(product(generate_spaces(), [
        ['get_fft_smoothing_kernel_function', None, LambdaType],
        ['get_fft_smoothing_kernel_function', 2.0, LambdaType],
        ]))
    def test_method_ret_type(self, space, method_expected_type):

        assert_equal(
            type(getattr(
                space,
                method_expected_type[0])(*method_expected_type[1:-1])
            ),
            method_expected_type[-1]
        )