def test_add_module(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in='read1', input_dir=None, image_tag='im_arr1') assert pipeline.add_module(read) is None read = FitsReadingModule(name_in='read2', input_dir=self.test_dir, image_tag='im_arr2') assert pipeline.add_module(read) is None with pytest.warns(UserWarning) as warning: pipeline.add_module(read) assert len(warning) == 1 assert warning[0].message.args[0] == 'Pipeline module names need to be unique. ' \ 'Overwriting module \'read2\'.' process = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_arr1', image_out_tag='im_out') assert pipeline.add_module(process) is None write = FitsWritingModule(name_in='write1', file_name='result.fits', data_tag='im_arr1') assert pipeline.add_module(write) is None write = FitsWritingModule(name_in='write2', file_name='result.fits', data_tag='im_arr1', output_dir=self.test_dir) assert pipeline.add_module(write) is None assert pipeline.run() is None assert pipeline.get_module_names() == ['read1', 'read2', 'badpixel', 'write1', 'write2'] os.remove(self.test_dir+'result.fits') os.remove(self.test_dir+'PynPoint_database.hdf5')
def test_add_module(self) -> None: pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) module = FitsReadingModule(name_in='read1', input_dir=None, image_tag='im_arr1') assert pipeline.add_module(module) is None module = FitsReadingModule(name_in='read2', input_dir=self.test_dir, image_tag='im_arr2') assert pipeline.add_module(module) is None with pytest.warns(UserWarning) as warning: pipeline.add_module(module) assert len(warning) == 1 assert warning[0].message.args[0] == 'Names of pipeline modules that are added to the ' \ 'Pypeline need to be unique. The current pipeline ' \ 'module, \'read2\', does already exist in the ' \ 'Pypeline dictionary so the previous module with ' \ 'the same name will be overwritten.' module = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_arr1', image_out_tag='im_out') assert pipeline.add_module(module) is None module = FitsWritingModule(name_in='write1', file_name='result.fits', data_tag='im_arr1') assert pipeline.add_module(module) is None module = FitsWritingModule(name_in='write2', file_name='result.fits', data_tag='im_arr1', output_dir=self.test_dir) assert pipeline.add_module(module) is None assert pipeline.run() is None assert pipeline.get_module_names() == [ 'read1', 'read2', 'badpixel', 'write1', 'write2' ] os.remove(self.test_dir + 'result.fits') os.remove(self.test_dir + 'PynPoint_database.hdf5')
def test_attribute_length(self): text = 'long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text' self.pipeline.set_attribute('images', 'short', 'value', static=True) self.pipeline.set_attribute('images', 'longer_than_eight1', 'value', static=True) self.pipeline.set_attribute('images', 'longer_than_eight2', text, static=True) module = FitsWritingModule(file_name='test.fits', name_in='write8', output_dir=None, data_tag='images', data_range=None, overwrite=True, subset_size=None) self.pipeline.add_module(module) with pytest.warns(UserWarning) as warning: self.pipeline.run_module('write8') assert len(warning) == 1 assert warning[0].message.args[0] == 'Key \'hierarch longer_than_eight2\' with value ' \ '\'long_text_long_text_long_text_long_text_long_' \ 'text_long_text_long_text_long_text\' is too ' \ 'long for the FITS format. To avoid an error, ' \ 'the value was truncated to \'long_text_long_text' \ '_long_text_long_text_long_tex\'.'
def test_attribute_length(self): text = "long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text" self.pipeline.set_attribute("images", "short", "value", static=True) self.pipeline.set_attribute("images", "longer_than_eight1", "value", static=True) self.pipeline.set_attribute("images", "longer_than_eight2", text, static=True) write = FitsWritingModule(file_name="test.fits", name_in="write6", output_dir=None, data_tag="images", data_range=None, overwrite=True) self.pipeline.add_module(write) with pytest.warns(UserWarning) as warning: self.pipeline.run_module("write6") assert len(warning) == 1 assert warning[0].message.args[0] == "Key 'hierarch longer_than_eight2' with value " \ "'long_text_long_text_long_text_long_text_long_" \ "text_long_text_long_text_long_text' is too " \ "long for the FITS format. To avoid an error, " \ "the value was truncated to 'long_text_long_text" \ "_long_text_long_text_long_tex'."
def test_add_module(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in="read1", input_dir=None, image_tag="im_arr1") assert pipeline.add_module(read) is None read = FitsReadingModule(name_in="read2", input_dir=self.test_dir, image_tag="im_arr2") assert pipeline.add_module(read) is None with pytest.warns(UserWarning) as warning: pipeline.add_module(read) assert len(warning) == 1 assert warning[0].message.args[0] == "Processing module names need to be unique. " \ "Overwriting module 'read2'." process = BadPixelSigmaFilterModule(name_in="badpixel", image_in_tag="im_arr1") assert pipeline.add_module(process) is None write = FitsWritingModule(name_in="write1", file_name="result.fits", data_tag="im_arr1") assert pipeline.add_module(write) is None write = FitsWritingModule(name_in="write2", file_name="result.fits", data_tag="im_arr1", output_dir=self.test_dir) assert pipeline.add_module(write) is None assert pipeline.run() is None assert pipeline.get_module_names() == [ 'read1', 'read2', 'badpixel', 'write1', 'write2' ] os.remove(self.test_dir + "result.fits") os.remove(self.test_dir + "PynPoint_database.hdf5")
def test_write_fits(self): writing = FitsWritingModule(name_in="fits_writing", file_name="test.fits", data_tag="res_mean") self.pipeline.add_module(writing) self.pipeline.run_module("fits_writing") assert os.path.exists(self.test_dir + "test.fits")
def test_filename_extension(self): with pytest.raises(ValueError) as error: FitsWritingModule(file_name='test.dat', name_in='write3', output_dir=None, data_tag='images', data_range=None, overwrite=True) assert str(error.value) == 'Output \'file_name\' requires the FITS extension.'
def test_filename_string(self): with pytest.raises(ValueError) as error: FitsWritingModule(file_name=0., name_in='write2', output_dir=None, data_tag='images', data_range=None, overwrite=True) assert str(error.value) == 'Output \'file_name\' needs to be a string.'
def test_data_range(self): write = FitsWritingModule(file_name="test.fits", name_in="write4", output_dir=None, data_tag="images", data_range=(0, 10), overwrite=True) self.pipeline.add_module(write) self.pipeline.run_module("write4")
def test_data_range(self): write = FitsWritingModule(file_name='test.fits', name_in='write4', output_dir=None, data_tag='images', data_range=(0, 10), overwrite=True) self.pipeline.add_module(write) self.pipeline.run_module('write4')
def test_fits_writing(self): module = FitsWritingModule(file_name='test.fits', name_in='write1', output_dir=None, data_tag='images', data_range=None, overwrite=True) self.pipeline.add_module(module) self.pipeline.run_module('write1')
def test_filename_extension(self): with pytest.raises(ValueError) as error: FitsWritingModule(file_name="test.dat", name_in="write3", output_dir=None, data_tag="images", data_range=None, overwrite=True) assert str( error.value) == "Output 'file_name' requires the FITS extension."
def test_subset_size_data_range(self): module = FitsWritingModule(file_name='test.fits', name_in='write7', output_dir=None, data_tag='images', data_range=(8, 18), overwrite=True, subset_size=10) self.pipeline.add_module(module) self.pipeline.run_module('write7')
def test_run_module_wrong_tag(self) -> None: pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) module = FitsReadingModule(name_in='read') pipeline.add_module(module) module = FitsWritingModule(name_in='write', file_name='result.fits', data_tag='im_list') pipeline.add_module(module) module = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_list', image_out_tag='im_out') pipeline.add_module(module) with pytest.raises(AttributeError) as error: pipeline.run_module('badpixel') assert str(error.value) == 'Pipeline module \'badpixel\' is looking for data under a ' \ 'tag which does not exist in the database.' with pytest.raises(AttributeError) as error: pipeline.run_module('write') assert str(error.value) == 'Pipeline module \'write\' is looking for data under a tag ' \ 'which does not exist in the database.' with pytest.raises(AttributeError) as error: pipeline.run() assert str(error.value) == 'Pipeline module \'write\' is looking for data under a tag ' \ 'which is not created by a previous module or the data does ' \ 'not exist in the database.' assert pipeline.validate_pipeline_module('test') == (False, 'test') with pytest.raises(TypeError) as error: pipeline._validate('module', 'tag') assert str(error.value) == 'type of argument "module" must be one of (ReadingModule, ' \ 'WritingModule, ProcessingModule); got str instead' os.remove(self.test_dir + 'PynPoint_database.hdf5')
def test_not_overwritten(self): write = FitsWritingModule(file_name='test.fits', name_in='write5', output_dir=None, data_tag='images', data_range=None, overwrite=False) self.pipeline.add_module(write) with pytest.warns(UserWarning) as warning: self.pipeline.run_module('write5') assert len(warning) == 1 assert warning[0].message.args[0] == 'Filename already present. Use overwrite=True ' \ 'to overwrite an existing FITS file.'
def test_run_module_wrong_tag(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in='read') pipeline.add_module(read) write = FitsWritingModule(name_in='write', file_name='result.fits', data_tag='im_list') pipeline.add_module(write) process = BadPixelSigmaFilterModule(name_in='badpixel', image_in_tag='im_list', image_out_tag='im_out') pipeline.add_module(process) with pytest.raises(AttributeError) as error: pipeline.run_module('badpixel') assert str(error.value) == 'Pipeline module \'badpixel\' is looking for data under a ' \ 'tag which does not exist in the database.' with pytest.raises(AttributeError) as error: pipeline.run_module('write') assert str(error.value) == 'Pipeline module \'write\' is looking for data under a tag ' \ 'which does not exist in the database.' with pytest.raises(AttributeError) as error: pipeline.run() assert str(error.value) == 'Pipeline module \'write\' is looking for data under a tag ' \ 'which is not created by a previous module or does not exist ' \ 'in the database.' assert pipeline.validate_pipeline_module('test') is None assert pipeline._validate('module', 'tag') == (False, None) os.remove(self.test_dir + 'PynPoint_database.hdf5')
def test_run_module_wrong_tag(self): pipeline = Pypeline(self.test_dir, self.test_dir, self.test_dir) read = FitsReadingModule(name_in="read") pipeline.add_module(read) write = FitsWritingModule(name_in="write", file_name="result.fits", data_tag="im_list") pipeline.add_module(write) process = BadPixelSigmaFilterModule(name_in="badpixel", image_in_tag="im_list") pipeline.add_module(process) with pytest.raises(AttributeError) as error: pipeline.run_module("badpixel") assert str(error.value) == "Pipeline module 'badpixel' is looking for data under a tag " \ "which does not exist in the database." with pytest.raises(AttributeError) as error: pipeline.run_module("write") assert str(error.value) == "Pipeline module 'write' is looking for data under a tag " \ "which does not exist in the database." with pytest.raises(AttributeError) as error: pipeline.run() assert str(error.value) == "Pipeline module 'write' is looking for data under a tag " \ "which is not created by a previous module or does not exist " \ "in the database." assert pipeline.validate_pipeline_module("test") is None assert pipeline._validate("module", "tag") == (False, None) os.remove(self.test_dir + "PynPoint_database.hdf5")