<commit_before>from tests.unit_test_base import UnitTestBase
import pyshelf.bucket_update.utils as utils
import logging
import os.path


class UtilsTest(UnitTestBase):
    def test_create_container(self):
        directory = os.path.dirname(os.path.realpath(__file__)) + "/../data/logging-dir"
        bucket_config = {
            "name": "my-test-bucket",
            "logLevel": logging.INFO,
            "bulkUpdateLogDirectory": directory
        }

        container = utils._create_container(bucket_config)
        logger = container.logger
        # There is not a whole lot else I can validate due
        # to the nature of basicConfig.  I do want to use
        # basicConfig though, so that other loggers in
        # third party tools will inherit the settings.
        self.assertEqual(bucket_config["name"], logger.name)<commit_msg>adding test for update_search_index<commit_after>from mock import Mock
from pyproctor import MonkeyPatcher
from tests.unit_test_base import UnitTestBase
import logging
import os.path
import pyshelf.bucket_update.utils as utils


class UtilsTest(UnitTestBase):
    def test_create_container(self):
        directory = os.path.dirname(os.path.realpath(__file__)) + "/../data/logging-dir"
        bucket_config = {
            "name": "my-test-bucket",
            "logLevel": logging.INFO,
            "bulkUpdateLogDirectory": directory
        }

        container = utils._create_container(bucket_config)
        logger = container.logger
        # There is not a whole lot else I can validate due
        # to the nature of basicConfig.  I do want to use
        # basicConfig though, so that other loggers in
        # third party tools will inherit the settings.
        self.assertEqual(bucket_config["name"], logger.name)

    def test_update_search_index(self):
        container = type("FakeContainer", (object,), {})()
        container.search_updater = type("FakeSearchUpdater", (object,), {})()
        container.search_updater.run = Mock()
        _create_container = Mock(return_value=container)
        MonkeyPatcher.patch(utils, "_create_container", _create_container)
        fake_config = {"fake": "blah"}
        utils.update_search_index(fake_config)
        _create_container.assert_called_with(fake_config)
        self.assertTrue(container.search_updater.run.called)
{'fraction_non_alphanumeric': 0.09079229122055675, 'fraction_numerical': 0.0, 'mean_word_length': 3.062608695652174, 'pattern_counts': {'":': 7, '<': 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': '4020588', 'n_tokens_mistral': 640, 'n_tokens_neox': 642, 'n_words': 165}