def test_submit(self, api: ApiClient, wf: Workflow) -> None: """Test `Workflow.submit` method.""" fake_workflow_name = "test" flexmock(WorkflowServiceApi).should_receive("create_workflow").and_return( fake_workflow_name ) # submit w/o parameters workflow_name: str = wf.submit(client=ApiClient(), namespace="test") assert isinstance(workflow_name, str) assert workflow_name == "test" # submit w/ parameters with pytest.raises(AttributeError) as exc: # Expected ValueError due to undefined parameter workflow_name: str = wf.submit( client=api, namespace="test", parameters={"param": "test"} ) wf.spec.arguments = V1alpha1Arguments( parameters=[V1alpha1Parameter(name="param")] ) workflow_result: str = wf.submit( client=api, namespace="test", parameters={"param": "test"} )
def test_submit(self, api: V1alpha1Api, wf: Workflow) -> None: """Test `Workflow.submit` method.""" fake_workflow_name = "test" flexmock(V1alpha1Api).should_receive("create_namespaced_workflow").and_return( fake_workflow_name ) # submit w/o parameters workflow_name: str = wf.submit(client=V1alpha1Api(), namespace="test") assert isinstance(workflow_name, str) assert workflow_name == "test" # submit w/ parameters with pytest.raises(AttributeError) as exc: # Expected ValueError due to undefined parameter workflow_name: str = wf.submit( client=api, namespace="test", parameters={"param": "test"} ) wf.spec.arguments = V1alpha1Arguments( parameters=[V1alpha1Parameter(name="param")] ) workflow_result: str = wf.submit( client=api, namespace="test", parameters={"param": "test"} ) assert isinstance(workflow_result, V1alpha1Workflow) assert isinstance(workflow_result.metadata.name, str) assert len(workflow_result.spec.arguments.parameters) == 1 assert workflow_result.spec.arguments.parameters[0].name == 'param' assert workflow_result.spec.arguments.parameters[0].value == 'test' assert workflow_result.metadata.name == "test"
def test_from_file(self) -> None: """Test `Workflow.from_file` method.""" wf = Workflow.from_file(self._WORKFLOW_FILE) assert isinstance(wf, Workflow) assert wf.name == "hello-world" assert wf.kind == "Workflow" assert len(wf.spec.templates) == 1
def test_export(mock_docker_calls, backup_packaged_project, monkeypatch, mode, args): load_tasks_mock = Mock(wraps=commons.load_tasks) monkeypatch.setattr(commons, 'load_tasks', load_tasks_mock) exporter = ArgoWorkflowsExporter(path_to_config='soopervisor.yaml', env_name='serve') exporter.add() exporter.export(mode=mode, until=None) yaml_str = Path('serve/argo.yaml').read_text() spec = yaml.safe_load(yaml_str) dag = DAGSpec.find().to_dag() load_tasks_mock.assert_called_once_with(mode=mode) # make sure the "source" key is represented in literal style # (https://yaml-multiline.info/) to make the generated script more readable assert 'source: |' in yaml_str run_task_template = spec['spec']['templates'][0] tasks = spec['spec']['templates'][1]['dag']['tasks'] assert run_task_template['script'][ 'source'] == 'ploomber task {{inputs.parameters.task_name}}' + args assert spec['spec']['volumes'] == [] assert run_task_template['script']['volumeMounts'] == [] assert Workflow.from_dict(copy(spec)) assert set(spec) == {'apiVersion', 'kind', 'metadata', 'spec'} assert set(spec['metadata']) == {'generateName'} assert set(spec['spec']) == {'entrypoint', 'templates', 'volumes'} # should not change workingdir assert run_task_template['script']['workingDir'] is None assert run_task_template['script'][ 'image'] == 'your-repository/name:0.1dev' assert run_task_template['name'] == 'run-task' assert spec['metadata']['generateName'] == 'my-project-' assert all([ set(dag[t['name']].upstream) == set(t['dependencies']) for t in tasks ]) # tasks call the right template assert set(t['template'] for t in tasks) == {'run-task'} # check each task uses the right parameters assert all([ t['arguments']['parameters'][0] == { 'name': 'task_name', 'value': t['name'] } for t in tasks ])
def test_from_url(self, url: str) -> None: """Test `Workflow.from_url` method.""" fake_response = type( "Response", (), {"text": self._WORKFLOW_FILE.read_text(), "raise_for_status": lambda: None}, ) flexmock(requests).should_receive("get").and_return(fake_response) wf = Workflow.from_url(url) assert isinstance(wf, Workflow) # assert wf.name == "test" assert wf.kind == "Workflow" assert len(wf.spec.templates) == 1
def test_generate_valid_argo_specs(name, tmp_projects): if name == 'ml-online': subprocess.run(['pip', 'uninstall', 'ml-online', '--yes'], check=True) subprocess.run(['pip', 'install', 'ml-online/'], check=True) os.chdir(name) runner = CliRunner() result = runner.invoke( cli.add, ['serve', '--backend', 'argo-workflows'], catch_exceptions=False, ) assert result.exit_code == 0 # validate argo workflow content = Path('serve', 'argo.yaml').read_text() assert Workflow.from_dict(yaml.safe_load(content))