<commit_before>from __future__ import print_function, division

import os

import pytest
import numpy as np

from ..helpers import find_factory
from ....tests.helpers import requires_astrodendro
from ....external.astro import fits

DATA = os.path.join(os.path.dirname(__file__), 'data')


@requires_astrodendro
@pytest.mark.parametrize('filename', ['dendro.fits', 'dendro_old.fits', 'dendro.hdf5'])
def test_is_dendro(filename):
    from ..dendro_loader import is_dendro
    assert is_dendro(os.path.join(DATA, filename))


@requires_astrodendro
@pytest.mark.parametrize('filename', ['dendro.fits', 'dendro_old.fits', 'dendro.hdf5'])
def test_find_factory(filename):
    from ..dendro_loader import load_dendro
    assert find_factory(os.path.join(DATA, filename)) is load_dendro


@requires_astrodendro
def test_identifier_heuristics(tmpdir):

    filename = tmpdir.join('test.fits').strpath

    from ..dendro_loader import is_dendro

    hdulist = fits.HDUList()
    hdulist.append(fits.PrimaryHDU())
    hdulist.append(fits.ImageHDU())
    hdulist.append(fits.ImageHDU())

    hdulist.writeto(filename)
    assert not is_dendro(filename)

    hdulist.append(fits.ImageHDU())

    hdulist.writeto(filename, clobber=True)
    assert not is_dendro(filename)

    hdulist[1].name = 'random'

    hdulist.writeto(filename, clobber=True)
    assert not is_dendro(filename)

    hdulist[1].name = ''
    hdulist[0].data = np.array([1,2,3])

    hdulist.writeto(filename, clobber=True)
    assert not is_dendro(filename)

    hdulist[0].data = None
    hdulist[1].data = np.ones((3,4))<commit_msg>Fix test when Astropy is not present<commit_after>from __future__ import print_function, division

import os

import pytest
import numpy as np

from ..helpers import find_factory
from ....tests.helpers import requires_astrodendro

DATA = os.path.join(os.path.dirname(__file__), 'data')


@requires_astrodendro
@pytest.mark.parametrize('filename', ['dendro.fits', 'dendro_old.fits', 'dendro.hdf5'])
def test_is_dendro(filename):
    from ..dendro_loader import is_dendro
    assert is_dendro(os.path.join(DATA, filename))


@requires_astrodendro
@pytest.mark.parametrize('filename', ['dendro.fits', 'dendro_old.fits', 'dendro.hdf5'])
def test_find_factory(filename):
    from ..dendro_loader import load_dendro
    assert find_factory(os.path.join(DATA, filename)) is load_dendro


@requires_astrodendro
def test_identifier_heuristics(tmpdir):

    filename = tmpdir.join('test.fits').strpath

    from ..dendro_loader import is_dendro

    from ....external.astro import fits

    hdulist = fits.HDUList()
    hdulist.append(fits.PrimaryHDU())
    hdulist.append(fits.ImageHDU())
    hdulist.append(fits.ImageHDU())

    hdulist.writeto(filename)
    assert not is_dendro(filename)

    hdulist.append(fits.ImageHDU())

    hdulist.writeto(filename, clobber=True)
    assert not is_dendro(filename)

    hdulist[1].name = 'random'

    hdulist.writeto(filename, clobber=True)
    assert not is_dendro(filename)

    hdulist[1].name = ''
    hdulist[0].data = np.array([1,2,3])

    hdulist.writeto(filename, clobber=True)
    assert not is_dendro(filename)

    hdulist[0].data = None
    hdulist[1].data = np.ones((3,4))
{'fraction_non_alphanumeric': 0.12507778469197262, 'fraction_numerical': 0.0074673304293715, 'mean_word_length': 4.524054982817869, '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': '6883746', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1172, 'n_words': 207}