def test_clean_module_idempotency(testplugin, tmpconfig): testplugin.load() test_mod = testplugin._module callables, jobs, shutdowns, urls = loader.clean_module(test_mod, tmpconfig) # sanity assertions: check test_clean_module if any of these fails assert len(callables) == 3 assert len(jobs) == 2 assert len(shutdowns) == 1 assert len(urls) == 2 # recall clean_module, we should have the same result new_callables, new_jobs, new_shutdowns, new_urls = loader.clean_module( test_mod, tmpconfig) assert new_callables == callables assert new_jobs == jobs assert new_shutdowns == shutdowns assert new_urls == urls # assert is_triggerable behavior assert loader.is_triggerable(test_mod.first_command) assert loader.is_triggerable(test_mod.second_command) assert loader.is_triggerable(test_mod.on_topic_command) assert not loader.is_triggerable(test_mod.interval5s) assert not loader.is_triggerable(test_mod.interval10s) assert not loader.is_triggerable(test_mod.shutdown) assert not loader.is_triggerable(test_mod.example_url)
def test_clean_module_commands(tmpdir, tmpconfig): root = tmpdir.mkdir('loader_mods') 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) 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
def test_clean_module_commands(tmpdir, tmpconfig): root = tmpdir.mkdir('loader_mods') 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) 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
def test_clean_module(testplugin, tmpconfig): testplugin.load() test_mod = testplugin._module callables, jobs, shutdowns, urls = loader.clean_module(test_mod, tmpconfig) assert len(callables) == 3 assert test_mod.first_command in callables assert test_mod.second_command in callables assert test_mod.on_topic_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 # assert is_triggerable behavior *after* clean_module has been called assert loader.is_triggerable(test_mod.first_command) assert loader.is_triggerable(test_mod.second_command) assert loader.is_triggerable(test_mod.on_topic_command) assert not loader.is_triggerable(test_mod.interval5s) assert not loader.is_triggerable(test_mod.interval10s) assert not loader.is_triggerable(test_mod.shutdown) assert not loader.is_triggerable(test_mod.example_url) # 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
def register(self, bot): relevant_parts = loader.clean_module(self._module, bot.config) for part in itertools.chain(*relevant_parts): # annotate all callables in relevant_parts with `plugin_name` # attribute to make per-channel config work; see #1839 setattr(part, 'plugin_name', self.name) bot.add_plugin(self, *relevant_parts)
def test_clean_module(testplugin, tmpconfig): testplugin.load() test_mod = testplugin._module callables, jobs, shutdowns, urls = loader.clean_module( test_mod, tmpconfig) assert len(callables) == 6 assert test_mod.first_command in callables assert test_mod.second_command in callables assert test_mod.on_topic_command in callables assert test_mod.example_rule_lazy in callables assert test_mod.example_find_lazy in callables assert test_mod.example_search_lazy 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) == 2 assert test_mod.example_url in urls assert test_mod.example_url_lazy in urls # assert is_triggerable behavior *after* clean_module has been called assert loader.is_triggerable(test_mod.first_command) assert loader.is_triggerable(test_mod.second_command) assert loader.is_triggerable(test_mod.on_topic_command) assert loader.is_triggerable(test_mod.example_rule_lazy) assert loader.is_triggerable(test_mod.example_find_lazy) assert loader.is_triggerable(test_mod.example_search_lazy) assert not loader.is_triggerable(test_mod.interval5s) assert not loader.is_triggerable(test_mod.interval10s) assert not loader.is_triggerable(test_mod.shutdown) assert not loader.is_triggerable(test_mod.example_url) assert not loader.is_triggerable(test_mod.example_url_lazy) # 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 # @rate doesn't create a callable and is ignored assert test_mod.ignored_rate not in callables assert test_mod.ignored_rate not in jobs assert test_mod.ignored_rate not in shutdowns assert test_mod.ignored_rate not in urls # object with a triggerable attribute are ignored by default assert loader.is_triggerable(test_mod.ignored_obj) assert test_mod.ignored_obj not in callables assert test_mod.ignored_obj not in jobs assert test_mod.ignored_obj not in shutdowns assert test_mod.ignored_obj not in urls # trickster function is ignored: it's still not a proper plugin callable assert not loader.is_triggerable(test_mod.ignored_trickster) assert test_mod.ignored_trickster not in callables assert test_mod.ignored_trickster not in jobs assert test_mod.ignored_trickster not in shutdowns assert test_mod.ignored_trickster not in urls
def setUp(self, module: ModuleType) -> None: """Sets up the test.""" self.time = MockTime() self.config = MockConfig() botfactory = sopel.tests.factories.BotFactory() self.bot = botfactory.preloaded(self.config) self.callables, self.jobs, self.shutdowns, self.urls = clean_module( module, self.bot.config)
def unregister(self, bot): relevant_parts = loader.clean_module(self._module, bot.config) bot.remove_plugin(self, *relevant_parts)