Exemplo n.º 1
0
def test_ass_dict():
    missing = object()
    x = psyco.compact()
    x.a = 5
    assert x.__dict__ == {'a': 5}
    x.__dict__ = {'b': 6}
    assert x.b == 6
    assert getattr(x, 'a', missing) is missing
    assert x.__dict__ == {'b': 6}
    y = psyco.compact()
    y.__dict__ = x.__dict__
    assert y.__dict__ == {'b': 6}
    y.__dict__ = y.__dict__
    assert y.__dict__ == {'b': 6}
Exemplo n.º 2
0
def test_ass_dict():
    missing = object()
    x = psyco.compact()
    x.a = 5
    assert x.__dict__ == {'a': 5}
    x.__dict__ = {'b': 6}
    assert x.b == 6
    assert getattr(x, 'a', missing) is missing
    assert x.__dict__ == {'b': 6}
    y = psyco.compact()
    y.__dict__ = x.__dict__
    assert y.__dict__ == {'b': 6}
    y.__dict__ = y.__dict__
    assert y.__dict__ == {'b': 6}
Exemplo n.º 3
0
def do_test_1(objects):
    d = [{} for i in range(20)]
    s = [psyco.compact() for i in range(20)]
    attrnames = list('abcdefghijklmnopqrstuvwxyz')
    for j in range(5000):
        i = random.randrange(0, 20)
        attr = random.choice(attrnames)
        if random.randrange(0, 2):
            if attr in d[i]:
                if random.randrange(0,5) == 3:
                    delattr(s[i], attr)
                    del d[i][attr]
                else:
                    assert d[i][attr] == getattr(s[i], attr)
            else:
                try:
                    getattr(s[i], attr)
                except AttributeError:
                    pass
                else:
                    raise AssertionError, attr
        else:
            obj = random.choice(objects)
            setattr(s[i], attr, obj)
            d[i][attr] = obj
    for i in range(20):
        d1 = {}
        for attr in attrnames:
            try:
                d1[attr] = getattr(s[i], attr)
            except AttributeError:
                pass
        assert d[i] == d1
Exemplo n.º 4
0
def do_test_1(objects):
    d = [{} for i in range(20)]
    s = [psyco.compact() for i in range(20)]
    attrnames = list('abcdefghijklmnopqrstuvwxyz')
    for j in range(5000):
        i = random.randrange(0, 20)
        attr = random.choice(attrnames)
        if random.randrange(0, 2):
            if attr in d[i]:
                if random.randrange(0,5) == 3:
                    delattr(s[i], attr)
                    del d[i][attr]
                else:
                    assert d[i][attr] == getattr(s[i], attr)
            else:
                try:
                    getattr(s[i], attr)
                except AttributeError:
                    pass
                else:
                    raise AssertionError, attr
        else:
            obj = random.choice(objects)
            setattr(s[i], attr, obj)
            d[i][attr] = obj
    for i in range(20):
        d1 = {}
        for attr in attrnames:
            try:
                d1[attr] = getattr(s[i], attr)
            except AttributeError:
                pass
        assert d[i] == d1
Exemplo n.º 5
0
def pcompact_test():
    k = psyco.compact()
    k.x = 12
    k.z = None
    k.y = 'hello'
    print read_x(k)
    print read_y(k)
    print read_z(k)
Exemplo n.º 6
0
def pcompact_test():
    k = psyco.compact()
    k.x = 12
    k.z = None
    k.y = 'hello'
    print read_x(k)
    print read_y(k)
    print read_z(k)
Exemplo n.º 7
0
def pcompact_modif(obj):
    base = sys.getrefcount(obj)
    for i in range(21):
        k = psyco.compact()
        #k.x = i+1
        #k.y = (i*2,i*3,i*4,i*5,i*6,i*7)
        k.x = obj
        print k.x,
        print sys.getrefcount(obj) - base,
        k.x = i+1
        print sys.getrefcount(obj) - base,
        print k.x
        #k.x = len
        #k.x = i+2
        #print k.x, k.y
    print sys.getrefcount(obj) - base
Exemplo n.º 8
0
def pcompact_modif(obj):
    base = sys.getrefcount(obj)
    for i in range(21):
        k = psyco.compact()
        #k.x = i+1
        #k.y = (i*2,i*3,i*4,i*5,i*6,i*7)
        k.x = obj
        print k.x,
        print sys.getrefcount(obj) - base,
        k.x = i+1
        print sys.getrefcount(obj) - base,
        print k.x
        #k.x = len
        #k.x = i+2
        #print k.x, k.y
    print sys.getrefcount(obj) - base
Exemplo n.º 9
0
def pcompact_creat(obj):
    base = sys.getrefcount(obj)
    items = []
    for i in range(11):
        k = psyco.compact()
        k.x = (0,i,i*2)
        k.y = i+1
        k.z = None
        k.t = obj
        k.y = i+2
        k.y = i+3
        print k.x, k.y, k.z, k.t
        items.append(k)
        del k
    print sys.getrefcount(obj) - base
    del items[:]
    print sys.getrefcount(obj) - base
Exemplo n.º 10
0
def pcompact_creat(obj):
    base = sys.getrefcount(obj)
    items = []
    for i in range(11):
        k = psyco.compact()
        k.x = (0,i,i*2)
        k.y = i+1
        k.z = None
        k.t = obj
        k.y = i+2
        k.y = i+3
        print k.x, k.y, k.z, k.t
        items.append(k)
        del k
    print sys.getrefcount(obj) - base
    del items[:]
    print sys.getrefcount(obj) - base
Exemplo n.º 11
0
 def f2(): psyco.compact(12)
 def f3(): ClassWithNoInit(21)
Exemplo n.º 12
0
 def f2(): psyco.compact(12)
 def f3(): ClassWithNoInit(21)