Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit 8ac2833

Browse files
chore: improve reliability metric (#71)
- Don't use disjoint types in test assertions - Rename `equal` to `pythonEquals` in numeric types to avoid any potential confusion with `Object.equals` - Add xfail to test_solver_manager.test_solve
1 parent 57ac260 commit 8ac2833

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

jpyinterpreter/src/main/java/ai/timefold/jpyinterpreter/types/numeric/PythonFloat.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ private static PythonLikeType registerMethods() throws NoSuchMethodException {
125125

126126
// Comparisons
127127
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
128-
PythonFloat.class.getMethod("equal", PythonLikeObject.class));
128+
PythonFloat.class.getMethod("pythonEquals", PythonLikeObject.class));
129129
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
130-
PythonFloat.class.getMethod("equal", PythonInteger.class));
130+
PythonFloat.class.getMethod("pythonEquals", PythonInteger.class));
131131
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
132-
PythonFloat.class.getMethod("equal", PythonFloat.class));
132+
PythonFloat.class.getMethod("pythonEquals", PythonFloat.class));
133133
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.NOT_EQUAL,
134134
PythonFloat.class.getMethod("notEqual", PythonLikeObject.class));
135135
BuiltinTypes.FLOAT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.NOT_EQUAL,
@@ -550,11 +550,11 @@ public PythonFloat power(PythonFloat other) {
550550
return new PythonFloat(Math.pow(value, other.value));
551551
}
552552

553-
public PythonLikeObject equal(PythonLikeObject other) {
553+
public PythonLikeObject pythonEquals(PythonLikeObject other) {
554554
if (other instanceof PythonInteger) {
555-
return equal((PythonInteger) other);
555+
return pythonEquals((PythonInteger) other);
556556
} else if (other instanceof PythonFloat) {
557-
return equal((PythonFloat) other);
557+
return pythonEquals((PythonFloat) other);
558558
} else {
559559
return NotImplemented.INSTANCE;
560560
}
@@ -610,7 +610,7 @@ public PythonLikeObject greaterThanOrEqual(PythonLikeObject other) {
610610
}
611611
}
612612

613-
public PythonBoolean equal(PythonInteger other) {
613+
public PythonBoolean pythonEquals(PythonInteger other) {
614614
return PythonBoolean.valueOf(value == other.value.doubleValue());
615615
}
616616

@@ -634,7 +634,7 @@ public PythonBoolean greaterThanOrEqual(PythonInteger other) {
634634
return PythonBoolean.valueOf(value >= other.value.doubleValue());
635635
}
636636

637-
public PythonBoolean equal(PythonFloat other) {
637+
public PythonBoolean pythonEquals(PythonFloat other) {
638638
return PythonBoolean.valueOf(value == other.value);
639639
}
640640

jpyinterpreter/src/main/java/ai/timefold/jpyinterpreter/types/numeric/PythonInteger.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ private static PythonLikeType registerMethods() throws NoSuchMethodException {
161161

162162
// Comparisons
163163
BuiltinTypes.INT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
164-
PythonInteger.class.getMethod("equal", PythonLikeObject.class));
164+
PythonInteger.class.getMethod("pythonEquals", PythonLikeObject.class));
165165
BuiltinTypes.INT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
166-
PythonInteger.class.getMethod("equal", PythonInteger.class));
166+
PythonInteger.class.getMethod("pythonEquals", PythonInteger.class));
167167
BuiltinTypes.INT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.EQUAL,
168-
PythonInteger.class.getMethod("equal", PythonFloat.class));
168+
PythonInteger.class.getMethod("pythonEquals", PythonFloat.class));
169169

170170
BuiltinTypes.INT_TYPE.addLeftBinaryMethod(PythonBinaryOperator.NOT_EQUAL,
171171
PythonInteger.class.getMethod("notEqual", PythonLikeObject.class));
@@ -648,11 +648,11 @@ public PythonInteger bitwiseXor(PythonInteger other) {
648648
return new PythonInteger(value.xor(other.value));
649649
}
650650

651-
public PythonLikeObject equal(PythonLikeObject other) {
651+
public PythonLikeObject pythonEquals(PythonLikeObject other) {
652652
if (other instanceof PythonInteger) {
653-
return equal((PythonInteger) other);
653+
return pythonEquals((PythonInteger) other);
654654
} else if (other instanceof PythonFloat) {
655-
return equal((PythonFloat) other);
655+
return pythonEquals((PythonFloat) other);
656656
} else {
657657
return NotImplemented.INSTANCE;
658658
}
@@ -708,7 +708,7 @@ public PythonLikeObject greaterThanOrEqual(PythonLikeObject other) {
708708
}
709709
}
710710

711-
public PythonBoolean equal(PythonInteger other) {
711+
public PythonBoolean pythonEquals(PythonInteger other) {
712712
return PythonBoolean.valueOf(value.compareTo(other.value) == 0);
713713
}
714714

@@ -732,7 +732,7 @@ public PythonBoolean greaterThanOrEqual(PythonInteger other) {
732732
return PythonBoolean.valueOf(value.compareTo(other.value) >= 0);
733733
}
734734

735-
public PythonBoolean equal(PythonFloat other) {
735+
public PythonBoolean pythonEquals(PythonFloat other) {
736736
return PythonBoolean.valueOf(value.doubleValue() == other.value);
737737
}
738738

jpyinterpreter/src/test/java/ai/timefold/jpyinterpreter/implementors/ExceptionImplementorTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import ai.timefold.jpyinterpreter.opcodes.descriptor.StackOpDescriptor;
2121
import ai.timefold.jpyinterpreter.types.PythonLikeType;
2222
import ai.timefold.jpyinterpreter.types.PythonNone;
23+
import ai.timefold.jpyinterpreter.types.PythonString;
2324
import ai.timefold.jpyinterpreter.types.errors.PythonAssertionError;
2425
import ai.timefold.jpyinterpreter.types.errors.PythonException;
2526
import ai.timefold.jpyinterpreter.types.errors.PythonTraceback;
@@ -111,15 +112,15 @@ public void testTryExceptFinally() {
111112

112113
assertThat(javaFunction.apply(0)).isEqualTo(1);
113114
assertThat(globalsMap.get("exception")).isEqualTo(PythonNone.INSTANCE);
114-
assertThat(globalsMap.get("finally")).isEqualTo("Finally");
115+
assertThat(globalsMap.get("finally")).isEqualTo(PythonString.valueOf("Finally"));
115116

116117
assertThat(javaFunction.apply(1)).isEqualTo(1);
117-
assertThat(globalsMap.get("exception")).isEqualTo("Assert");
118-
assertThat(globalsMap.get("finally")).isEqualTo("Finally");
118+
assertThat(globalsMap.get("exception")).isEqualTo(PythonString.valueOf("Assert"));
119+
assertThat(globalsMap.get("finally")).isEqualTo(PythonString.valueOf("Finally"));
119120

120121
assertThatCode(() -> javaFunction.apply(2)).isInstanceOf(StopIteration.class);
121122
assertThat(globalsMap.get("exception")).isEqualTo(PythonNone.INSTANCE);
122-
assertThat(globalsMap.get("finally")).isEqualTo("Finally");
123+
assertThat(globalsMap.get("finally")).isEqualTo(PythonString.valueOf("Finally"));
123124
}
124125

125126
@Test

jpyinterpreter/src/test/java/ai/timefold/jpyinterpreter/types/datetime/PythonDateTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
import java.time.Duration;
66
import java.time.LocalDate;
77

8+
import ai.timefold.jpyinterpreter.types.PythonString;
9+
810
import org.junit.jupiter.api.Test;
911

1012
public class PythonDateTest {
1113
@Test
1214
public void testIsoFormat() {
1315
PythonDate pythonDate = new PythonDate(LocalDate.of(2002, 3, 11));
14-
assertThat(pythonDate.iso_format()).isEqualTo("2002-03-11");
16+
assertThat(pythonDate.iso_format()).isEqualTo(PythonString.valueOf("2002-03-11"));
1517
}
1618

1719
@Test
1820
public void testCTime() {
1921
PythonDate pythonDate = new PythonDate(LocalDate.of(2002, 3, 11));
20-
assertThat(pythonDate.ctime()).isEqualTo("Mon Mar 11 00:00:00 2002");
22+
assertThat(pythonDate.ctime()).isEqualTo(PythonString.valueOf("Mon Mar 11 00:00:00 2002"));
2123
}
2224

2325
@Test

jpyinterpreter/src/test/java/ai/timefold/jpyinterpreter/types/datetime/PythonDateTimeTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
import java.time.Duration;
66
import java.time.LocalDateTime;
77

8+
import ai.timefold.jpyinterpreter.types.PythonString;
9+
810
import org.junit.jupiter.api.Test;
911

1012
public class PythonDateTimeTest {
1113
@Test
1214
public void testIsoFormat() {
1315
PythonDateTime pythonDateTime = new PythonDateTime(LocalDateTime.of(2002, 3, 11, 1, 30, 45));
14-
assertThat(pythonDateTime.iso_format()).isEqualTo("2002-03-11T01:30:45");
16+
assertThat(pythonDateTime.iso_format()).isEqualTo(PythonString.valueOf("2002-03-11T01:30:45"));
1517
}
1618

1719
@Test
1820
public void testCTime() {
1921
PythonDateTime pythonDateTime = new PythonDateTime(LocalDateTime.of(2002, 3, 11, 1, 30, 45));
20-
assertThat(pythonDateTime.ctime()).isEqualTo("Mon Mar 11 01:30:45 2002");
22+
assertThat(pythonDateTime.ctime()).isEqualTo(PythonString.valueOf("Mon Mar 11 01:30:45 2002"));
2123
}
2224

2325
@Test

jpyinterpreter/src/test/java/ai/timefold/jpyinterpreter/types/datetime/PythonTimeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public class PythonTimeTest {
1212
@Test
1313
public void testIsoFormat() {
1414
PythonTime pythonTime = new PythonTime(LocalTime.of(1, 30, 45));
15-
assertThat(pythonTime.isoformat(PythonString.valueOf("auto"))).isEqualTo("01:30:45");
15+
assertThat(pythonTime.isoformat(PythonString.valueOf("auto"))).isEqualTo(PythonString.valueOf("01:30:45"));
1616
}
1717
}

tests/test_solver_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Annotated, List
99

1010

11+
@pytest.mark.xfail(reason='Flaky test')
1112
def test_solve():
1213
from threading import Lock, Semaphore
1314
lock = Lock()

0 commit comments

Comments
 (0)