def test_nonexistent_file(self):

        # Provide a workflow file path that does not exists
        with testfixtures.LogCapture() as capture:
            with warnings.catch_warnings():
                warnings.simplefilter("error")
                app = BDSSApplication(False,
                                      fixtures.get("test_nonexistent.json"))
                capture.clear()
                with self.assertRaises(FileNotFoundError):
                    app._load_workflow()
            capture.check(('force_bdss.app.bdss_application', 'ERROR',
                           "Unable to open workflow file '{}'.".format(
                               fixtures.get("test_nonexistent.json"))))
 def test_toolkit_null(self):
     ETSConfig.toolkit = 'null'
     with testfixtures.LogCapture():
         with warnings.catch_warnings():
             warnings.simplefilter("ignore")
             BDSSApplication(False, "foo/bar")
     self.assertEqual(ETSConfig.toolkit, 'null')
 def test_plugins_imported(self):
     with mock.patch(
             "eggbox_potential_sampler.eggbox_plugin.EggboxPlugin.get_name",
             side_effect=lambda: "Example") as mock_example_plugin_get_name:
         # initialize the command line app
         BDSSApplication(True, self.empty_workflow_path)
         mock_example_plugin_get_name.assert_called_once()
예제 #4
0
def run(evaluate, logfile, workflow_filepath):
    logging_config = {}
    logging_config["level"] = logging.INFO

    if logfile is not None:
        logging_config["filename"] = logfile

    logging.basicConfig(**logging_config)
    log = logging.getLogger(__name__)

    try:
        application = BDSSApplication(evaluate=evaluate,
                                      workflow_file=workflow_filepath)

        application.run()
    except Exception as e:
        log.exception(e)
 def test_initialization(self):
     with testfixtures.LogCapture():
         with warnings.catch_warnings():
             warnings.simplefilter("ignore")
             app = BDSSApplication(False, "foo/bar")
     self.assertIsInstance(app.operation, OptimizeOperation)
     self.assertEqual(app.workflow_file.path, "foo/bar")
     self.assertEqual(ETSConfig.toolkit, 'null')
    def test_run_error_raise_sys_exit(self):
        # Sys exit on non-existent file
        with testfixtures.LogCapture():
            app = BDSSApplication(False, fixtures.get("test_nonexistent.json"))
            with self.assertRaises(SystemExit):
                app.run()

        # Sys exit on empty workflow file
        with testfixtures.LogCapture():
            app = BDSSApplication(False, fixtures.get("test_empty.json"))
            with self.assertRaises(SystemExit):
                app.run()
    def test_workflow(self):
        with testfixtures.LogCapture():
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                app = BDSSApplication(False, fixtures.get("test_empty.json"))
                app._load_workflow()

        self.assertIsInstance(app.workflow_file.workflow, Workflow)

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

        self.assertIsInstance(app.workflow_file.workflow, Workflow)
    def test_data_views_module_not_imported_by_bdss(self):
        # hide the example_data_views module
        sys.modules[
            "eggbox_potential_sampler.sampling_data_view.sampling_data_view"] = None

        plugin = EggboxPlugin()
        # accessing get_data_view should trigger the import (and fail)
        with self.assertRaises(ModuleNotFoundError):
            plugin.get_data_views()

        # However, BDSS shouldn't attempt the import
        try:
            BDSSApplication(True, self.empty_workflow_path)
        except ModuleNotFoundError:
            self.fail("Has BDSS attempted to import .example_data_views?")
    def test_contributed_ui_module_not_imported_by_bdss(self):
        # hide the get_contributed_uis module
        sys.modules[
            "enthought_example.example_contributed_ui.example_contributed_ui"] = None

        plugin = ExamplePlugin()
        # accessing get_contributed_uis should trigger the import (and fail)
        with self.assertRaises(ModuleNotFoundError):
            plugin.get_contributed_uis()

        # However, BDSS shouldn't attempt the import
        try:
            BDSSApplication(True, self.empty_workflow_path)
        except ModuleNotFoundError:
            self.fail("Has BDSS attempted to import .example_contributed_ui?")
예제 #10
0
    def test_run_workflow_error(self):

        with testfixtures.LogCapture() as capture:
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                app = BDSSApplication(False, fixtures.get("test_empty.json"))
                app._load_workflow()
                capture.clear()
                with self.assertRaises(Exception):
                    app._run_workflow()
            capture.check(
                ('force_bdss.app.base_operation', 'ERROR',
                 'Unable to execute workflow due to verification errors:'),
                ('force_bdss.app.base_operation', 'ERROR',
                 'Workflow has no MCO'),
                ('force_bdss.app.base_operation', 'ERROR',
                 'Workflow has no execution layers'),
                ('force_bdss.app.bdss_application', 'ERROR',
                 'Error running workflow.'))