use of io.kestra.core.tasks.scripts.Python in project kestra by kestra-io.
the class PythonTest method docker.
@Test
void docker() throws Exception {
Map<String, String> files = new HashMap<>();
files.put("main.py", "import requests; print('::{\"outputs\": {\"extract\":\"' + str(requests.get('http://google.com').status_code) + '\"}}::')");
Python python = Python.builder().id("test-python-task").type(Python.class.getName()).inputFiles(files).runner(AbstractBash.Runner.DOCKER).dockerOptions(AbstractBash.DockerOptions.builder().image("python").build()).requirements(Collections.singletonList("requests")).build();
RunContext runContext = TestsUtils.mockRunContext(runContextFactory, python, ImmutableMap.of());
ScriptOutput run = python.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getVars().get("extract"), is("200"));
}
use of io.kestra.core.tasks.scripts.Python in project kestra by kestra-io.
the class PythonTest method run.
@Test
void run() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.py", "print('::{\"outputs\": {\"extract\":\"hello world\"}}::')");
Python python = Python.builder().id("test-python-task").pythonPath("python3").inputFiles(files).build();
ScriptOutput run = python.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getStdOutLineCount(), is(1));
assertThat(run.getVars().get("extract"), is("hello world"));
}
use of io.kestra.core.tasks.scripts.Python in project kestra by kestra-io.
the class PythonTest method failed.
@Test
void failed() {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.py", "import sys; sys.exit(1)");
Python python = Python.builder().id("test-python-task").pythonPath("python3").inputFiles(files).build();
Bash.BashException pythonException = assertThrows(Bash.BashException.class, () -> {
python.run(runContext);
});
assertThat(pythonException.getExitCode(), is(1));
assertThat(pythonException.getStdOutSize(), is(0));
}
use of io.kestra.core.tasks.scripts.Python in project kestra by kestra-io.
the class PythonTest method requirements.
@Test
void requirements() throws Exception {
RunContext runContext = runContextFactory.of();
Map<String, String> files = new HashMap<>();
files.put("main.py", "import requests; print('::{\"outputs\": {\"extract\":\"' + str(requests.get('http://google.com').status_code) + '\"}}::')");
Python python = Python.builder().id("test-python-task").pythonPath("python3").inputFiles(files).requirements(Collections.singletonList("requests")).build();
ScriptOutput run = python.run(runContext);
assertThat(run.getExitCode(), is(0));
assertThat(run.getVars().get("extract"), is("200"));
}
Aggregations