File: test.py

package info (click to toggle)
libgnatcoll 1.6gpl2014-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 22,760 kB
  • ctags: 10,162
  • sloc: ada: 132,013; ansic: 94,291; python: 3,762; sh: 2,781; cpp: 1,394; makefile: 342; xml: 31; sql: 6
file content (44 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import GPS
import sys

def test_myclass():
    sys.stdout.write("start test_myclass\n")
    sys.stdout.flush()

    c = GPS.MyClass()
    sys.stdout.write("c.refcount=%d\n" % (sys.getrefcount(c), ))
    sys.stdout.flush()
    c = None

    c2 = GPS.MyClass.get()
    sys.stdout.write("c2.refcount=%d\n" % (sys.getrefcount(c2), ))
    sys.stdout.flush()
    c2 = None

    sys.stdout.write("finish test_myclass\n")
    sys.stdout.flush()

def test_cache():
    sys.stdout.write("start test_cache\n")
    sys.stdout.flush()

    c = GPS.Cache.get()
    sys.stdout.write("c.value=%s  c.refcount=%d\n" % (c.value(), sys.getrefcount(c)))
    sys.stdout.flush()
    c.foo = 1
    c = None

    c2 = GPS.Cache.get()
    sys.stdout.write("c2.foo=%s\n" % getattr(c2, "foo", None))
    sys.stdout.write("c2.value=%s  c2.refcount=%d\n" % (c2.value(), sys.getrefcount(c2)))
    sys.stdout.flush()

    c2.destroy()    # Simulate a free from Ada
    c2 = None       # The last ref was hold by python

    sys.stdout.write("finish test_cache\n")
    sys.stdout.flush()

test_myclass()
sys.stdout.write("\n")
test_cache()