From 6d1ab8c4464ca77ee467548a0d8d8e4aa5c6a78d Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Wed, 26 Dec 2018 17:27:02 +0100 Subject: [PATCH 1/8] test: sopel.loader.get_module_description --- test/test_loader.py | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/test_loader.py diff --git a/test/test_loader.py b/test/test_loader.py new file mode 100644 index 0000000000..8fd170d3ed --- /dev/null +++ b/test/test_loader.py @@ -0,0 +1,62 @@ +# coding=utf-8 +"""Test for the ``sopel.loader`` module.""" +import imp + +from sopel import loader + + +def test_get_module_description_good_file(tmpdir): + root = tmpdir.mkdir('loader_mods') + test_file = root.join('file_module.py') + test_file.write('') + + filename = test_file.strpath + assert loader.get_module_description(filename) == ( + 'file_module', filename, imp.PY_SOURCE + ) + + +def test_get_module_description_bad_file_pyc(tmpdir): + root = tmpdir.mkdir('loader_mods') + test_file = root.join('file_module.pyc') + test_file.write('') + + filename = test_file.strpath + assert loader.get_module_description(filename) is None + + +def test_get_module_description_bad_file_no_ext(tmpdir): + root = tmpdir.mkdir('loader_mods') + test_file = root.join('file_module') + test_file.write('') + + filename = test_file.strpath + assert loader.get_module_description(filename) is None + + +def test_get_module_description_good_dir(tmpdir): + root = tmpdir.mkdir('loader_mods') + test_dir = root.mkdir('dir_package') + test_dir.join('__init__.py').write('') + + filename = test_dir.strpath + assert loader.get_module_description(filename) == ( + 'dir_package', filename, imp.PKG_DIRECTORY + ) + + +def test_get_module_description_bad_dir_empty(tmpdir): + root = tmpdir.mkdir('loader_mods') + test_dir = root.mkdir('dir_package') + + filename = test_dir.strpath + assert loader.get_module_description(filename) is None + + +def test_get_module_description_bad_dir_no_init(tmpdir): + root = tmpdir.mkdir('loader_mods') + test_dir = root.mkdir('dir_package') + test_dir.join('no_init.py').write('') + + filename = test_dir.strpath + assert loader.get_module_description(filename) is None From abe199ce979b358151865a9d5f3f0ee469ebfe5b Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Thu, 27 Dec 2018 15:33:56 +0100 Subject: [PATCH 2/8] test: sopel.loader.clean_module --- test/test_loader.py | 80 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/test/test_loader.py b/test/test_loader.py index 8fd170d3ed..ad071c3ab4 100644 --- a/test/test_loader.py +++ b/test/test_loader.py @@ -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): @@ -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 From 115b2d8fd4f834e789c75a8aafc844e0608cea6e Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Thu, 27 Dec 2018 18:07:33 +0100 Subject: [PATCH 3/8] test: sopel.loader.clean_callable Tested cases: * test function has new attributes, * these attributes all have a default value, * test the `commands` and `nickname_commands` attribute, * test the `rule` attribute, * test the `event` atribute, Missing cases are: * doc, * and example. Still better than nothing! --- test/test_loader.py | 133 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/test/test_loader.py b/test/test_loader.py index ad071c3ab4..9ef44dc2bc 100644 --- a/test/test_loader.py +++ b/test/test_loader.py @@ -138,3 +138,136 @@ def ignored(): assert test_mod.ignored not in jobs assert test_mod.ignored not in shutdowns assert test_mod.ignored not in urls + + +def test_clean_callable_default(tmpconfig): + def func(): + pass + loader.clean_callable(func, tmpconfig) + + # Default values + assert hasattr(func, 'unblockable') + assert func.unblockable is False + assert hasattr(func, 'priority') + assert func.priority == 'medium' + assert hasattr(func, 'thread') + assert func.thread is True + assert hasattr(func, 'rate') + assert func.rate == 0 + assert hasattr(func, 'channel_rate') + assert func.rate == 0 + assert hasattr(func, 'global_rate') + assert func.global_rate == 0 + assert hasattr(func, 'event') + assert func.event == ['PRIVMSG'] + + # Not added by default + assert not hasattr(func, 'rule') + assert not hasattr(func, 'commands') + assert not hasattr(func, 'intents') + + +def test_clean_callable_event(tmpconfig): + def func(): + pass + + setattr(func, 'event', ['low', 'UP', 'MiXeD']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'event') + assert func.event == ['LOW', 'UP', 'MIXED'] + + +def test_clean_callable_event_string(tmpconfig): + def func(): + pass + + setattr(func, 'event', 'some') + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'event') + assert func.event == ['SOME'] + + +def test_clean_callable_rule(tmpconfig): + def func(): + pass + setattr(func, 'rule', [r'abc']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'rule') + assert len(func.rule) == 1 + + # Test the regex is compiled properly + regex = func.rule[0] + assert regex.match('abc') + assert regex.match('abcd') + assert not regex.match('efg') + + +def test_clean_callable_rule_string(tmpconfig): + def func(): + pass + setattr(func, 'rule', r'abc') + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'rule') + assert len(func.rule) == 1 + + # Test the regex is compiled properly + regex = func.rule[0] + assert regex.match('abc') + assert regex.match('abcd') + assert not regex.match('efg') + + +def test_clean_callable_rule_nick(tmpconfig): + """Assert ``$nick`` in a rule will match ``Sopel: `` or ``Sopel, ``.""" + def func(): + pass + setattr(func, 'rule', [r'$nickhello']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'rule') + assert len(func.rule) == 1 + + # Test the regex is compiled properly + regex = func.rule[0] + assert regex.match('Sopel: hello') + assert regex.match('Sopel, hello') + assert not regex.match('Sopel not hello') + + +def test_clean_callable_rule_nickname(tmpconfig): + """Assert ``$nick`` in a rule will match ``Sopel``.""" + def func(): + pass + setattr(func, 'rule', [r'$nickname\s+hello']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'rule') + assert len(func.rule) == 1 + + # Test the regex is compiled properly + regex = func.rule[0] + assert regex.match('Sopel hello') + assert not regex.match('Sopel not hello') + + +def test_clean_callable_nickname_command(tmpconfig): + def func(): + pass + setattr(func, 'nickname_commands', ['hello!']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'nickname_commands') + assert len(func.nickname_commands) == 1 + assert func.nickname_commands == ['hello!'] + assert hasattr(func, 'rule') + assert len(func.rule) == 1 + + regex = func.rule[0] + assert regex.match('Sopel hello!') + assert regex.match('Sopel, hello!') + assert regex.match('Sopel: hello!') + assert not regex.match('Sopel not hello') From 629c1333e8572570c27d0732030df184551325a6 Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Wed, 23 Jan 2019 21:40:46 +0100 Subject: [PATCH 4/8] test: sopel.loader.load_module --- test/test_loader.py | 128 ++++++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 39 deletions(-) diff --git a/test/test_loader.py b/test/test_loader.py index 9ef44dc2bc..03b2de97bb 100644 --- a/test/test_loader.py +++ b/test/test_loader.py @@ -1,12 +1,52 @@ # coding=utf-8 """Test for the ``sopel.loader`` module.""" import imp +import os import pytest from sopel import loader, config +MOCK_MODULE_CONTENT = """# 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 + +""" + + @pytest.fixture def tmpconfig(tmpdir): conf_file = tmpdir.join('conf.ini') @@ -78,45 +118,7 @@ def test_get_module_description_bad_dir_no_init(tmpdir): 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 - -""") + mod_file.write(MOCK_MODULE_CONTENT) test_mod, _ = loader.load_module('file_mod', mod_file.strpath, imp.PY_SOURCE) callables, jobs, shutdowns, urls = loader.clean_module( @@ -271,3 +273,51 @@ def func(): assert regex.match('Sopel, hello!') assert regex.match('Sopel: hello!') assert not regex.match('Sopel not hello') + + +def test_load_module_pymod(tmpdir): + root = tmpdir.mkdir('loader_mods') + mod_file = root.join('file_mod.py') + mod_file.write(MOCK_MODULE_CONTENT) + + test_mod, timeinfo = loader.load_module( + 'file_mod', mod_file.strpath, imp.PY_SOURCE) + + assert hasattr(test_mod, 'first_command') + assert hasattr(test_mod, 'second_command') + assert hasattr(test_mod, 'interval5s') + assert hasattr(test_mod, 'interval10s') + assert hasattr(test_mod, 'example_url') + assert hasattr(test_mod, 'shutdown') + assert hasattr(test_mod, 'ignored') + + assert timeinfo == os.path.getmtime(mod_file.strpath) + + +def test_load_module_pypackage(tmpdir): + root = tmpdir.mkdir('loader_mods') + package_dir = root.mkdir('dir_mod') + mod_file = package_dir.join('__init__.py') + mod_file.write(MOCK_MODULE_CONTENT) + + test_mod, timeinfo = loader.load_module( + 'dir_mod', package_dir.strpath, imp.PKG_DIRECTORY) + + assert hasattr(test_mod, 'first_command') + assert hasattr(test_mod, 'second_command') + assert hasattr(test_mod, 'interval5s') + assert hasattr(test_mod, 'interval10s') + assert hasattr(test_mod, 'example_url') + assert hasattr(test_mod, 'shutdown') + assert hasattr(test_mod, 'ignored') + + assert timeinfo == os.path.getmtime(package_dir.strpath) + + +def test_load_module_error(tmpdir): + root = tmpdir.mkdir('loader_mods') + mod_file = root.join('file_mod.py') + mod_file.write(MOCK_MODULE_CONTENT) + + with pytest.raises(TypeError): + loader.load_module('file_mod', mod_file.strpath, None) From 3237486243d692e1f448abe45453a3a2e6bc2c92 Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Wed, 23 Jan 2019 22:05:45 +0100 Subject: [PATCH 5/8] test: sopel.loader.clean_callable function with event --- test/test_loader.py | 85 +++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 27 deletions(-) diff --git a/test/test_loader.py b/test/test_loader.py index 03b2de97bb..53ff5512c3 100644 --- a/test/test_loader.py +++ b/test/test_loader.py @@ -37,6 +37,11 @@ def example_url(bot): pass +@sopel.module.event('TOPIC') +def on_topic_command(bot): + pass + + def shutdown(): pass @@ -47,6 +52,15 @@ def ignored(): """ +@pytest.fixture +def func(): + """Pytest fixture to get a function that will return True all the time""" + def bot_command(): + """Test callable defined as a pytest fixture.""" + return True + return bot_command + + @pytest.fixture def tmpconfig(tmpdir): conf_file = tmpdir.join('conf.ini') @@ -120,7 +134,8 @@ def test_clean_module_commands(tmpdir, tmpconfig): mod_file = root.join('file_mod.py') mod_file.write(MOCK_MODULE_CONTENT) - test_mod, _ = loader.load_module('file_mod', mod_file.strpath, imp.PY_SOURCE) + test_mod, _ = loader.load_module( + 'file_mod', mod_file.strpath, imp.PY_SOURCE) callables, jobs, shutdowns, urls = loader.clean_module( test_mod, tmpconfig) @@ -142,9 +157,7 @@ def test_clean_module_commands(tmpdir, tmpconfig): assert test_mod.ignored not in urls -def test_clean_callable_default(tmpconfig): - def func(): - pass +def test_clean_callable_default(tmpconfig, func): loader.clean_callable(func, tmpconfig) # Default values @@ -169,10 +182,7 @@ def func(): assert not hasattr(func, 'intents') -def test_clean_callable_event(tmpconfig): - def func(): - pass - +def test_clean_callable_event(tmpconfig, func): setattr(func, 'event', ['low', 'UP', 'MiXeD']) loader.clean_callable(func, tmpconfig) @@ -180,10 +190,7 @@ def func(): assert func.event == ['LOW', 'UP', 'MIXED'] -def test_clean_callable_event_string(tmpconfig): - def func(): - pass - +def test_clean_callable_event_string(tmpconfig, func): setattr(func, 'event', 'some') loader.clean_callable(func, tmpconfig) @@ -191,9 +198,7 @@ def func(): assert func.event == ['SOME'] -def test_clean_callable_rule(tmpconfig): - def func(): - pass +def test_clean_callable_rule(tmpconfig, func): setattr(func, 'rule', [r'abc']) loader.clean_callable(func, tmpconfig) @@ -207,9 +212,7 @@ def func(): assert not regex.match('efg') -def test_clean_callable_rule_string(tmpconfig): - def func(): - pass +def test_clean_callable_rule_string(tmpconfig, func): setattr(func, 'rule', r'abc') loader.clean_callable(func, tmpconfig) @@ -223,10 +226,8 @@ def func(): assert not regex.match('efg') -def test_clean_callable_rule_nick(tmpconfig): +def test_clean_callable_rule_nick(tmpconfig, func): """Assert ``$nick`` in a rule will match ``Sopel: `` or ``Sopel, ``.""" - def func(): - pass setattr(func, 'rule', [r'$nickhello']) loader.clean_callable(func, tmpconfig) @@ -240,10 +241,8 @@ def func(): assert not regex.match('Sopel not hello') -def test_clean_callable_rule_nickname(tmpconfig): +def test_clean_callable_rule_nickname(tmpconfig, func): """Assert ``$nick`` in a rule will match ``Sopel``.""" - def func(): - pass setattr(func, 'rule', [r'$nickname\s+hello']) loader.clean_callable(func, tmpconfig) @@ -256,9 +255,7 @@ def func(): assert not regex.match('Sopel not hello') -def test_clean_callable_nickname_command(tmpconfig): - def func(): - pass +def test_clean_callable_nickname_command(tmpconfig, func): setattr(func, 'nickname_commands', ['hello!']) loader.clean_callable(func, tmpconfig) @@ -275,6 +272,40 @@ def func(): assert not regex.match('Sopel not hello') +def test_clean_callable_events(tmpconfig, func): + setattr(func, 'event', ['TOPIC']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'event') + assert func.event == ['TOPIC'] + + setattr(func, 'event', ['TOPIC', 'JOIN']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'event') + assert func.event == ['TOPIC', 'JOIN'] + + setattr(func, 'event', ['TOPIC', 'join', 'Nick']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'event') + assert func.event == ['TOPIC', 'JOIN', 'NICK'] + + +def test_clean_callable_events_basetring(tmpconfig, func): + setattr(func, 'event', 'topic') + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'event') + assert func.event == ['TOPIC'] + + setattr(func, 'event', 'JOIN') + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'event') + assert func.event == ['JOIN'] + + def test_load_module_pymod(tmpdir): root = tmpdir.mkdir('loader_mods') mod_file = root.join('file_mod.py') From c26a1d263af89d39cf4a64d017b74c7ae8509c11 Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Wed, 23 Jan 2019 22:32:23 +0100 Subject: [PATCH 6/8] test: sopel.loader.clean_callable function with example --- test/test_loader.py | 109 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/test/test_loader.py b/test/test_loader.py index 53ff5512c3..a49a44da16 100644 --- a/test/test_loader.py +++ b/test/test_loader.py @@ -1,11 +1,12 @@ # coding=utf-8 """Test for the ``sopel.loader`` module.""" import imp +import inspect import os import pytest -from sopel import loader, config +from sopel import loader, config, module MOCK_MODULE_CONTENT = """# coding=utf-8 @@ -306,6 +307,112 @@ def test_clean_callable_events_basetring(tmpconfig, func): assert func.event == ['JOIN'] +def test_clean_callable_example(tmpconfig, func): + module.commands('test')(func) + module.example('.test hello')(func) + + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, '_docs') + assert len(func._docs) == 1 + assert 'test' in func._docs + + docs = func._docs['test'] + assert len(docs) == 2 + assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() + assert docs[1] == '.test hello' + + +def test_clean_callable_example_multi_commands(tmpconfig, func): + module.commands('test')(func) + module.commands('unit')(func) + module.example('.test hello')(func) + + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, '_docs') + assert len(func._docs) == 2 + assert 'test' in func._docs + assert 'unit' in func._docs + + test_docs = func._docs['test'] + unit_docs = func._docs['unit'] + assert len(test_docs) == 2 + assert test_docs == unit_docs + + assert test_docs[0] == inspect.cleandoc(func.__doc__).splitlines() + assert test_docs[1] == '.test hello' + + +def test_clean_callable_example_first_only(tmpconfig, func): + module.commands('test')(func) + module.example('.test hello')(func) + module.example('.test bonjour')(func) + + loader.clean_callable(func, tmpconfig) + + assert len(func._docs) == 1 + assert 'test' in func._docs + + docs = func._docs['test'] + assert len(docs) == 2 + assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() + assert docs[1] == '.test hello' + + +def test_clean_callable_example_first_only_multi_commands(tmpconfig, func): + module.commands('test')(func) + module.commands('unit')(func) + module.example('.test hello')(func) + module.example('.test bonjour')(func) + + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, '_docs') + assert len(func._docs) == 2 + assert 'test' in func._docs + assert 'unit' in func._docs + + test_docs = func._docs['test'] + unit_docs = func._docs['unit'] + assert len(test_docs) == 2 + assert test_docs == unit_docs + + assert test_docs[0] == inspect.cleandoc(func.__doc__).splitlines() + assert test_docs[1] == '.test hello' + + +def test_clean_callable_example_default_prefix(tmpconfig, func): + module.commands('test')(func) + module.example('.test hello')(func) + + tmpconfig.core.help_prefix = '!' + loader.clean_callable(func, tmpconfig) + + assert len(func._docs) == 1 + assert 'test' in func._docs + + docs = func._docs['test'] + assert len(docs) == 2 + assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() + assert docs[1] == '!test hello' + + +def test_clean_callable_example_nickname(tmpconfig, func): + module.commands('test')(func) + module.example('$nickname: hello')(func) + + loader.clean_callable(func, tmpconfig) + + assert len(func._docs) == 1 + assert 'test' in func._docs + + docs = func._docs['test'] + assert len(docs) == 2 + assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() + assert docs[1] == 'Sopel: hello' + + def test_load_module_pymod(tmpdir): root = tmpdir.mkdir('loader_mods') mod_file = root.join('file_mod.py') From 945dbe3f4fbefabd1151d106ca856dd1d0c9381c Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Wed, 23 Jan 2019 23:22:15 +0100 Subject: [PATCH 7/8] test: sopel.loader.clean_callable function with intents --- test/test_loader.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_loader.py b/test/test_loader.py index a49a44da16..5cf39009a8 100644 --- a/test/test_loader.py +++ b/test/test_loader.py @@ -413,6 +413,22 @@ def test_clean_callable_example_nickname(tmpconfig, func): assert docs[1] == 'Sopel: hello' +def test_clean_callable_intents(tmpconfig, func): + setattr(func, 'intents', [r'abc']) + loader.clean_callable(func, tmpconfig) + + assert hasattr(func, 'intents') + assert len(func.intents) == 1 + + # Test the regex is compiled properly + regex = func.intents[0] + assert regex.match('abc') + assert regex.match('abcd') + assert regex.match('ABC') + assert regex.match('AbCdE') + assert not regex.match('efg') + + def test_load_module_pymod(tmpdir): root = tmpdir.mkdir('loader_mods') mod_file = root.join('file_mod.py') From 28951553a9b09f02b97b20d326d116cfcc698d06 Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Wed, 30 Jan 2019 11:27:59 +0100 Subject: [PATCH 8/8] test: sopel.loader set tmpconfig's nick The config's default value for "nick" could be changed, breaking any tests that rely on this value. To prevent that, the tmpconfig fixture now provides a test nick. --- test/test_loader.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test/test_loader.py b/test/test_loader.py index 5cf39009a8..864dfe025e 100644 --- a/test/test_loader.py +++ b/test/test_loader.py @@ -68,6 +68,7 @@ def tmpconfig(tmpdir): conf_file.write("\n".join([ "[core]", "owner=testnick", + "nick = TestBot", "" ])) return config.Config(conf_file.strpath) @@ -228,7 +229,7 @@ def test_clean_callable_rule_string(tmpconfig, func): def test_clean_callable_rule_nick(tmpconfig, func): - """Assert ``$nick`` in a rule will match ``Sopel: `` or ``Sopel, ``.""" + """Assert ``$nick`` in a rule will match ``TestBot: `` or ``TestBot, ``.""" setattr(func, 'rule', [r'$nickhello']) loader.clean_callable(func, tmpconfig) @@ -237,13 +238,13 @@ def test_clean_callable_rule_nick(tmpconfig, func): # Test the regex is compiled properly regex = func.rule[0] - assert regex.match('Sopel: hello') - assert regex.match('Sopel, hello') - assert not regex.match('Sopel not hello') + assert regex.match('TestBot: hello') + assert regex.match('TestBot, hello') + assert not regex.match('TestBot not hello') def test_clean_callable_rule_nickname(tmpconfig, func): - """Assert ``$nick`` in a rule will match ``Sopel``.""" + """Assert ``$nick`` in a rule will match ``TestBot``.""" setattr(func, 'rule', [r'$nickname\s+hello']) loader.clean_callable(func, tmpconfig) @@ -252,8 +253,8 @@ def test_clean_callable_rule_nickname(tmpconfig, func): # Test the regex is compiled properly regex = func.rule[0] - assert regex.match('Sopel hello') - assert not regex.match('Sopel not hello') + assert regex.match('TestBot hello') + assert not regex.match('TestBot not hello') def test_clean_callable_nickname_command(tmpconfig, func): @@ -267,10 +268,10 @@ def test_clean_callable_nickname_command(tmpconfig, func): assert len(func.rule) == 1 regex = func.rule[0] - assert regex.match('Sopel hello!') - assert regex.match('Sopel, hello!') - assert regex.match('Sopel: hello!') - assert not regex.match('Sopel not hello') + assert regex.match('TestBot hello!') + assert regex.match('TestBot, hello!') + assert regex.match('TestBot: hello!') + assert not regex.match('TestBot not hello') def test_clean_callable_events(tmpconfig, func): @@ -410,7 +411,7 @@ def test_clean_callable_example_nickname(tmpconfig, func): docs = func._docs['test'] assert len(docs) == 2 assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() - assert docs[1] == 'Sopel: hello' + assert docs[1] == 'TestBot: hello' def test_clean_callable_intents(tmpconfig, func):