<commit_before>import os
import logging
import time
from threading import Semaphore, Thread, Event
from unittest.mock import patch, Mock

import git

from app.core.logger import configure_logging
from app.core.messaging import Receiver, Sender
from app.core.services import ServiceManager
from app.core.rpc import RPCClient
from app.services.updater.service import UpdaterService, UpdateScanner
from app.services.updater.service import Updater


configure_logging()


def make_receiver(count, obj, sem, r):
    def on_message(msg):
        obj["msg"] = msg
        sem.release()
        nonlocal count
        count -= 1
        if not count:
            r.stop()
    return on_message


class TestUpdateScanner(object):
    def setup_method(self):
        self.update_check_freq_backup = UpdateScanner.UPDATE_CHECK_FREQ
        UpdateScanner.UPDATE_CHECK_FREQ = 5

        os.environ["USE_FAKE_REDIS"] = "TRUE"
        self.service_manager = ServiceManager(None)
        self.service_manager.start_services(["messaging"])

    def teardown_method(self):
        del os.environ["USE_FAKE_REDIS"]
        self.service_manager.stop()

    def test_simple_update(self):
        mock_repo = Mock()
        mock_repo.needs_pull = Mock(return_value=False)
        UpdateScanner.list_repos = lambda x, y: ["dir"]
        UpdateScanner.get_repo = lambda x, y: mock_repo

        started = Event()
        service = UpdaterService(None)
        service.notify_start = started.set
        Thread(target=service.on_service_start).start()

        started.wait()

        assert service.get_status() == "No updates available."<commit_msg>Fix unit test case.<commit_after>import os
import logging
import time
from threading import Semaphore, Thread, Event
from unittest.mock import patch, Mock

import git

from app.core.logger import configure_logging
from app.core.messaging import Receiver, Sender
from app.core.services import ServiceManager
from app.core.rpc import RPCClient
from app.services.updater.service import UpdaterService, UpdateScanner
from app.services.updater.service import Updater


configure_logging()


def make_receiver(count, obj, sem, r):
    def on_message(msg):
        obj["msg"] = msg
        sem.release()
        nonlocal count
        count -= 1
        if not count:
            r.stop()
    return on_message


class TestUpdateScanner(object):
    def setup_method(self):
        self.update_check_freq_backup = UpdateScanner.UPDATE_CHECK_FREQ
        UpdateScanner.UPDATE_CHECK_FREQ = 5

        os.environ["USE_FAKE_REDIS"] = "TRUE"
        self.service_manager = ServiceManager(None)
        self.service_manager.start_services(["messaging"])

    def teardown_method(self):
        del os.environ["USE_FAKE_REDIS"]
        self.service_manager.stop()

    def test_simple_update(self):
        mock_repo = Mock()
        mock_repo.needs_pull = Mock(return_value=False)
        UpdateScanner.list_repos = lambda x, y: ["dir"]
        UpdateScanner.get_repo = lambda x, y: mock_repo

        started = Event()
        service = UpdaterService(None)
        service.notify_start = started.set
        Thread(target=service.on_service_start).start()

        started.wait()

        while service.get_status() != "No updates available.":
            time.sleep(1)

{'fraction_non_alphanumeric': 0.08736681887366819, 'fraction_numerical': 0.0015220700152207, 'mean_word_length': 3.148989898989899, 'pattern_counts': {'":': 1, '<': 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': '1869701', 'n_tokens_mistral': 980, 'n_tokens_neox': 963, 'n_words': 229}