Skip to content

Commit 6700e66

Browse files
committed
Handle 0 values in division in Python TCK
1 parent f520065 commit 6700e66

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

graalpython/com.oracle.graal.python.tck/src/com/oracle/graal/python/tck/PythonProvider.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public Collection<? extends Snippet> createValueConstructors(Context context) {
172172
"bool:True", BOOL, "True",
173173
"bool:False", BOOL, "False",
174174
"int", INT, "1",
175+
// "int:0", INT, "0", // disabled due to GR-45046
175176
"float", FLOAT, "1.1",
176177
"complex", COMPLEX, "1.0j",
177178
"str", STR, "class pstr(str):\n pass\npstr('hello world')",
@@ -522,8 +523,12 @@ public void accept(SnippetRun snippetRun) throws PolyglotException {
522523
Value par0 = parameters.get(0);
523524
Value par1 = parameters.get(1);
524525

525-
// If anumber/Boolean should be divided, ignore if divisor is Boolean false
526-
if (!par0.isNumber() && !par0.isBoolean() || !par1.isBoolean() || par1.asBoolean()) {
526+
// If a number should be divided by 0 or false, expect an exception
527+
if ((par0.isNumber() || par0.isBoolean()) && (par1.isBoolean() && par1.asBoolean() == false || par1.isNumber() && par1.fitsInInt() && par1.asInt() == 0)) {
528+
if (snippetRun.getException() == null || !snippetRun.getException().getMessage().contains("division by zero")) {
529+
throw new AssertionError("Division by 0 should have raised");
530+
}
531+
} else {
527532
ResultVerifier.getDefaultResultVerifier().accept(snippetRun);
528533
}
529534
}

0 commit comments

Comments
 (0)