<commit_before># -*- coding: utf-8 -*-

from twisted.trial import unittest
from twisted.internet import reactor
from mock import Mock, patch
from toxicbuild import master
from toxicbuild.db.connector import connector


class MasterConfigTestCase(unittest.TestCase):
    @patch.object(master, 'BuildMasterBase', Mock())
    @patch.object(master, 'connector', Mock())
    def setUp(self):
        master.BuildMaster.basedir = 'bla'
        self.master = master.BuildMaster()
        self.master.config.change_sources = [Mock()]
        self.master.umask = None
        self.master.db_loop = False

    def make_reactor(self):
        r = Mock()
        r.callWhenRunning = reactor.callWhenRunning
        return r

    @patch.object(master, 'BuildMasterBase', Mock())
    @patch.object(master, 'connector', Mock())
    def test_toxicbuilddb(self):
        # tests if toxicbuild db is setted correctly
        # on globals
        self.assertTrue(master.TOXICDB)

    @patch.object(master, 'log', Mock())
    def test_startService(self):
        reactor = self.make_reactor()

        d = self.master.startService(_reactor=reactor)
        d.addCallback(lambda _: self.master.stopService())

        @d.addCallback
        def check(_):
            self.failIf(reactor.stop.called)
            self.assertTrue(master.log.msg.called)

        return d

    def test_startService_not_ready_database(self):
        reactor = self.make_reactor()

        def db_setup():
            raise connector.DatabaseNotReadyError()
        self.master.toxicdb.setup = db_setup

        d = self.master.startService(_reactor=reactor)<commit_msg>correcting unit tests<commit_after># -*- coding: utf-8 -*-

from twisted.trial import unittest
#from twisted.internet import reactor
from mock import Mock, patch
from toxicbuild import master
from toxicbuild.db.connector import connector


class MasterConfigTestCase(unittest.TestCase):
    @patch.object(master, 'BuildMasterBase', Mock())
    @patch.object(master, 'connector', Mock())
    def setUp(self):
        master.BuildMaster.basedir = 'bla'
        self.master = master.BuildMaster()
        self.master.config.change_sources = [Mock()]
        self.master.umask = None
        self.master.db_loop = False

    def make_reactor(self):
        r = Mock()
 #       r.callWhenRunning = reactor.callWhenRunning
        return r

    def test_toxicbuilddb(self):
        # tests if toxicbuild db is setted correctly
        # on globals
        self.assertTrue(master.TOXICDB)

    @patch.object(master, 'BuildMasterBase', Mock())
    @patch.object(master, 'log', Mock())
    def test_startService(self):
        reactor = self.make_reactor()

        d = self.master.startService(_reactor=reactor)
        d.addCallback(lambda _: self.master.stopService())

        @d.addCallback
        def check(_):
            self.failIf(reactor.stop.called)
            self.assertTrue(master.log.msg.called)

        return d

    @patch.object(master, 'BuildMasterBase', Mock())
    def test_startService_not_ready_database(self):
        reactor = self.make_reactor()

        def db_setup():
            raise connector.DatabaseNotReadyError()
        self.master.toxicdb.setup = db_setup

        d = self.master.startService(_reactor=reactor)
{'fraction_non_alphanumeric': 0.10819070904645477, 'fraction_numerical': 0.0006112469437652812, 'mean_word_length': 2.8551236749116606, 'pattern_counts': {'":': 0, '<': 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': '6581145', 'n_tokens_mistral': 968, 'n_tokens_neox': 936, 'n_words': 201}