Skip to content
Snippets Groups Projects
test_bdss_application.py 1.97 KiB
Newer Older
import warnings

import testfixtures

from force_bdss.bdss_application import (
    BDSSApplication,
    _load_failure_callback,
    _import_extensions
)
Stefano Borini's avatar
Stefano Borini committed
from force_bdss.core.workflow import Workflow
from force_bdss.tests import fixtures

try:
    import mock
except ImportError:
    from unittest import mock


class TestBDSSApplication(unittest.TestCase):
    def test_initialization(self):
        with testfixtures.LogCapture():
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                app = BDSSApplication(False, "foo/bar")
        self.assertFalse(app.evaluate)
        self.assertEqual(app.workflow_filepath, "foo/bar")

    def test_extension_load_failure(self):
        plugins = []
        with testfixtures.LogCapture() as log:
            _load_failure_callback(plugins,
                                   mock.Mock(),
                                   "foo",
                                   Exception("hello"))

        log.check(
            ('force_bdss.bdss_application',
             'ERROR',
             "Unable to load plugin foo. Exception: "
             "Exception. Message: hello"),
        )
        self.assertEqual(plugins, [])

    def test_import_extension(self):
        plugins = []
        plugin = mock.Mock()
        ext = mock.Mock()
        ext.obj = plugin
        _import_extensions(plugins, ext)

        self.assertEqual(plugins[0], plugin)
Stefano Borini's avatar
Stefano Borini committed

    def test_workflow(self):
        with testfixtures.LogCapture():
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                app = BDSSApplication(False, fixtures.get("test_empty.json"))

        self.assertIsInstance(app.workflow, Workflow)
Stefano Borini's avatar
Stefano Borini committed

        with testfixtures.LogCapture():
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                app = BDSSApplication(True, fixtures.get("test_empty.json"))

        self.assertIsInstance(app.workflow, Workflow)