Skip to content

Commit

Permalink
Merge pull request #1025 from sphuber/fix_1023_broken_pluginloader_test
Browse files Browse the repository at this point in the history
Improve and fix issues with the plugin loader tests
  • Loading branch information
sphuber authored Dec 22, 2017
2 parents bb4b7cc + fabfc93 commit 76af975
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
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

0 comments on commit 76af975

Please sign in to comment.