Raw File
Tip revision: 0d99c94d2bc0558e519d1d2302673c213f18273b authored by Bryna Hazelton on 14 April 2017, 20:15 UTC
increase version number after addition of uvcal module
Tip revision: 0d99c94
"""Tests for uvbase object."""
import as nt
import numpy as np
import copy
from pyuvdata import UVBase
from pyuvdata import parameter as uvp

class UVTest(UVBase):
    def __init__(self):
        """ UVBase test object. """
        # add some test UVParameters to the class

        self._int1 = uvp.UVParameter('int1', description='integer value',
                                     expected_type=int, value=3)

        self._int2 = uvp.UVParameter('int2', description='integer value',
                                     expected_type=int, value=5)

        self._float1 = uvp.UVParameter('float1', description='float value',
                                       expected_type=np.float, value=18.2)

        self._string = uvp.UVParameter('string', description='string value',
                                       expected_type=str, value='test')

        self._floatarr = uvp.UVParameter('floatarr', description='float array',
                                         form=('int1', 'int2'),

        self._strlist = uvp.UVParameter('strlist', description='string list',
                                        form=('int1',), expected_type=str,
                                        value=['s' + str(i) for i in np.arange(self._int1.value)])

        self._intlist = uvp.UVParameter('intlist', description='integer list',
                                        form=('int1',), expected_type=int,
                                        value=[i for i in np.arange(self._int1.value)])
        super(UVTest, self).__init__()

def test_equality():
    """Basic equality test."""
    test_obj = UVTest()
    nt.assert_equal(test_obj, test_obj)

def test_inequality():
    """Check that inequality is handled correctly."""
    test_obj = UVTest()
    test_obj2 = copy.deepcopy(test_obj)
    test_obj2.float1 = 13
    nt.assert_not_equal(test_obj, test_obj2)

def test_class_inequality():
    """Test equality error for different classes."""
    test_obj = UVTest()
    nt.assert_not_equal(test_obj, test_obj._floatarr)

def test_check():
    """Test simple check function."""
    test_obj = UVTest()

def test_string_check():
    """Test check function with wrong type (string)."""
    test_obj = UVTest()
    test_obj.string = 1
    nt.assert_raises(ValueError, test_obj.check)

def test_single_value_check():
    """Test check function with wrong dimensions or type."""
    test_obj = UVTest()
    test_obj.int1 += 4
    nt.assert_raises(ValueError, test_obj.check)
    test_obj.int1 = np.float(4)
    nt.assert_raises(ValueError, test_obj.check)

def test_array():
    """Test check function with wrong array dimensions or type."""
    test_obj = UVTest()

    test_obj.floatarr = test_obj.floatarr + 1j * test_obj.floatarr
    nt.assert_raises(ValueError, test_obj.check)

    test_obj.floatarr = np.array([4, 5, 6], dtype=np.float)
    nt.assert_raises(ValueError, test_obj.check)

def test_list_dims():
    """Test check function with wrong list dimensions."""
    test_obj = UVTest()
    test_obj.strlist = ['s' + str(i) for i in np.arange(test_obj.int2)]
    nt.assert_raises(ValueError, test_obj.check)

def test_list_dims():
    """Test check function with wrong list type."""
    test_obj = UVTest()
    test_obj.intlist = ['s' + str(i) for i in np.arange(test_obj.int1)]
    nt.assert_raises(ValueError, test_obj.check)

    test_obj.intlist = [i for i in np.arange(test_obj.int1)]
    test_obj.intlist[1] = 'test'
    nt.assert_raises(ValueError, test_obj.check)
back to top