<commit_before># Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-
"""Test desimodel.io.
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import unittest
from .. import io
#
# Try to import specter.
#
specter_available = True
try:
    import specter
except ImportError:
    specter_available = False
#
# Try to load the DESIMODEL environment variable
#
desimodel_available = True
try:
    spam = os.environ['DESIMODEL']
except KeyError:
    desimodel_available = False
#
#
class TestIO(unittest.TestCase):
    """Test desimodel.io.
    """
    @classmethod
    def setUpClass(cls):
        global specter_available, desimodel_available
        cls.specter_available = specter_available
        cls.desimodel_available = desimodel_available
        # cls.data_dir = os.path.dirname(__file__)
        # try:
        #     cls.old_desimodel = os.environ['DESIMODEL']
        # except KeyError:
        #     cls.old_desimodel = None
        # os.environ['DESIMODEL'] = cls.data_dir

    @classmethod
    def tearDownClass(cls):
        pass
        # if cls.old_desimodel is None:
        #     del os.environ['DESIMODEL']
        # else:
        #     os.environ['DESIMODEL'] = cls.old_desimodel

    @unittest.skipUnless(specter_available,"The specter package was not detected.")
    def test_throughput(self):
        """Test loading of throughput files.
        """
        for channel in ('b', 'r', 'z'):
            t = io.load_throughput(channel)

    @unittest.skipUnless(specter_available,"The specter package was not detected.")
    def test_psf(self):
        """Test loading of PSF files.
        """
        for channel in ('b', 'r', 'z'):
            t = io.load_psf(channel)

    @unittest.skipUnless(desimodel_available,"The desimodel data set was not detected.")
    def test_desiparams(self):
        """Test loading of basic DESI parameters.
        """
        p = io.load_desiparams()
        self.assertTrue(isinstance(p, dict))

    @unittest.skipUnless(desimodel_available,"The desimodel data set was not detected.")
    def test_fiberpos(self):
        """Test loading of fiber positioner data.
        """
        fiberpos = io.load_fiberpos()
        self.assertEqual(len(fiberpos), 5000)
        #- Check workaround for astropy 1.0.x bug for lower -> upper col names
        for key in ('FIBER', 'POSITIONER', 'SPECTROGRAPH', 'X', 'Y', 'Z'):
            self.assertIn(key, fiberpos.dtype.names)
            x = fiberpos[key]

    @unittest.skipUnless(desimodel_available,"The desimodel data set was not detected.")
    def test_tiles(self):
        """Test loading of tile files.
        """
        t1 = io.load_tiles(onlydesi=False)
        t2 = io.load_tiles(onlydesi=True)
        self.assertLess(len(t2), len(t1))
        self.assertEqual(len(set(t2.TILEID) - set(t1.TILEID)), 0)

#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
    unittest.main()<commit_msg>also skip specter tests if desimodel is not detected<commit_after># Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-
"""Test desimodel.io.
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import unittest
from .. import io
#
# Try to import specter.
#
specter_available = True
specter_message = "The specter package was not detected."
try:
    import specter
except ImportError:
    specter_available = False
#
# Try to load the DESIMODEL environment variable
#
desimodel_available = True
desimodel_message = "The desimodel data set was not detected."
try:
    spam = os.environ['DESIMODEL']
except KeyError:
    desimodel_available = False
    specter_available = False
    specter_message = desimodel_message
#
#
class TestIO(unittest.TestCase):
    """Test desimodel.io.
    """
    @classmethod
    def setUpClass(cls):
        global specter_available, desimodel_available
        cls.specter_available = specter_available
        cls.desimodel_available = desimodel_available
        # cls.data_dir = os.path.dirname(__file__)
        # try:
        #     cls.old_desimodel = os.environ['DESIMODEL']
        # except KeyError:
        #     cls.old_desimodel = None
        # os.environ['DESIMODEL'] = cls.data_dir

    @classmethod
    def tearDownClass(cls):
        pass
        # if cls.old_desimodel is None:
        #     del os.environ['DESIMODEL']
        # else:
        #     os.environ['DESIMODEL'] = cls.old_desimodel

    @unittest.skipUnless(specter_available, specter_message)
    def test_throughput(self):
        """Test loading of throughput files.
        """
        for channel in ('b', 'r', 'z'):
            t = io.load_throughput(channel)

    @unittest.skipUnless(specter_available, specter_message)
    def test_psf(self):
        """Test loading of PSF files.
        """
        for channel in ('b', 'r', 'z'):
            t = io.load_psf(channel)

    @unittest.skipUnless(desimodel_available, desimodel_message)
    def test_desiparams(self):
        """Test loading of basic DESI parameters.
        """
        p = io.load_desiparams()
        self.assertTrue(isinstance(p, dict))

    @unittest.skipUnless(desimodel_available, desimodel_message)
    def test_fiberpos(self):
        """Test loading of fiber positioner data.
        """
        fiberpos = io.load_fiberpos()
        self.assertEqual(len(fiberpos), 5000)
        #- Check workaround for astropy 1.0.x bug for lower -> upper col names
        for key in ('FIBER', 'POSITIONER', 'SPECTROGRAPH', 'X', 'Y', 'Z'):
            self.assertIn(key, fiberpos.dtype.names)
            x = fiberpos[key]

    @unittest.skipUnless(desimodel_available, desimodel_message)
    def test_tiles(self):
        """Test loading of tile files.
        """
        t1 = io.load_tiles(onlydesi=False)
        t2 = io.load_tiles(onlydesi=True)
        self.assertLess(len(t2), len(t1))
        self.assertEqual(len(set(t2.TILEID) - set(t1.TILEID)), 0)

#- This runs all test* functions in any TestCase class in this file
if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.11065973350666233, 'fraction_numerical': 0.004874878128046799, 'mean_word_length': 2.8040791100123608, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2618095', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1942, 'n_words': 479}