<commit_before>import pyfits

from pyfits.tests import PyfitsTestCase

from nose.tools import assert_equal, assert_true


class TestNonstandardHdus(PyfitsTestCase):
    def test_create_fitshdu(self):
        """
        A round trip test of creating a FitsHDU, adding a FITS file to it,
        writing the FitsHDU out as part of a new FITS file, and then reading
        it and recovering the original FITS file.
        """

        self._test_create_fitshdu(compression=False)

    def test_create_fitshdu_with_compression(self):
        """Same as test_create_fitshdu but with gzip compression enabled."""

        self._test_create_fitshdu(compression=True)

    def _test_create_fitshdu(self, compression=False):
        hdul_orig = pyfits.open(self.data('test0.fits'))
        hdul_orig_info = hdul_orig.info(output=False)

        fitshdu = pyfits.FitsHDU.fromhdulist(hdul_orig, compress=compression)
        # Just to be meta, let's append to the same hdulist that the fitshdu
        # encapuslates
        hdul_orig.append(fitshdu)
        hdul_orig.writeto(self.temp('tmp.fits'), clobber=True)

        hdul = pyfits.open(self.temp('tmp.fits'))
        assert_true(isinstance(hdul[-1], pyfits.FitsHDU))

        wrapped = hdul[-1].hdulist
        assert_true(isinstance(wrapped, pyfits.HDUList))

        assert_equal(hdul_orig_info, wrapped.info(output=False))
        assert_true((hdul[1].data == wrapped[1].data).all())
        assert_true((hdul[2].data == wrapped[2].data).all())
        assert_true((hdul[3].data == wrapped[3].data).all())
        assert_true((hdul[4].data == wrapped[4].data).all())<commit_msg>A slight fix to the FITS HDU tests.<commit_after>import pyfits

from pyfits.tests import PyfitsTestCase

from nose.tools import assert_equal, assert_true


class TestNonstandardHdus(PyfitsTestCase):
    def test_create_fitshdu(self):
        """
        A round trip test of creating a FitsHDU, adding a FITS file to it,
        writing the FitsHDU out as part of a new FITS file, and then reading
        it and recovering the original FITS file.
        """

        self._test_create_fitshdu(compression=False)

    def test_create_fitshdu_with_compression(self):
        """Same as test_create_fitshdu but with gzip compression enabled."""

        self._test_create_fitshdu(compression=True)

    def _test_create_fitshdu(self, compression=False):
        hdul_orig = pyfits.open(self.data('test0.fits'))

        fitshdu = pyfits.FitsHDU.fromhdulist(hdul_orig, compress=compression)
        # Just to be meta, let's append to the same hdulist that the fitshdu
        # encapuslates
        hdul_orig.append(fitshdu)
        hdul_orig.writeto(self.temp('tmp.fits'), clobber=True)
        del hdul_orig[-1]

        hdul = pyfits.open(self.temp('tmp.fits'))
        assert_true(isinstance(hdul[-1], pyfits.FitsHDU))

        wrapped = hdul[-1].hdulist
        assert_true(isinstance(wrapped, pyfits.HDUList))

        assert_equal(hdul_orig.info(output=False), wrapped.info(output=False))
        assert_true((hdul[1].data == wrapped[1].data).all())
        assert_true((hdul[2].data == wrapped[2].data).all())
        assert_true((hdul[3].data == wrapped[3].data).all())
        assert_true((hdul[4].data == wrapped[4].data).all())
{'fraction_non_alphanumeric': 0.112369871402327, 'fraction_numerical': 0.007042253521126761, 'mean_word_length': 3.3386454183266934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3851807', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1061, 'n_words': 220}