Skip to content

Commit 89f0bee

Browse files
committed
Relax stack trace errors
Different versions of Python give slightly different stack traces. The tests were passing with Python 3.10, but failing with Python 3.13. This commit relaxes the checks to look for the most important telltales, rather than being rigid about the complete stack trace contents.
1 parent 3702960 commit 89f0bee

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/test/java/org/apposed/appose/ApposeTest.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,8 @@ public void testTaskFailurePython() throws InterruptedException, IOException {
161161
task.waitFor();
162162
assertSame(TaskStatus.FAILED, task.status);
163163
String nl = "(\r\n|\n|\r)";
164-
String expectedError =
165-
"Traceback \\(most recent call last\\):" + nl +
166-
" File \"[^ ]*python_worker.py\", line \\d+, in execute_script" + nl +
167-
" result = eval\\(" + nl +
168-
" File \"<string>\", line 1, in <module>" + nl +
169-
"NameError: name 'whee' is not defined" + nl;
170-
assertTrue(task.error.matches(expectedError));
164+
String expectedError = "NameError: name 'whee' is not defined";
165+
assertTrue(task.error.contains(expectedError));
171166
}
172167
}
173168

@@ -182,14 +177,12 @@ public void testStartupCrash() throws InterruptedException, IOException {
182177
Thread.sleep(5);
183178
}
184179
assertFalse(service.isAlive());
185-
assertEquals(3, service.errorLines().size());
186180
// Check that the crash happened and was recorded correctly.
187-
List<String> expectedLines = Arrays.asList(
188-
"Traceback (most recent call last):",
189-
" File \"<string>\", line 1, in <module>",
190-
"ModuleNotFoundError: No module named 'nonexistentpackage'"
191-
);
192-
assertEquals(expectedLines, service.errorLines());
181+
List<String> errorLines = service.errorLines();
182+
assertNotNull(errorLines);
183+
assertFalse(errorLines.isEmpty());
184+
String error = errorLines.get(errorLines.size() - 1);
185+
assertEquals("ModuleNotFoundError: No module named 'nonexistentpackage'", error);
193186
}
194187

195188
@Test

0 commit comments

Comments
 (0)