<commit_before>import unittest

import mock
import nose.tools as ntools

from smqtk.algorithms.descriptor_generator.colordescriptor.colordescriptor import (
    ColorDescriptor_Image_csift  # arbitrary leaf class
)

__author__ = "<EMAIL>"


class TestColorDescriptor (unittest.TestCase):

    @mock.patch('smqtk.algorithms.descriptor_generator.colordescriptor.colordescriptor'
                '.file_utils.safe_create_dir')
    def test_configuration(self, mock_scd):
        default_config = ColorDescriptor_Image_csift.get_default_config()
        default_config['model_directory'] = '/some/path/models/'
        default_config['work_directory'] = '/some/path/work/'

        inst = ColorDescriptor_Image_csift.from_config(default_config)
        ntools.assert_equal(
            default_config,
            inst.get_config()
        )
        inst2 = ColorDescriptor_Image_csift.from_config(inst.get_config())
        ntools.assert_equal(inst.get_config(), inst2.get_config())
        ntools.assert_equal(inst._model_dir, inst2._model_dir)
        ntools.assert_equal(inst._work_dir, inst2._work_dir)
        ntools.assert_equal(inst._kmeans_k, inst2._kmeans_k)
        ntools.assert_equal(inst._flann_target_precision,
                            inst2._flann_target_precision)
        ntools.assert_equal(inst._flann_sample_fraction,
                            inst2._flann_sample_fraction)
        ntools.assert_equal(inst._flann_autotune, inst2._flann_autotune)
        ntools.assert_equal(inst._use_sp, inst2._use_sp)
        ntools.assert_equal(inst._rand_seed, inst2._rand_seed)
<commit_msg>Protected ColorDescriptor test behind `is_usable` test<commit_after>import unittest

import mock
import nose.tools as ntools

from smqtk.algorithms.descriptor_generator.colordescriptor.colordescriptor import (
    ColorDescriptor_Image_csift  # arbitrary leaf class
)

__author__ = "<EMAIL>"


if ColorDescriptor_Image_csift.is_usable():

    class TestColorDescriptor (unittest.TestCase):

        @mock.patch('smqtk.algorithms.descriptor_generator'
                    '.colordescriptor.colordescriptor'
                    '.file_utils.safe_create_dir')
        def test_configuration(self, mock_scd):
            default_config = ColorDescriptor_Image_csift.get_default_config()
            default_config['model_directory'] = '/some/path/models/'
            default_config['work_directory'] = '/some/path/work/'

            inst = ColorDescriptor_Image_csift.from_config(default_config)
            ntools.assert_equal(
                default_config,
                inst.get_config()
            )
            inst2 = ColorDescriptor_Image_csift.from_config(inst.get_config())
            ntools.assert_equal(inst.get_config(), inst2.get_config())
            ntools.assert_equal(inst._model_dir, inst2._model_dir)
            ntools.assert_equal(inst._work_dir, inst2._work_dir)
            ntools.assert_equal(inst._kmeans_k, inst2._kmeans_k)
            ntools.assert_equal(inst._flann_target_precision,
                                inst2._flann_target_precision)
            ntools.assert_equal(inst._flann_sample_fraction,
                                inst2._flann_sample_fraction)
            ntools.assert_equal(inst._flann_autotune, inst2._flann_autotune)
            ntools.assert_equal(inst._use_sp, inst2._use_sp)
            ntools.assert_equal(inst._rand_seed, inst2._rand_seed)

{'fraction_non_alphanumeric': 0.08448225286007627, 'fraction_numerical': 0.005866823115283074, 'mean_word_length': 2.9883040935672516, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5529457', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1011, 'n_words': 120}