コード例 #1
0
ファイル: test_mapdict.py プロジェクト: charred/pypy
 def test_mix_classes_attribute(self):
     import __pypy__
     seen = []
     for i in range(20):
         class A(object):
             def __init__(self):
                 self.x = 42
         class B(object):
             def __init__(self):
                 self.x = 43
         class C(object):
             def __init__(self):
                 self.x = 44
         l = [A(), B(), C()] * 10
         __pypy__.reset_method_cache_counter()
         for i, a in enumerate(l):
             assert a.x == 42 + i % 3
         cache_counter = __pypy__.mapdict_cache_counter("x")
         if cache_counter == (27, 3):
             break
         # keep them alive, to make sure that on the
         # next try they have difference addresses
         seen.append((l, cache_counter))
     else:
         assert 0, "failed: got %r" % ([got[1] for got in seen],)
コード例 #2
0
ファイル: test_mapdict.py プロジェクト: charred/pypy
 def test_mix_classes(self):
     import __pypy__
     seen = []
     for i in range(20):
         class A(object):
             def f(self):
                 return 42
         class B(object):
             def f(self):
                 return 43
         class C(object):
             def f(self):
                 return 44
         l = [A(), B(), C()] * 10
         __pypy__.reset_method_cache_counter()
         # 'exec' to make sure that a.f() is compiled with CALL_METHOD
         exec """for i, a in enumerate(l):
                     assert a.f() == 42 + i % 3
         """ in locals()
         cache_counter = __pypy__.mapdict_cache_counter("f")
         if cache_counter == (27, 3):
             break
         # keep them alive, to make sure that on the
         # next try they have difference addresses
         seen.append((l, cache_counter))
     else:
         assert 0, "failed: got %r" % ([got[1] for got in seen],)
コード例 #3
0
ファイル: test_mapdict.py プロジェクト: zcxowwww/pypy
    def test_mix_classes_attribute(self):
        import __pypy__
        seen = []
        for i in range(20):

            class A(object):
                def __init__(self):
                    self.x = 42

            class B(object):
                def __init__(self):
                    self.x = 43

            class C(object):
                def __init__(self):
                    self.x = 44

            l = [A(), B(), C()] * 10
            __pypy__.reset_method_cache_counter()
            for i, a in enumerate(l):
                assert a.x == 42 + i % 3
            cache_counter = __pypy__.mapdict_cache_counter("x")
            if cache_counter == (27, 3):
                break
            # keep them alive, to make sure that on the
            # next try they have difference addresses
            seen.append((l, cache_counter))
        else:
            assert 0, "failed: got %r" % ([got[1] for got in seen], )
コード例 #4
0
ファイル: test_mapdict.py プロジェクト: zcxowwww/pypy
    def test_mix_classes(self):
        import __pypy__
        seen = []
        for i in range(20):

            class A(object):
                def f(self):
                    return 42

            class B(object):
                def f(self):
                    return 43

            class C(object):
                def f(self):
                    return 44

            l = [A(), B(), C()] * 10
            __pypy__.reset_method_cache_counter()
            # 'exec' to make sure that a.f() is compiled with CALL_METHOD
            exec """for i, a in enumerate(l):
                        assert a.f() == 42 + i % 3
            """ in locals()
            cache_counter = __pypy__.mapdict_cache_counter("f")
            if cache_counter == (27, 3):
                break
            # keep them alive, to make sure that on the
            # next try they have difference addresses
            seen.append((l, cache_counter))
        else:
            assert 0, "failed: got %r" % ([got[1] for got in seen], )
コード例 #5
0
ファイル: test_mapdict.py プロジェクト: ieure/pypy
 def test_mix_classes_attribute(self):
     import __pypy__
     class A(object):
         def __init__(self):
             self.x = 42
     class B(object):
         def __init__(self):
             self.x = 43
     class C(object):
         def __init__(self):
             self.x = 44
     l = [A(), B(), C()] * 10
     __pypy__.reset_method_cache_counter()
     for i, a in enumerate(l):
         assert a.x == 42 + i % 3
     cache_counter = __pypy__.mapdict_cache_counter("x")
     assert cache_counter[0] >= 15
     assert cache_counter[1] >= 3 # should be (27, 3)
     assert sum(cache_counter) == 30
コード例 #6
0
ファイル: test_mapdict.py プロジェクト: ieure/pypy
    def test_mix_classes(self):
        import __pypy__
        class A(object):
            def f(self):
                return 42
        class B(object):
            def f(self):
                return 43
        class C(object):
            def f(self):
                return 44
        l = [A(), B(), C()] * 10
        __pypy__.reset_method_cache_counter()
        # 'exec' to make sure that a.f() is compiled with CALL_METHOD
        exec """for i, a in enumerate(l):
                    assert a.f() == 42 + i % 3
"""
        cache_counter = __pypy__.mapdict_cache_counter("f")
        assert cache_counter[0] >= 15
        assert cache_counter[1] >= 3 # should be (27, 3)
        assert sum(cache_counter) == 30