summaryrefslogtreecommitdiff
path: root/test/aaa_profiling/test_compiler.py
blob: 18d0118f142b80d2ceeca0161c292afe3eb5469a (plain)
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
45
46
47
48
49
50
51
52
53
from sqlalchemy import *
from test.lib import *
from sqlalchemy.engine import default

class CompileTest(TestBase, AssertsExecutionResults):
    @classmethod
    def setup_class(cls):

        global t1, t2, metadata
        metadata = MetaData()
        t1 = Table('t1', metadata,
            Column('c1', Integer, primary_key=True),
            Column('c2', String(30)))

        t2 = Table('t2', metadata,
            Column('c1', Integer, primary_key=True),
            Column('c2', String(30)))

        # do a "compile" ahead of time to load
        # deferred imports
        t1.insert().compile()

        # go through all the TypeEngine
        # objects in use and pre-load their _type_affinity
        # entries.
        for t in (t1, t2):
            for c in t.c:
                c.type._type_affinity
        from sqlalchemy import types
        for t in types._type_map.values():
            t._type_affinity

        cls.dialect = default.DefaultDialect()

    @profiling.function_call_count(versions={'2.7':58, '2.6':58,
                                            '3':64})
    def test_insert(self):
        t1.insert().compile(dialect=self.dialect)

    @profiling.function_call_count(versions={'2.6':49, '2.7':49})
    def test_update(self):
        t1.update().compile(dialect=self.dialect)

    @profiling.function_call_count(versions={'2.6':110, '2.7':110, '3':115})
    def test_update_whereclause(self):
        t1.update().where(t1.c.c2==12).compile(dialect=self.dialect)

    @profiling.function_call_count(versions={'2.7':148, '2.6':148,
                                                '3':161})
    def test_select(self):
        s = select([t1], t1.c.c2==t2.c.c1)
        s.compile(dialect=self.dialect)