test_interface.py 2.1 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
from types import LambdaType
from numpy.testing import assert_, assert_raises, assert_equal
7
8
from nose.plugins.skip import SkipTest
from nifty import LMSpace, GLSpace, HPSpace
Jait Dixit's avatar
Jait Dixit committed
9
from nifty.config import dependency_injector as di
10
from test.common import expand, generate_spaces
Jait Dixit's avatar
Jait Dixit committed
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
39
40
41
42


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):
43
44
45
46
47
48
        # handle exceptions here
        try:
            getattr(
                space, method_expected_type[0])(*method_expected_type[1:-1])
        except NotImplementedError:
            raise SkipTest
Jait Dixit's avatar
Jait Dixit committed
49
50
51
52
53
54
55
56

        assert_equal(
            type(getattr(
                space,
                method_expected_type[0])(*method_expected_type[1:-1])
            ),
            method_expected_type[-1]
        )
57
58
59
60
61
62
63

    @expand([[space] for space in generate_spaces()])
    def test_copy(self, space):
        # make sure it's a deep copy
        assert_(space is not space.copy())
        # make sure contents are the same
        assert_equal(space, space.copy())