Skip to content

Commit

Permalink
test: remove test_tools from test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Dec 9, 2019
1 parent f4db54f commit 7115801
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 63 deletions.
26 changes: 15 additions & 11 deletions test/modules/test_modules_remind.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
import pytest
import pytz

from sopel import test_tools
from sopel.modules import remind


@pytest.fixture
def sopel():
bot = test_tools.MockSopel('Sopel')
bot.config.basename = 'default'
bot.config.core.owner = 'Admin'
bot.config.core.host = 'chat.freenode.net'
return bot
TMP_CONFIG = """
[core]
owner = Admin
nick = Sopel
enable =
coretasks
remind
host = chat.freenode.net
"""


WEIRD_MESSAGE = (
Expand Down Expand Up @@ -313,10 +314,13 @@ def test_timereminder_get_duration_error(date1, date2, date3):
reminder.get_duration(test_today)


def test_get_filename(sopel):
filename = remind.get_filename(sopel)
def test_get_filename(configfactory, botfactory):
tmpconfig = configfactory('default.ini', TMP_CONFIG)
mockbot = botfactory(tmpconfig)

filename = remind.get_filename(mockbot)
assert filename == os.path.join(
sopel.config.core.homedir,
mockbot.config.core.homedir,
'default.reminders.db')


Expand Down
46 changes: 29 additions & 17 deletions test/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,59 @@
import pytest

from sopel.trigger import PreTrigger, Trigger
from sopel.test_tools import MockSopel, MockSopelWrapper
from sopel.tools import Identifier
from sopel import module
from sopel import module, tools


@pytest.fixture
def sopel():
bot = MockSopel('Sopel')
bot.config.core.owner = 'Bar'
return bot
TMP_CONFIG = """
[core]
owner = Bar
nick = Sopel
enable = coretasks
"""


FOO_MESSAGE = ':Foo!foo@example.com PRIVMSG #Sopel :Hello, world'
FOO_PRIV_MESSAGE = ':Foo!foo@example.com PRIVMSG Sopel :Hello, world'


@pytest.fixture
def bot(sopel, pretrigger):
bot = MockSopelWrapper(sopel, pretrigger)
bot.channels[Identifier('#Sopel')].privileges[Identifier('Foo')] = module.VOICE
def bot(configfactory, botfactory, triggerfactory, ircfactory):
settings = configfactory('default.cfg', TMP_CONFIG)
mockbot = botfactory.preloaded(settings)
mockserver = ircfactory(mockbot)

bot = triggerfactory.wrapper(mockbot, FOO_MESSAGE)
mockserver.channel_joined('#Sopel')
mockserver.join('Foo', '#Sopel')
mockserver.mode_set('#Sopel', '+v', ['Foo'])

return bot


@pytest.fixture
def pretrigger():
line = ':Foo!foo@example.com PRIVMSG #Sopel :Hello, world'
return PreTrigger(Identifier('Foo'), line)
return PreTrigger(tools.Identifier('Foo'), FOO_MESSAGE)


@pytest.fixture
def pretrigger_pm():
line = ':Foo!foo@example.com PRIVMSG Sopel :Hello, world'
return PreTrigger(Identifier('Foo'), line)
return PreTrigger(tools.Identifier('Foo'), FOO_PRIV_MESSAGE)


@pytest.fixture
def trigger_owner(bot):
line = ':Bar!bar@example.com PRIVMSG #Sopel :Hello, world'
return Trigger(bot.config, PreTrigger(Identifier('Bar'), line), None)
return Trigger(bot.config, PreTrigger(tools.Identifier('Bar'), line), None)


@pytest.fixture
def trigger_account(bot):
line = '@account=egg :egg!egg@eg.gs PRIVMSG #Sopel :Hello, world'
return Trigger(bot.config, PreTrigger(Identifier('egg'), line), None, 'egg')
return Trigger(
bot.config,
PreTrigger(tools.Identifier('egg'), line),
None,
'egg')


@pytest.fixture
Expand Down
57 changes: 32 additions & 25 deletions test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,50 @@
"""Regression tests"""
from __future__ import unicode_literals, absolute_import, print_function, division

import pytest
from sopel import coretasks, tools

from sopel import coretasks
from sopel.tools import Identifier
from sopel.test_tools import MockSopel, MockSopelWrapper
from sopel.trigger import PreTrigger, Trigger

TMP_CONFIG = """
[core]
owner = testnick
nick = Sopel
enable = coretasks
"""

@pytest.fixture
def sopel():
bot = MockSopel("Sopel")
return bot


def test_bot_legacy_permissions(sopel):
def test_bot_legacy_permissions(configfactory, botfactory, triggerfactory):
"""
Make sure permissions match after being updated from both RPL_NAMREPLY
and RPL_WHOREPLY, #1482
"""

nick = Identifier("Admin")
mockbot = botfactory(configfactory('default.cfg', TMP_CONFIG))
nick = tools.Identifier("Admin")

# RPL_NAMREPLY
pretrigger = PreTrigger("Foo", ":test.example.com 353 Foo = #test :Foo ~@Admin")
trigger = Trigger(sopel.config, pretrigger, None)
coretasks.handle_names(MockSopelWrapper(sopel, trigger), trigger)
mockwrapper = triggerfactory.wrapper(
mockbot, ":test.example.com 353 Foo = #test :Foo ~@Admin")
coretasks.handle_names(mockwrapper, mockwrapper._trigger)

assert '#test' in mockbot.channels
assert nick in mockbot.channels["#test"].privileges

assert '#test' in mockbot.privileges
assert nick in mockbot.privileges["#test"]

channel_privileges = mockbot.channels["#test"].privileges[nick]
privileges = mockbot.privileges["#test"][nick]

assert sopel.channels["#test"].privileges[nick] == sopel.privileges["#test"][nick]
assert channel_privileges == privileges

# RPL_WHOREPLY
pretrigger = PreTrigger(
"Foo",
":test.example.com 352 Foo #test ~Admin adminhost test.example.com Admin Hr~ :0 Admin",
)
trigger = Trigger(sopel.config, pretrigger, None)
coretasks.recv_who(MockSopelWrapper(sopel, trigger), trigger)
mockwrapper = triggerfactory.wrapper(
mockbot,
":test.example.com 352 Foo #test "
"~Admin adminhost test.example.com Admin Hr~ :0 Admin")
coretasks.recv_who(mockwrapper, mockwrapper._trigger)

assert sopel.channels["#test"].privileges[nick] == sopel.privileges["#test"][nick]
channel_privileges = mockbot.channels["#test"].privileges[nick]
privileges = mockbot.privileges["#test"][nick]

assert sopel.users.get(nick) is not None
assert channel_privileges == privileges
assert mockbot.users.get(nick) is not None
19 changes: 9 additions & 10 deletions test/tools/test_tools_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
import datetime
import time

import pytest

from sopel import test_tools
from sopel.tools import jobs


@pytest.fixture
def sopel():
bot = test_tools.MockSopel('Sopel')
bot.config.core.owner = 'Bar'
return bot
TMP_CONFIG = """
[core]
owner = Bar
nick = Sopel
enable = coretasks
"""


def test_jobscheduler_stop(sopel):
scheduler = jobs.JobScheduler(sopel)
def test_jobscheduler_stop(configfactory, botfactory):
mockbot = botfactory(configfactory('config.cfg', TMP_CONFIG))
scheduler = jobs.JobScheduler(mockbot)
assert not scheduler.stopping.is_set(), 'Stopping must not be set at init'

scheduler.stop()
Expand Down

0 comments on commit 7115801

Please sign in to comment.