Exemplo n.º 1
0
    def __init__(self):
        self.tk = Tk()
        self.tk.configure(background='black')
        self.topFrame = Frame(self.tk, background='black')
        self.bottomFrame = Frame(self.tk, background='black')
        self.topFrame.pack(side=TOP, fill=BOTH, expand=YES)
        self.bottomFrame.pack(side=BOTTOM, fill=BOTH, expand=YES)
        self.centerFrame = Frame(self.tk, background='black')
        self.centerFrame.pack(fill="none", expand=True)
        self.state = False
        self.tk.bind("<Return>", self.toggle_fullscreen)
        self.tk.bind("<Escape>", self.end_fullscreen)
        # clock
        self.clock = Clock(self.topFrame)
        self.clock.pack(side=RIGHT, anchor=N, padx=100, pady=60)
        # weather
        self.weather = Weather(self.topFrame)
        self.weather.pack(side=LEFT, anchor=N, padx=100, pady=60)

        # commands text
        self.commands_sec = Commands(self.bottomFrame)
        self.commands_sec.pack(fill="none", expand=True, anchor="center")
        self.commands_sec.command_actions('weather')
        # news
        # self.news = News(self.bottomFrame)
        # self.news.pack(side=LEFT, anchor=S, padx=100, pady=60)
        # calender - removing for now
        # self.calender = Calendar(self.bottomFrame)
        # self.calender.pack(side = RIGHT, anchor=S, padx=100, pady=60)

        # Greetings

        self.greetings = Greetings(self.centerFrame)
        self.greetings.pack(fill="none", expand=True)
Exemplo n.º 2
0
def test_karma(bot):
    """Tests karma command.

    Args:
        bot: Fake instance of an Irc3Bot.
    """
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {}
    expected = 'python (5), java (-10)'
    plugin = Commands(bot)
    asyncio.get_event_loop().run_until_complete(
        plugin.karma(mask, channel, args))
    assert bot.privmsg.called_once_with(channel, expected)
Exemplo n.º 3
0
def test_slackers(bot):
    """Tests slackers command.

    Args:
        bot: Fake instance of an Irc3Bot.
    """
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {}
    expected = 'somebody_else (100), somebody (10)'
    plugin = Commands(bot)
    asyncio.get_event_loop().run_until_complete(
        plugin.slackers(mask, channel, args))
    assert bot.privmsg.called_once_with(channel, expected)
Exemplo n.º 4
0
class FullscreenWindow:
    def __init__(self):
        self.tk = Tk()
        self.tk.configure(background='black')
        self.topFrame = Frame(self.tk, background='black')
        self.bottomFrame = Frame(self.tk, background='black')
        self.topFrame.pack(side=TOP, fill=BOTH, expand=YES)
        self.bottomFrame.pack(side=BOTTOM, fill=BOTH, expand=YES)
        self.centerFrame = Frame(self.tk, background='black')
        self.centerFrame.pack(fill="none", expand=True)
        self.state = False
        self.tk.bind("<Return>", self.toggle_fullscreen)
        self.tk.bind("<Escape>", self.end_fullscreen)
        # clock
        self.clock = Clock(self.topFrame)
        self.clock.pack(side=RIGHT, anchor=N, padx=100, pady=60)
        # weather
        self.weather = Weather(self.topFrame)
        self.weather.pack(side=LEFT, anchor=N, padx=100, pady=60)

        # commands text
        self.commands_sec = Commands(self.bottomFrame)
        self.commands_sec.pack(fill="none", expand=True, anchor="center")
        self.commands_sec.command_actions('weather')
        # news
        # self.news = News(self.bottomFrame)
        # self.news.pack(side=LEFT, anchor=S, padx=100, pady=60)
        # calender - removing for now
        # self.calender = Calendar(self.bottomFrame)
        # self.calender.pack(side = RIGHT, anchor=S, padx=100, pady=60)

        # Greetings

        self.greetings = Greetings(self.centerFrame)
        self.greetings.pack(fill="none", expand=True)
        # self.greetings.place(relx=.5, rely=.5, anchor="center")

    def toggle_fullscreen(self, event=None):
        self.state = not self.state  # Just toggling the boolean
        self.tk.attributes("-fullscreen", self.state)
        return "break"

    def end_fullscreen(self, event=None):
        self.state = False
        self.tk.attributes("-fullscreen", False)
        return "break"
Exemplo n.º 5
0
def test_commands_initialization(bot):
    """Tests the initialization of Commands plugin.

    Args:
        bot: Fake instance of an Irc3Bot.
    """
    plugin = Commands(bot)
    assert isinstance(plugin, Commands)
    assert plugin.bot == bot
Exemplo n.º 6
0
def test_about(bot):
    """Tests about command.

    Args:
        bot: Fake instance of an Irc3Bot.
    """
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {}
    expected = (
        f'Hi there, my name is {bot.nick} and I am an IRC bot '
        'written in Python. If you wanna know more about me take '
        'a look at my Github page https://github.com/meleca/mr-roboto/. '
        f'Currently running v{bot.version}')
    plugin = Commands(bot)
    asyncio.get_event_loop().run_until_complete(
        plugin.about(mask, channel, args))
    assert bot.privmsg.called_once_with(channel, expected)
Exemplo n.º 7
0
def test_urls(mock_or_, date, keyword, expected, bot):
    """Tests the urls command.

    Args:
        mock_or_: Fakes sqlalchemy.sql.or_ function.
        date: An ISO date or special keyword.
        keyword: A list of keywords to be used for filtering.
        expected: Expected response.
        bot: Fake instance of an Irc3Bot.
    """
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {'<date>': date, '<keyword>': keyword}
    expected = 'Invalid date' if date == '2018-02-31' else expected
    plugin = Commands(bot)
    asyncio.get_event_loop().run_until_complete(
        plugin.urls(mask, channel, args))
    assert bot.privmsg.called_once_with(channel, expected)
Exemplo n.º 8
0
def test_cebolate(bot):
    """Tests the cebolate command.

    Args:
        bot: Fake instance of an Irc3Bot.
    """
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {'<message>': ['CORRECT', 'answer']}
    plugin = Commands(bot)

    async def test():
        response = await plugin.cebolate(mask, channel, args)
        assert response == 'COLLECT answel'

    asyncio.get_event_loop().run_until_complete(test())
Exemplo n.º 9
0
def test_greeting_raising_exception(bot):
    """Tests the greeting command when error occur.

    Args:
        bot: Fake instance of an Irc3Bot.
    """
    bot.dataset['greetings'].upsert.side_effect = ValueError()
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {'<nick>': 'nickname', '<message>': 'Hello there.'}
    plugin = Commands(bot)

    async def test():
        response = await plugin.greeting(mask, channel, args)
        assert response == 'Sorry, looks like something went wrong :('

    asyncio.get_event_loop().run_until_complete(test())
Exemplo n.º 10
0
def test_excuse(mock_session_get, bot):
    """Tests the excuse command.

    Args:
        mock_session_get: Fakes aiohttp.ClientSession.get method.
        bot: Fake instance of an Irc3Bot.
    """
    data = 'The user must not know how to use it'
    request = asynctest.Mock(text=asynctest.CoroutineMock(side_effect=[data]))
    mock_session_get.return_value.__aenter__.return_value = request
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    plugin = Commands(bot)

    async def test():
        response = await plugin.excuse(mask, channel, None)
        assert response == data

    asyncio.get_event_loop().run_until_complete(test())
Exemplo n.º 11
0
def test_horoscope(mock_session_get, sign, expected, bot):
    """Tests the horoscope command.

    Args:
        mock_session_get: Fakes aiohttp.ClientSession.get method.
        sign: A zodiac sign.
        expected: The expected response.
        bot: Fake instance of an Irc3Bot.
    """
    data = {'horoscope': expected}
    request = asynctest.Mock(json=asynctest.CoroutineMock(side_effect=[data]))
    mock_session_get.return_value.__aenter__.return_value = request
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {'<sign>': sign}
    plugin = Commands(bot)

    async def test():
        response = await plugin.horoscope(mask, channel, args)
        assert response == expected

    asyncio.get_event_loop().run_until_complete(test())
Exemplo n.º 12
0
def test_joke(mock_session_get, subject, joke, expected, bot):
    """Tests the joke command.

    Args:
        mock_session_get: Fakes aiohttp.ClientSession.get method.
        subject: A joke subject.
        joke: Fake joke service response.
        expected: The expected response.
        bot: Fake instance of an Irc3Bot.
    """
    request = asynctest.Mock(json=asynctest.CoroutineMock(side_effect=[joke]))
    mock_session_get.return_value.__aenter__.return_value = request
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {'<subject>': subject}
    plugin = Commands(bot)

    async def test():
        response = await plugin.joke(mask, channel, args)
        assert response == expected

    asyncio.get_event_loop().run_until_complete(test())
Exemplo n.º 13
0
def test_greeting(bot):
    """Tests the greeting command.

    Args:
        bot: Fake instance of an Irc3Bot.
    """
    mask = IrcString('[email protected]')
    channel = IrcString('#meleca')
    args = {'<nick>': 'nickname', '<message>': 'Hello there.'}
    data = {
        'channel': channel.replace('#', ''),
        'nick': args.get('<nick>'),
        'options': '\n'.join(['Hey there!', 'Hello there.'])
    }
    rule = ['channel', 'nick']
    plugin = Commands(bot)

    async def test():
        response = await plugin.greeting(mask, channel, args)
        assert bot.dataset['greetings'].upsert.called_once_with(data, rule)
        assert response == 'Okie dokie'

    asyncio.get_event_loop().run_until_complete(test())