Skip to content

Commit

Permalink
Add a test for FAILED task status
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrueden committed Sep 25, 2024
1 parent e713a2d commit 34c77b1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/java/org/apposed/appose/ApposeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
Expand Down Expand Up @@ -147,6 +148,26 @@ public void testServiceStartupFailure() throws IOException, InterruptedException
}
}

@Test
public void testTaskFailurePython() throws InterruptedException, IOException {
Environment env = Appose.system();
try (Service service = env.python()) {
service.debug(System.out::println);
String script = "whee\n";
Task task = service.task(script);
task.waitFor();
assertSame(TaskStatus.FAILED, task.status);
String nl = "(\r\n|\n|\r)";
String expectedError =
"Traceback \\(most recent call last\\):" + nl +
" File \"[^ ]*python_worker.py\", line \\d+, in execute_script" + nl +
" result = eval\\(" + nl +
" File \"<string>\", line 1, in <module>" + nl +
"NameError: name 'whee' is not defined" + nl;
assertTrue(task.error.matches(expectedError));
}
}

public void executeAndAssert(Service service, String script)
throws IOException, InterruptedException
{
Expand Down

0 comments on commit 34c77b1

Please sign in to comment.