Skip to content

Commit

Permalink
test: sopel.loader.clean_module
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Jan 10, 2019
1 parent 9eab383 commit 2f109d9
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion test/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@
"""Test for the ``sopel.loader`` module."""
import imp

from sopel import loader
import pytest

from sopel import loader, config


@pytest.fixture
def tmpconfig(tmpdir):
conf_file = tmpdir.join('conf.ini')
conf_file.write("\n".join([
"[core]",
"owner=testnick",
""
]))
return config.Config(conf_file.strpath)


def test_get_module_description_good_file(tmpdir):
Expand Down Expand Up @@ -60,3 +73,68 @@ def test_get_module_description_bad_dir_no_init(tmpdir):

filename = test_dir.strpath
assert loader.get_module_description(filename) is None


def test_clean_module_commands(tmpdir, tmpconfig):
root = tmpdir.mkdir('loader_mods')
mod_file = root.join('file_mod.py')
mod_file.write("""
# coding=utf-8
import sopel.module
@sopel.module.commands("first")
def first_command(bot, trigger):
pass
@sopel.module.commands("second")
def second_command(bot, trigger):
pass
@sopel.module.interval(5)
def interval5s(bot):
pass
@sopel.module.interval(10)
def interval10s(bot):
pass
@sopel.module.url(r'.\\.example\\.com')
def example_url(bot):
pass
def shutdown():
pass
def ignored():
pass
""")

test_mod, _ = loader.load_module('file_mod', mod_file.strpath, imp.PY_SOURCE)
callables, jobs, shutdowns, urls = loader.clean_module(
test_mod, tmpconfig)

assert len(callables) == 2
assert test_mod.first_command in callables
assert test_mod.second_command in callables
assert len(jobs) == 2
assert test_mod.interval5s in jobs
assert test_mod.interval10s in jobs
assert len(shutdowns)
assert test_mod.shutdown in shutdowns
assert len(urls) == 1
assert test_mod.example_url in urls

# ignored function is ignored
assert test_mod.ignored not in callables
assert test_mod.ignored not in jobs
assert test_mod.ignored not in shutdowns
assert test_mod.ignored not in urls

0 comments on commit 2f109d9

Please sign in to comment.