def test_text_writing_string(self):

        with pytest.raises(ValueError) as error:
            TextWritingModule(file_name=0.,
                              name_in='text_write',
                              output_dir=None,
                              data_tag='images',
                              header=None)

        assert str(error.value) == 'Output \'file_name\' needs to be a string.'
    def test_text_writing_string(self):

        with pytest.raises(ValueError) as error:
            TextWritingModule(file_name=0.,
                              name_in="text_write",
                              output_dir=None,
                              data_tag="images",
                              header=None)

        assert str(error.value) == "Output 'file_name' needs to be a string."
    def test_text_writing(self):

        text_write = TextWritingModule(file_name="image.dat",
                                       name_in="text_write",
                                       output_dir=None,
                                       data_tag="images",
                                       header=None)

        self.pipeline.add_module(text_write)
        self.pipeline.run_module("text_write")

        data = np.loadtxt(self.test_dir+"image.dat")

        assert np.allclose(data[75, 25], 6.921353838812206e-05, rtol=limit, atol=0.)
        assert np.allclose(np.mean(data), 1.9545313398209947e-06, rtol=limit, atol=0.)
        assert data.shape == (100, 100)
    def test_text_writing(self) -> None:

        text_write = TextWritingModule(name_in='text_write',
                                       data_tag='images',
                                       file_name='image.dat',
                                       output_dir=None,
                                       header=None)

        self.pipeline.add_module(text_write)
        self.pipeline.run_module('text_write')

        data = np.loadtxt(self.test_dir + 'image.dat')

        assert np.sum(data) == pytest.approx(0.0008557279524431129,
                                             rel=self.limit,
                                             abs=0.)
        assert data.shape == (11, 11)
    def test_text_writing_ndim(self):

        data_4d = np.random.normal(loc=0, scale=2e-4, size=(5, 5, 5, 5))

        with h5py.File(self.test_dir+'PynPoint_database.hdf5', 'a') as hdf_file:
            hdf_file.create_dataset('data_4d', data=data_4d)

        text_write = TextWritingModule(file_name='data.dat',
                                       name_in='write_4d',
                                       output_dir=None,
                                       data_tag='data_4d',
                                       header=None)

        self.pipeline.add_module(text_write)

        with pytest.raises(ValueError) as error:
            self.pipeline.run_module('write_4d')

        assert str(error.value) == 'Only 1D or 2D arrays can be written to a text file.'
    def test_text_writing_ndim(self):

        data_4d = np.random.normal(loc=0, scale=2e-4, size=(5, 5, 5, 5))

        h5f = h5py.File(self.test_dir+"PynPoint_database.hdf5", "a")
        h5f.create_dataset("data_4d", data=data_4d)
        h5f.close()

        text_write = TextWritingModule(file_name="data.dat",
                                       name_in="write_4d",
                                       output_dir=None,
                                       data_tag="data_4d",
                                       header=None)

        self.pipeline.add_module(text_write)

        with pytest.raises(ValueError) as error:
            self.pipeline.run_module("write_4d")

        assert str(error.value) == "Only 1D or 2D arrays can be written to a text file."
    def test_text_writing_int(self):

        data_int = np.arange(1, 101, 1)

        with h5py.File(self.test_dir+'PynPoint_database.hdf5', 'a') as hdf_file:
            hdf_file.create_dataset('data_int', data=data_int)

        text_write = TextWritingModule(file_name='data.dat',
                                       name_in='write_int',
                                       output_dir=None,
                                       data_tag='data_int',
                                       header=None)

        self.pipeline.add_module(text_write)
        self.pipeline.run_module('write_int')

        data = np.loadtxt(self.test_dir+'data.dat')

        assert np.allclose(data, data_int, rtol=limit, atol=0.)
        assert data.shape == (100, )
    def test_text_writing_int(self):

        data_int = np.arange(1, 101, 1)

        h5f = h5py.File(self.test_dir+"PynPoint_database.hdf5", "a")
        h5f.create_dataset("data_int", data=data_int)
        h5f.close()

        text_write = TextWritingModule(file_name="data.dat",
                                       name_in="write_int",
                                       output_dir=None,
                                       data_tag="data_int",
                                       header=None)

        self.pipeline.add_module(text_write)
        self.pipeline.run_module("write_int")

        data = np.loadtxt(self.test_dir+"data.dat")

        assert np.allclose(data, data_int, rtol=limit, atol=0.)
        assert data.shape == (100, )
    def test_text_writing_int(self) -> None:

        data_int = np.arange(1, 11, 1)

        with h5py.File(self.test_dir + 'PynPoint_database.hdf5',
                       'a') as hdf_file:
            hdf_file.create_dataset('data_int', data=data_int)

        text_write = TextWritingModule(name_in='write_int',
                                       data_tag='data_int',
                                       file_name='data.dat',
                                       output_dir=None,
                                       header=None)

        self.pipeline.add_module(text_write)
        self.pipeline.run_module('write_int')

        data = np.loadtxt(self.test_dir + 'data.dat')

        assert data == pytest.approx(data_int, rel=self.limit, abs=0.)
        assert data.shape == (10, )