Skip to content

Commit 32d78d2

Browse files
entlichertimfel
authored andcommitted
Add test to verify key info flags
1 parent ba7763a commit 32d78d2

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/debug/PythonDebugTest.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import static org.junit.Assert.assertEquals;
4444
import static org.junit.Assert.assertNotNull;
45+
import static org.junit.Assert.assertTrue;
4546

4647
import java.util.Arrays;
4748
import java.util.HashMap;
@@ -326,6 +327,75 @@ public void testReenterArgumentsAndValues() throws Throwable {
326327
}
327328
}
328329

330+
@Test
331+
public void testGettersSetters() throws Throwable {
332+
final Source source = Source.newBuilder("python", "" +
333+
"class P:\n" +
334+
" def __init__(self):\n" +
335+
" self.__x = None\n" +
336+
" self.__y = None\n" +
337+
" self.__nx = 0\n" +
338+
" self.__ny = 0\n" +
339+
"\n" +
340+
" @property\n" +
341+
" def x(self):\n" +
342+
" self.__nx += 1\n" +
343+
" return self.__x\n" +
344+
"\n" +
345+
" @x.setter\n" +
346+
" def x(self, value):\n" +
347+
" self.__nx += 1\n" +
348+
" self.__x = value\n" +
349+
"\n" +
350+
" @property\n" +
351+
" def y(self):\n" +
352+
" self.__ny += 1\n" +
353+
" return self.__y\n" +
354+
"\n" +
355+
"p = P()\n" +
356+
"str(p)\n" +
357+
"\n", "testGettersSetters.py").buildLiteral();
358+
try (DebuggerSession session = tester.startSession()) {
359+
session.suspendNextExecution();
360+
tester.startEval(source);
361+
expectSuspended((SuspendedEvent event) -> {
362+
DebugStackFrame frame = event.getTopStackFrame();
363+
assertEquals(1, frame.getSourceSection().getStartLine());
364+
event.prepareStepOver(5);
365+
});
366+
expectSuspended((SuspendedEvent event) -> {
367+
DebugStackFrame frame = event.getTopStackFrame();
368+
assertEquals("p = P()", frame.getSourceSection().getCharacters().toString());
369+
event.prepareStepOver(1);
370+
});
371+
expectSuspended((SuspendedEvent event) -> {
372+
DebugValue p = session.getTopScope("python").getDeclaredValue("p");
373+
DebugValue x = p.getProperty("x");
374+
assertTrue(x.hasReadSideEffects());
375+
assertTrue(x.hasWriteSideEffects());
376+
assertTrue(x.isReadable());
377+
assertTrue(x.isWritable());
378+
DebugValue nx = p.getProperty("__nx");
379+
assertEquals(0, nx.as(Number.class).intValue());
380+
assertEquals("None", x.as(String.class));
381+
assertEquals(1, nx.as(Number.class).intValue());
382+
x.set(42);
383+
assertEquals(2, nx.as(Number.class).intValue());
384+
assertEquals("42", x.as(String.class));
385+
assertEquals(3, nx.as(Number.class).intValue());
386+
DebugValue y = p.getProperty("y");
387+
assertTrue(y.hasReadSideEffects());
388+
assertTrue(y.hasWriteSideEffects());
389+
assertTrue(y.isReadable());
390+
assertTrue(y.isWritable());
391+
DebugValue ny = p.getProperty("__ny");
392+
assertEquals(0, ny.as(Number.class).intValue());
393+
y.set(24);
394+
assertEquals("24", y.as(String.class));
395+
});
396+
}
397+
}
398+
329399
private void expectSuspended(SuspendedCallback callback) {
330400
tester.expectSuspended(callback);
331401
}

0 commit comments

Comments
 (0)