Example #1
0
def test_torst():
    keys = ['TEST', 'THIS']
    types = [int, float]
    descr = ['This is a test', 'And so is this']
    db = DataTable(keys, types, descr=descr, shape=10)
    # Just test for success of the method
    lines = db.to_rst_table()
Example #2
0
def test_tohdu():
    keys = ['TEST', 'THIS']
    types = [int, float]
    descr = ['This is a test', 'And so is this']
    db = DataTable(keys, types, descr=descr, shape=10)

    hdu = fits.HDUList([fits.PrimaryHDU(), db.to_hdu(name='TABLE')])

    assert isinstance(hdu['TABLE'], fits.BinTableHDU), 'Bad return type'
    assert numpy.array_equal(hdu['TABLE'].data['TEST'],
                             db['TEST']), 'Arrays are different.'
    assert numpy.array_equal(hdu['TABLE'].data['THIS'],
                             db['THIS']), 'Arrays are different.'
Example #3
0
def test_dtype():
    keys = ['TEST', 'THIS']
    types = [int, float]
    descr = ['This is a test', 'And so is this']
    db = DataTable(keys, types, descr=descr, shape=10)

    _dtype = numpy.dtype([(k, t) for k, t in zip(keys, types)])
    assert db.dtype == _dtype, 'dtype is wrong'
Example #4
0
def test_access():
    keys = ['TEST', 'THIS']
    types = [int, float]
    descr = ['This is a test', 'And so is this']
    db = DataTable(keys, types, descr=descr, shape=10)

    assert numpy.array_equal(db['TEST'], numpy.zeros(10, dtype=int)), \
                'Instantiation array is wrong.'

    db['THIS'] = numpy.arange(10)
    assert numpy.array_equal(db['THIS'], numpy.arange(10, dtype=float)), \
                'Assignment went wrong.'

    db['THIS'][5] = 20.
    assert db['THIS'][5] == 20., 'Assignment of single value went wrong.'

    db[5]['THIS'] = 100.
    assert db['THIS'][5] == 100., 'Assignment of single value went wrong.'
Example #5
0
def test_init():
    keys = ['TEST', 'THIS']
    types = [int, float]
    descr = ['This is a test', 'And so is this']

    # Test at instantiation
    db = DataTable(keys, types, descr=descr, shape=10)
    assert db.data is not None, 'Data should have been instantiated'
    assert db.shape == (10, ), 'Shape is incorrect'

    # Test after the fact
    db = DataTable(keys, types, descr=descr)
    db.init(10)
    assert db.data is not None, 'Data should have been instantiated'
    assert db.shape == (10, ), 'Shape is incorrect'
Example #6
0
def test_empty():
    keys = ['TEST', 'THIS']
    types = [int, float]
    descr = ['This is a test', 'And so is this']
    db = DataTable(keys, types, descr=descr)
    assert db.data is None, 'No data should be defined'