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()
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.'
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'
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.'
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'
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'