Skip to content

Commit

Permalink
test: remove MockConfig from test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Dec 9, 2019
1 parent e1eae44 commit be852ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
16 changes: 11 additions & 5 deletions test/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import pytest

from sopel.db import SopelDB
from sopel.test_tools import MockConfig
from sopel.tools import Identifier

db_filename = tempfile.mkstemp()[1]
Expand All @@ -31,11 +30,18 @@
iterkeys = dict.iterkeys


TMP_CONFIG = """
[core]
owner = Embolalia
db_filename = {db_filename}
"""


@pytest.fixture
def db():
config = MockConfig()
config.core.db_filename = db_filename
db = SopelDB(config)
def db(configfactory):
content = TMP_CONFIG.format(db_filename=db_filename)
settings = configfactory('default.cfg', content)
db = SopelDB(settings)
# TODO add tests to ensure db creation works properly, too.
return db

Expand Down
54 changes: 30 additions & 24 deletions test/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@
import pytest
import datetime

from sopel.test_tools import MockConfig
from sopel.trigger import PreTrigger, Trigger
from sopel.tools import Identifier


TMP_CONFIG = """
[core]
owner = Foo
admins =
Bar
"""


TMP_CONFIG_ACCOUNT = """
[core]
owner = Foo
owner_account = bar
admins =
Bar
"""


@pytest.fixture
def nick():
return Identifier('Sopel')
Expand Down Expand Up @@ -154,12 +170,11 @@ def test_ircv3_extended_join_pretrigger(nick):
assert pretrigger.sender == Identifier('#Sopel')


def test_ircv3_extended_join_trigger(nick):
def test_ircv3_extended_join_trigger(nick, configfactory):
line = ':Foo!foo@example.com JOIN #Sopel bar :Real Name'
pretrigger = PreTrigger(nick, line)

config = MockConfig()
config.core.owner_account = 'bar'
config = configfactory('default.cfg', TMP_CONFIG)

fakematch = re.match('.*', line)

Expand All @@ -182,22 +197,19 @@ def test_ircv3_extended_join_trigger(nick):
assert trigger.admin is True


def test_ircv3_intents_trigger(nick):
line = '@intent=ACTION :Foo!foo@example.com PRIVMSG #Sopel :Hello, world'
def test_ircv3_intents_trigger(nick, configfactory):
line = '@intent=ACTION :Foo!bar@example.com PRIVMSG #Sopel :Hello, world'
pretrigger = PreTrigger(nick, line)

config = MockConfig()
config.core.owner = 'Foo'
config.core.admins = ['Bar']

config = configfactory('default.cfg', TMP_CONFIG)
fakematch = re.match('.*', line)

trigger = Trigger(config, pretrigger, fakematch)
assert trigger.sender == '#Sopel'
assert trigger.raw == line
assert trigger.is_privmsg is False
assert trigger.hostmask == 'Foo!foo@example.com'
assert trigger.user == 'foo'
assert trigger.hostmask == 'Foo!bar@example.com'
assert trigger.user == 'bar'
assert trigger.nick == Identifier('Foo')
assert trigger.host == 'example.com'
assert trigger.event == 'PRIVMSG'
Expand All @@ -207,33 +219,27 @@ def test_ircv3_intents_trigger(nick):
assert trigger.groupdict == fakematch.groupdict
assert trigger.args == ['#Sopel', 'Hello, world']
assert trigger.tags == {'intent': 'ACTION'}
assert trigger.account is None
assert trigger.admin is True
assert trigger.owner is True


def test_ircv3_account_tag_trigger(nick):
line = '@account=Foo :Nick_Is_Not_Foo!foo@example.com PRIVMSG #Sopel :Hello, world'
def test_ircv3_account_tag_trigger(nick, configfactory):
line = '@account=bar :Nick_Is_Not_Foo!foo@example.com PRIVMSG #Sopel :Hello, world'
pretrigger = PreTrigger(nick, line)

config = MockConfig()
config.core.owner_account = 'Foo'
config.core.admins = ['Bar']

config = configfactory('default.cfg', TMP_CONFIG_ACCOUNT)
fakematch = re.match('.*', line)

trigger = Trigger(config, pretrigger, fakematch)
assert trigger.admin is True
assert trigger.owner is True


def test_ircv3_server_time_trigger(nick):
def test_ircv3_server_time_trigger(nick, configfactory):
line = '@time=2016-01-09T03:15:42.000Z :Foo!foo@example.com PRIVMSG #Sopel :Hello, world'
pretrigger = PreTrigger(nick, line)

config = MockConfig()
config.core.owner = 'Foo'
config.core.admins = ['Bar']

config = configfactory('default.cfg', TMP_CONFIG)
fakematch = re.match('.*', line)

trigger = Trigger(config, pretrigger, fakematch)
Expand Down

0 comments on commit be852ee

Please sign in to comment.