<commit_before># -*- coding: utf-8 -*-
from unittest import TestCase
from unittest.mock import MagicMock
from unittest.mock import patch
from unittest.mock import call
import irc3


def call_later(i, func, *args):
    if func.__name__ in dir(IrcBot):
        return func(*args)


def call_soon(func, *args):
    return func(*args)


class IrcBot(irc3.IrcBot):

    def __init__(self, **config):
        config.update(testing=True, async=False, level=1000)
        super(IrcBot, self).__init__(**config)
        self.protocol = irc3.IrcConnection()
        self.protocol.factory = self
        self.protocol.transport = MagicMock()
        self.protocol.write = MagicMock()
        self.loop = MagicMock()
        self.loop.call_later = call_later
        self.loop.call_soon = call_soon

    def test(self, data, show=True):
        self.dispatch(data)
        if show:
            for line in self.sent:
                print(line)

    @property
    def sent(self):
        values = [tuple(c)[0][0] for c in self.protocol.write.call_args_list]
        self.protocol.write.reset_mock()
        return values


class BotTestCase(TestCase):

    config = {'nick': 'nono'}

    def callFTU(self, **config):
        config = dict(self.config, **config)
        bot = IrcBot(**config)
        self.bot = bot
        return bot
<commit_msg>fix travis<commit_after># -*- coding: utf-8 -*-
from unittest import TestCase
from unittest.mock import MagicMock
from unittest.mock import patch
from unittest.mock import call
import irc3
import os

passwd_ini = """
[irc.freenode.net]
irc3=password

[twitter]
key=key
secret=secret
token=token
token_secret=token_secret
"""


def call_later(i, func, *args):
    if func.__name__ in dir(IrcBot):
        return func(*args)


def call_soon(func, *args):
    return func(*args)


class IrcBot(irc3.IrcBot):

    def __init__(self, **config):
        self.check_required()
        config.update(testing=True, async=False, level=1000)
        super(IrcBot, self).__init__(**config)
        self.protocol = irc3.IrcConnection()
        self.protocol.factory = self
        self.protocol.transport = MagicMock()
        self.protocol.write = MagicMock()
        self.loop = MagicMock()
        self.loop.call_later = call_later
        self.loop.call_soon = call_soon

    def check_required(self):
        dirname = os.path.expanduser('~/.irc3')
        if not os.path.isdir(dirname):
            os.makedirs(dirname)
        filename = os.path.expanduser('~/.irc3/passwd.ini')
        if not os.path.isfile(filename):
            with open(filename, 'w') as fd:
                fd.write(passwd_ini)

    def test(self, data, show=True):
        self.dispatch(data)
        if show:
            for line in self.sent:
                print(line)

    @property
    def sent(self):
        values = [tuple(c)[0][0] for c in self.protocol.write.call_args_list]
        self.protocol.write.reset_mock()
        return values


class BotTestCase(TestCase):

    config = {'nick': 'nono'}

    def callFTU(self, **config):
        config = dict(self.config, **config)
        bot = IrcBot(**config)
        self.bot = bot
        return bot

{'fraction_non_alphanumeric': 0.12002526847757422, 'fraction_numerical': 0.007264687302590019, 'mean_word_length': 2.5464725643896977, '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': '5647568', 'n_tokens_mistral': 1035, 'n_tokens_neox': 985, 'n_words': 233}