Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and fix issues with the plugin loader tests #1025

Merged
merged 4 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions aiida/backends/tests/test_plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from aiida.backends.testbase import AiidaTestCase
from aiida.common.pluginloader import all_plugins
from aiida.orm import CalculationFactory, DataFactory, WorkflowFactory
from aiida.scheduler import SchedulerFactory
from aiida.transport import TransportFactory
from aiida.orm import Workflow
from aiida.parsers import Parser, ParserFactory
from aiida.orm.data import Data
from aiida.orm import JobCalculation
from aiida.scheduler import Scheduler
from aiida.tools.dbexporters.tcod_plugins import BaseTcodtranslator
from aiida.transport import Transport
from aiida.scheduler import Scheduler, SchedulerFactory
from aiida.transport import Transport, TransportFactory
from aiida.tools.dbexporters.tcod_plugins import BaseTcodtranslator, TcodExporterFactory
from aiida.work import WorkChain


class TestExistingPlugins(AiidaTestCase):
Expand All @@ -35,19 +35,31 @@ def test_existing_calculations(self):
calculations = all_plugins('calculations')
self.assertIsInstance(calculations, list)
for i in calculations:
self.assertTrue(
issubclass(CalculationFactory(i), JobCalculation),
'Calculation plugin class {} is not subclass of JobCalculation'.format(
CalculationFactory(i)))
cls = CalculationFactory(i)
self.assertTrue(issubclass(cls, JobCalculation),
'Calculation plugin class {} is not subclass of {}'.format(cls, JobCalculation))

def test_existing_data(self):
"""
Test listing all preinstalled data formats
Test listing all preinstalled data classes
"""
data = all_plugins('data')
self.assertIsInstance(data, list)
for i in data:
self.assertTrue(issubclass(DataFactory(i), Data))
cls = DataFactory(i)
self.assertTrue(issubclass(cls, Data),
'Data plugin class {} is not subclass of {}'.format(cls, Data))

def test_existing_parsers(self):
"""
Test listing all preinstalled parsers
"""
parsers = all_plugins('parsers')
self.assertIsInstance(parsers, list)
for i in parsers:
cls = ParserFactory(i)
self.assertTrue(issubclass(cls, Parser),
'Parser plugin class {} is not subclass of {}'.format(cls, Parser))

def test_existing_schedulers(self):
"""
Expand All @@ -56,7 +68,9 @@ def test_existing_schedulers(self):
schedulers = all_plugins('schedulers')
self.assertIsInstance(schedulers, list)
for i in schedulers:
self.assertTrue(issubclass(SchedulerFactory(i), Scheduler))
cls = SchedulerFactory(i)
self.assertTrue(issubclass(cls, Scheduler),
'Scheduler plugin class {} is not subclass of {}'.format(cls, Scheduler))

def test_existing_transports(self):
"""
Expand All @@ -65,7 +79,9 @@ def test_existing_transports(self):
transports = all_plugins('transports')
self.assertIsInstance(transports, list)
for i in transports:
self.assertTrue(issubclass(TransportFactory(i), Transport))
cls = TransportFactory(i)
self.assertTrue(issubclass(cls, Transport),
'Transport plugin class {} is not subclass of {}'.format(cls, Transport))

def test_existing_workflows(self):
"""
Expand All @@ -74,11 +90,17 @@ def test_existing_workflows(self):
workflows = all_plugins('workflows')
self.assertIsInstance(workflows, list)
for i in workflows:
self.assertTrue(issubclass(WorkflowFactory(i), Workflow))
cls = WorkflowFactory(i)
self.assertTrue(issubclass(cls, (Workflow, WorkChain)),
'Workflow plugin class {} is neither a subclass of {} nor {}'.format(cls, Workflow, WorkChain))

def test_existing_tcod_plugins(self):
"""
Test listing all preinstalled tcod exporter plugins
"""
tcod_plugins = all_plugins('transports')
tcod_plugins = all_plugins('tools.dbexporters.tcod_plugins')
self.assertIsInstance(tcod_plugins, list)
for i in tcod_plugins:
cls = TcodExporterFactory(i)
self.assertTrue(issubclass(cls, BaseTcodtranslator),
'TcodExporter plugin class {} is not subclass of {}'.format(cls, BaseTcodtranslator))
2 changes: 1 addition & 1 deletion aiida/common/pluginloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
_category_mapping = {
'calculations': 'aiida.orm.calculation.job',
'data': 'aiida.orm.data',
'parsers': 'aiida.parsers.plugins',
'parsers': 'aiida.parsers',
'schedulers': 'aiida.scheduler.plugins',
'transports': 'aiida.transport.plugins',
'workflows': 'aiida.workflows',
Expand Down
2 changes: 1 addition & 1 deletion aiida/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def ParserFactory(module):
from aiida.common.pluginloader import BaseFactory
from aiida.common.exceptions import MissingPluginError

return BaseFactory(module, Parser, 'aiida.parsers.plugins')
return BaseFactory(module, Parser, 'aiida.parsers')
9 changes: 9 additions & 0 deletions aiida/tools/dbexporters/tcod_plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
###########################################################################


def TcodExporterFactory(module):
"""
Return a suitable BaseTcodtranslator subclass.
"""
from aiida.common.pluginloader import BaseFactory

return BaseFactory(module, BaseTcodtranslator, 'aiida.tools.dbexporters.tcod_plugins')


class BaseTcodtranslator(object):
"""
Base translator from calculation-specific input and output parameters
Expand Down