def test__internal_evaluate(self): workflow_file = ProbeWorkflowFile(path=fixtures.get("test_probe.json")) workflow_file.read() workflow = workflow_file.workflow kpi_results = workflow._internal_evaluate([1.0]) self.assertEqual(1, len(kpi_results))
def setUp(self): self.plugin = {"id": "pid", "name": "Plugin"} self.factory = DummyMCOFactory(self.plugin) workflow_file = ProbeWorkflowFile(path=fixtures.get("test_probe.json")) workflow_file.read() self.workflow = workflow_file.workflow self.parameters = [1, 1, 1, 1] self.optimizer_engine = DummyOptimizerEngine( single_point_evaluator=self.workflow)
def test_notify_driver_event(self): workflow_file = ProbeWorkflowFile(path=fixtures.get("test_probe.json")) workflow_file.read() workflow = workflow_file.workflow with self.assertTraitChanges(workflow, "event", count=1): workflow.execution_layers[0].data_sources[0].notify( BaseDriverEvent() ) with self.assertTraitChanges(workflow, "event", count=1): workflow.mco_model.notify(BaseDriverEvent())
def test_non_valid_file(self): # Provide a workflow that is invalid self.operation.workflow_file = ProbeWorkflowFile( path=fixtures.get("test_null.json")) self.operation.workflow_file.read() with testfixtures.LogCapture() as capture: with self.assertRaises(RuntimeError): self.operation.run() capture.check( ("force_bdss.app.base_operation", "ERROR", "Unable to execute workflow due to verification errors:"), ("force_bdss.app.base_operation", "ERROR", "The MCO has no defined parameters"), ("force_bdss.app.base_operation", "ERROR", "The MCO has no defined KPIs"), ("force_bdss.app.base_operation", "ERROR", "The number of input slots (1 values) returned by " "'test_data_source' does " 'not match the number of user-defined names specified ' '(0 values). This is ' 'either a plugin error or a file error.'), ('force_bdss.app.base_operation', 'ERROR', "The number of output slots (1 values) returned by " "'test_data_source' does " 'not match the number of user-defined names specified ' '(0 values). This is ' 'either a plugin error or a file error.'))
def test_assign_workflow_file(self): operation = OptimizeOperation() operation.workflow_file = ProbeWorkflowFile() self.assertIsNone(operation.workflow) operation.workflow_file.path = fixtures.get("test_empty.json") operation.workflow_file.read() self.assertIsNotNone(operation.workflow)
def test_notify_events(self): workflow_file = ProbeWorkflowFile(path=fixtures.get("test_probe.json")) workflow_file.read() workflow = workflow_file.workflow with self.assertTraitChanges(workflow, "event", count=1): with self.assertTraitChanges(workflow.mco_model, "event", count=1): workflow.mco_model.notify_start_event() with self.assertTraitChanges(workflow, "event", count=1): with self.assertTraitChanges(workflow.mco_model, "event", count=1): workflow.mco_model.notify_finish_event() with self.assertTraitChanges(workflow, "event", count=1): with self.assertTraitChanges(workflow.mco_model, "event", count=1): workflow.mco_model.notify_progress_event([ DataValue(value=2), DataValue(value=3) ], [DataValue(value=4), DataValue(value=5)])
def test_run_empty_workflow(self): # Load a blank workflow self.operation.workflow_file = ProbeWorkflowFile( path=fixtures.get("test_empty.json")) self.operation.workflow_file.read() with testfixtures.LogCapture() as capture: with self.assertRaises(RuntimeError): self.operation.run() 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"))
def setUp(self): self.operation = OptimizeOperation() self.operation.workflow_file = ProbeWorkflowFile( path=fixtures.get("test_probe.json")) self.operation.workflow_file.read() self.registry = self.operation.workflow_file.reader.factory_registry
def test_from_path_classmethod(self): # Test normal behaviour workflow_file = ProbeWorkflowFile.from_path( path=fixtures.get("test_empty.json")) self.assertIsInstance(workflow_file, ProbeWorkflowFile)
def setUp(self): self.workflow_file = ProbeWorkflowFile(path="foo/bar")
class TestWorkflowFile(TestCase): def setUp(self): self.workflow_file = ProbeWorkflowFile(path="foo/bar") def test__init__(self): self.assertIsNone(self.workflow_file.workflow) self.assertIsNotNone(self.workflow_file.reader) self.assertIsNotNone(self.workflow_file.writer) self.assertEqual("foo/bar", self.workflow_file.path) def test_from_path_classmethod(self): # Test normal behaviour workflow_file = ProbeWorkflowFile.from_path( path=fixtures.get("test_empty.json")) self.assertIsInstance(workflow_file, ProbeWorkflowFile) def test_read(self): # Test normal behaviour self.workflow_file.path = fixtures.get("test_empty.json") self.workflow_file.read() self.assertIsInstance(self.workflow_file.workflow, Workflow) # Test non-existent file self.workflow_file.path = "foo/bar" with self.assertRaisesRegex(FileNotFoundError, "No such file or directory: 'foo/bar'"): self.workflow_file.read() # Test undefined reader self.workflow_file.reader = None with self.assertRaisesRegex(AttributeError, "No workflow reader specified."): self.workflow_file.read() def test_write(self): # Test normal behaviour self.workflow_file.path = fixtures.get("test_empty.json") self.workflow_file.read() self.workflow_file.write() # Test undefined writer self.workflow_file.writer = None with self.assertRaisesRegex(AttributeError, "No workflow writer specified."): self.workflow_file.write()