<commit_before>from tests.unit_test_base import UnitTestBase
from pyproctor import MonkeyPatcher
from mock import Mock
from pyshelf.bulk_update.runner import Runner
import os.path
from pyshelf.bulk_update.utils import run
import logging


class UtilsTest(UnitTestBase):
    def setUp(self):
        super(UtilsTest, self).setUp()
        self.run_process_mock = Mock()
        MonkeyPatcher.patch(Runner, "_run_process", self.run_process_mock)

    def execute(self, bucket=None, chunk_size=None):
        path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../data/test_config.yaml")
        args = {
            "--chunk-size": 20,
            "--bucket": bucket,
            "<config-path>": path,
            "--verbose": False
        }

        if chunk_size:
            args["--chunk-size"] = chunk_size

        run(args)

    def test_run(self):
        self.execute()
        self.assertEqual(2, self.run_process_mock.call_count)
        args_list = self.run_process_mock.call_args_list
        expected_kyle = {
            "chunkSize": 20,
            "name": "kyle-long",
            "logLevel": logging.INFO,
            "elasticSearchConnectionString": "http://localhost:9200/metadata",
            "accessKey": "<KEY>",
            "secretKey": "<KEY>"
        }

        expected_andy = {
            "chunkSize": 20,
            "name": "andy-gertjejansen",
            "logLevel": logging.INFO,
            "elasticSearchConnectionString": "http://localhost:9200/metadata",
            "accessKey": "<KEY>",
            "secretKey": "<KEY>"
        }

        # I do this instead of assuming order since it is a dict
        # when the config is decoded and we can't rely on the
        # order of a dict
        for args in args_list:
            config = args[0][0]
            if config["name"] == "andy-gertjejansen":
                self.assertEqual(expected_andy, config)
            else:
                self.assertEqual(expected_kyle, config)<commit_msg>in the event I need to reuse them.<commit_after>from tests.unit_test_base import UnitTestBase
from pyproctor import MonkeyPatcher
from mock import Mock
from pyshelf.bulk_update.runner import Runner
import os.path
from pyshelf.bulk_update.utils import run
import logging


class UtilsTest(UnitTestBase):
    EXPECTED_KYLE = {
        "chunkSize": 20,
        "name": "kyle-long",
        "logLevel": logging.INFO,
        "elasticSearchConnectionString": "http://localhost:9200/metadata",
        "accessKey": "<KEY>",
        "secretKey": "<KEY>"
    }

    EXPECTED_ANDY = {
        "chunkSize": 20,
        "name": "andy-gertjejansen",
        "logLevel": logging.INFO,
        "elasticSearchConnectionString": "http://localhost:9200/metadata",
        "accessKey": "<KEY>",
        "secretKey": "<KEY>"
    }

    def setUp(self):
        super(UtilsTest, self).setUp()
        self.run_process_mock = Mock()
        MonkeyPatcher.patch(Runner, "_run_process", self.run_process_mock)

    def execute(self, bucket=None, chunk_size=None):
        path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../data/test_config.yaml")
        args = {
            "--chunk-size": 20,
            "--bucket": bucket,
            "<config-path>": path,
            "--verbose": False
        }

        if chunk_size:
            args["--chunk-size"] = chunk_size

        run(args)

    def test_run(self):
        self.execute()
        self.assertEqual(2, self.run_process_mock.call_count)
        args_list = self.run_process_mock.call_args_list
        # I do this instead of assuming order since it is a dict
        # when the config is decoded and we can't rely on the
        # order of a dict
        for args in args_list:
            config = args[0][0]
            if config["name"] == "andy-gertjejansen":
                self.assertEqual(UtilsTest.EXPECTED_ANDY, config)
            else:
                self.assertEqual(UtilsTest.EXPECTED_KYLE, config)
{'fraction_non_alphanumeric': 0.11860992193402166, 'fraction_numerical': 0.008562075044069504, 'mean_word_length': 2.2266450040617385, 'pattern_counts': {'":': 34, '<': 13, '<?xml version=': 0, '>': 13, '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': '7457031', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1158, 'n_words': 266}