File: test.py

package info (click to toggle)
libgnatcoll 1.7gpl2015-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,280 kB
  • ctags: 1,124
  • sloc: ada: 134,072; python: 4,017; cpp: 1,397; ansic: 1,234; makefile: 368; sh: 152; 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()