Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
tests: Fix issues with test ordering dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Jun 19, 2019
1 parent b90f4a0 commit 6bafde7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion plugins/badwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def list_bad(text):


@hook.event([EventType.message, EventType.action], singlethread=True)
def test_badwords(conn, message, chan, content, nick):
def check_badwords(conn, message, chan, content, nick):
match = matcher.regex.match(content)
if not match:
return
Expand Down
8 changes: 4 additions & 4 deletions plugins/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
multitwitch_re = re.compile(r'(.*:)//(www.multitwitch.tv|multitwitch.tv)/(.*)', re.I)


def test_name(s):
def check_name(s):
valid = set('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_/')
return set(s) <= valid

Expand Down Expand Up @@ -65,7 +65,7 @@ def multitwitch_url(match, reply):
usernames = match.group(3).split("/")
out = ""
for i in usernames:
if not test_name(i):
if not check_name(i):
return None
if out == "":
out = twitch_lookup(i, reply)
Expand All @@ -78,7 +78,7 @@ def multitwitch_url(match, reply):
def twitch_url(match, reply):
bit = match.group(4).split("#")[0]
location = "/".join(bit.split("/")[1:])
if not test_name(location):
if not check_name(location):
return None
return twitch_lookup(location, reply)

Expand All @@ -87,7 +87,7 @@ def twitch_url(match, reply):
def twitch(text, reply):
"""<channel name> - Retrieves the channel and shows it's offline/offline status"""
text = text.split("/")[-1]
if test_name(text):
if check_name(text):
location = text
else:
return "Not a valid channel name."
Expand Down
10 changes: 5 additions & 5 deletions tests/plugin_tests/test_duckhunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

from plugins.duckhunt import top_list


class MockDB:
def __init__(self):
Expand All @@ -31,17 +29,19 @@ def mock_db():
],
])
def test_top_list(prefix, items, result):
from plugins.duckhunt import top_list
assert top_list(prefix, items.items()) == result


def test_display_scores(mock_db):
from cloudbot.util.database import metadata
metadata.bind = mock_db.engine
from cloudbot.util import database
importlib.reload(database)
database.metadata.bind = mock_db.engine
from plugins import duckhunt

importlib.reload(duckhunt)

metadata.create_all(checkfirst=True)
database.metadata.create_all(checkfirst=True)

session = mock_db.session()

Expand Down
9 changes: 9 additions & 0 deletions tests/plugin_tests/test_factoids.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib
from textwrap import dedent

import pytest
Expand Down Expand Up @@ -49,6 +50,10 @@ def test_remove_fact_no_paste():


def test_remove_fact(patch_paste):
from cloudbot.util import database
importlib.reload(database)
from plugins import factoids
importlib.reload(factoids)
from plugins.factoids import factoid_cache
factoid_cache.clear()
mock_session = MagicMock()
Expand Down Expand Up @@ -82,6 +87,10 @@ def test_remove_fact(patch_paste):


def test_clear_facts():
from cloudbot.util import database
importlib.reload(database)
from plugins import factoids
importlib.reload(factoids)
mock_session = MagicMock()

from plugins.factoids import forget_all
Expand Down
2 changes: 1 addition & 1 deletion tests/plugin_tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_munge(text, leet_data):
@pytest.mark.parametrize('text', [
'foo bar baz!',
])
def test_leet(text):
def test_leet(text, leet_data):
from plugins.utility import leet
assert leet(text)

Expand Down
4 changes: 2 additions & 2 deletions tests/plugin_tests/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, config):
self.config = MockConfig(self, config)


@pytest.mark.parametrize('bearing,direction', {
@pytest.mark.parametrize('bearing,direction', [
(360, 'N'),
(0, 'N'),
(1, 'N'),
Expand All @@ -40,7 +40,7 @@ def __init__(self, config):
(180, 'S'),
(348.75, 'N'),
(348.74, 'NNW'),
})
])
def test_wind_direction(bearing, direction):
from plugins.weather import bearing_to_card
assert bearing_to_card(bearing) == direction
Expand Down

0 comments on commit 6bafde7

Please sign in to comment.