Skip to content
Snippets Groups Projects
Commit e653a19f authored by Mattia Mancini's avatar Mattia Mancini
Browse files

SSB-47: Remove test for removed code

parent ae1c63e8
Branches
Tags
1 merge request!44Merge back holography to master
...@@ -21,7 +21,6 @@ include(LofarCTest) ...@@ -21,7 +21,6 @@ include(LofarCTest)
lofar_add_test(t_holography_ms_class) lofar_add_test(t_holography_ms_class)
lofar_add_test(t_holography_beam_specification_class) lofar_add_test(t_holography_beam_specification_class)
lofar_add_test(t_holography_datatable_class)
lofar_add_test(t_holography_dataset_class) lofar_add_test(t_holography_dataset_class)
lofar_add_test(t_holography_dataset_class2) lofar_add_test(t_holography_dataset_class2)
lofar_add_test(t_holography_observation) lofar_add_test(t_holography_observation)
......
import logging
import unittest
import numpy
import tempfile
import h5py
from lofar.calibration.common.datacontainers.holography_datatable import LazyH5Table,\
HolographyDataTable
logger = logging.getLogger('t_holography_datatable_class')
def test_data_dict_string_indexes():
frequencies = [str(i) for i in numpy.linspace(0, 1000, 100, dtype=float)]
stations = ['CS001', 'CS002']
beams = [str(int(i)) for i in range(100)]
dset = numpy.random.rand(10)
data_dict = {}
for fr in frequencies:
for station in stations:
for beam in beams:
data_dict[(fr, station, beam)] = dset
return data_dict
class TestLazyH5Table(unittest.TestCase):
def test_create_table(self):
test_data = test_data_dict_string_indexes()
test_uri = '/mytest_uri'
temp_file_name = 'tempFile.h5'
with tempfile.TemporaryDirectory() as temporary_dir:
full_path = temporary_dir + '/' + temp_file_name
logger.info('creating temp file %s', full_path)
h5file = h5py.File(full_path)
data_table = LazyH5Table(uri=test_uri, h5_file=h5file)
for key, value in test_data.items():
data_table[key] = value
h5file.close()
h5file = h5py.File(full_path)
for key, value in test_data.items():
data_uri = '/'.join(key)
self.assertIn(test_uri + '/' + data_uri, h5file)
def test_data_dict_holography_index_types():
frequencies = [i for i in numpy.linspace(0, 1000, 100, dtype=float)]
stations = ['CS001', 'CS002']
beams = [int(i) for i in range(100)]
dset = numpy.random.rand(10)
data_dict = {}
for station in stations:
for fr in frequencies:
for beam in beams:
data_dict[(station, fr, beam)] = dset
return data_dict
class TestHolographyDatasetClass(unittest.TestCase):
def test_create_read_dataset(self):
test_data = test_data_dict_holography_index_types()
test_uri = '/mytest_uri'
temp_file_name = 'tempFile.h5'
with tempfile.TemporaryDirectory() as temporary_dir:
full_path = temporary_dir + '/' + temp_file_name
logger.info('creating temp file %s', full_path)
h5file = h5py.File(full_path, 'w')
data_table = HolographyDataTable(uri=test_uri, h5_file=h5file)
for key, value in test_data.items():
data_table[key] = value
h5file.close()
h5file = h5py.File(full_path, 'r')
data_table = HolographyDataTable(uri=test_uri, h5_file=h5file)
stored_keys = data_table.keys()
stations = set(key[0] for key in stored_keys)
frequencies = set(key[1] for key in stored_keys)
beams = set(key[2] for key in stored_keys)
self.assertEqual(set(data_table.frequencies), frequencies)
self.assertEqual(set(data_table.reference_stations), stations)
self.assertEqual(set(data_table.beam_numbers), beams)
self.assertEqual(stored_keys.difference(test_data.keys()), set())
for key, value in data_table.iter_items():
self.assertIn(key, test_data)
station_name, frequency, beam = key
numpy.testing.assert_array_equal(data_table[station_name, frequency, beam], test_data[key])
for frequency in data_table.frequencies:
for reference_station in data_table.reference_stations:
for beam in data_table.beam_numbers:
self.assertIn((reference_station, frequency, beam), stored_keys)
def test_wrong_index_types(self):
test_uri = '/mytest_uri'
temp_file_name = 'tempFile.h5'
with tempfile.TemporaryDirectory() as temporary_dir:
full_path = temporary_dir + '/' + temp_file_name
logger.info('creating temp file %s', full_path)
h5file = h5py.File(full_path)
data_table = HolographyDataTable(uri=test_uri, h5_file=h5file)
with self.assertRaises(IndexError):
data_table['ref', 1, 1] = 1
with self.assertRaises(IndexError):
data_table['ref', 1., ""] = 1
with self.assertRaises(IndexError):
data_table[1 , 1., 1] = 1
def test_wrong_index_number(self):
test_uri = '/mytest_uri'
temp_file_name = 'tempFile.h5'
with tempfile.TemporaryDirectory() as temporary_dir:
full_path = temporary_dir + '/' + temp_file_name
logger.info('creating temp file %s', full_path)
h5file = h5py.File(full_path)
data_table = HolographyDataTable(uri=test_uri, h5_file=h5file)
with self.assertRaises(IndexError):
data_table[1 , 1.] = 1
with self.assertRaises(IndexError):
data_table[1 , 1., 1, 1] = 1
def test_error_getting_non_existing_data(self):
test_uri = '/mytest_uri'
temp_file_name = 'tempFile.h5'
with tempfile.TemporaryDirectory() as temporary_dir:
full_path = temporary_dir + '/' + temp_file_name
logger.info('creating temp file %s', full_path)
h5file = h5py.File(full_path)
data_table = HolographyDataTable(uri=test_uri, h5_file=h5file)
with self.assertRaises(KeyError):
_ = data_table['stat', 1., 1]
if __name__ == '__main__':
logging.basicConfig(format='%(name)s : %(message)s', level=logging.DEBUG)
unittest.main()
#!/bin/bash
# Copyright (C) 2018 ASTRON (Netherlands Institute for Radio Astronomy)
# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
# Run the unit test
source python-coverage.sh
python_coverage_test "*holography_datatable*" t_holography_datatable_class.py
\ No newline at end of file
#!/bin/sh
# Copyright (C) 2018 ASTRON (Netherlands Institute for Radio Astronomy)
# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
./runctest.sh t_holography_datatable_class
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment