def test_jobs_are_polled_agained_when_poll_is_None(self, mock_popen, *args): polled = {'yes': False, 'calls': 0} def poll(): polled['calls'] += 1 if polled['yes']: mock_popen.return_value.returncode = 0 return 0 else: polled['yes'] = True return None mock_popen.return_value.poll = poll executor = LocalPipelineExecutor(run_serial=False) executor._parse_results_file = lambda *args, **kwargs: '1' executor.run_pipeline_collection(self.pipeline) # Called twice for first step and once for second. self.assertGreater(polled['calls'], 0)
def test_Popen_is_called_when_command_executes(self, mock_popen, *args): executor = LocalPipelineExecutor() command = 'hello' executor.execute_command(command, watch=False) mock_popen.assert_called_with(command) executor.execute_command(command, job_name='job', watch=True) mock_popen.assert_called_with(command, shell=True)
def test_Popen_is_not_called_with_bad_command(self, mock_popen, *args): executor = LocalPipelineExecutor() bad_commands = [ '', 0, True, ['Commands'], { 'command': 'again' }, ' ', '\n', '\t', ] for bad_command in bad_commands: self.assertRaises(ValueError, executor.execute_command, bad_command) self.assertFalse(mock_popen.called)
class TestLocalParallelRun(TestLocalSerialRun): executor = lambda *a, **kw: LocalPipelineExecutor( *a, run_serial=False, poll_interval=1, **kw)
from doepipeline.designer import BaseExperimentDesigner import pandas as pd import numpy as np class ExampleDesigner(BaseExperimentDesigner): def __init__(self, *args, **kwargs): super(ExampleDesigner, self).__init__(*args, **kwargs) self.design = None np.random.seed(123456789) def update_factors_from_response(self, response): self.design += 1 return self.design def new_design(self, factor_settings=None): data = np.random.randint(10, size=(2, len(self.factors))) self.design = pd.DataFrame(data, index=['A', 'B'], columns=self.factors.keys()) return self.design if __name__ == '__main__': generator = PipelineGenerator.from_yaml('example_pipeline.yaml') designer = generator.new_designer_from_config(ExampleDesigner) design = designer.new_design() pipeline = generator.new_pipeline_collection(design) executor = LocalPipelineExecutor() results = executor.run_pipeline_collection(pipeline) design = designer.update_factors_from_response(results)