~canonical-livepatch-dependencies/canonical-livepatch-service-dependencies/sqlalchemy

« back to all changes in this revision

Viewing changes to test/aaa_profiling/test_compiler.py

  • Committer: Free Ekanayaka
  • Author(s): Piotr Ożarowski
  • Date: 2016-06-05 20:53:44 UTC
  • Revision ID: free.ekanayaka@canonical.com-20160605205344-y5n5bo3sf9oc1irq
Tags: upstream-1.0.13+ds1
Import upstream version 1.0.13+ds1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from sqlalchemy.engine import default
 
2
from sqlalchemy.testing import fixtures, AssertsExecutionResults, profiling
 
3
from sqlalchemy import MetaData, Table, Column, Integer, String, select
 
4
 
 
5
t1 = t2 = None
 
6
 
 
7
 
 
8
class CompileTest(fixtures.TestBase, AssertsExecutionResults):
 
9
    __requires__ = 'cpython',
 
10
    __backend__ = True
 
11
 
 
12
    @classmethod
 
13
    def setup_class(cls):
 
14
 
 
15
        global t1, t2, metadata
 
16
        metadata = MetaData()
 
17
        t1 = Table('t1', metadata,
 
18
                   Column('c1', Integer, primary_key=True),
 
19
                   Column('c2', String(30)))
 
20
 
 
21
        t2 = Table('t2', metadata,
 
22
                   Column('c1', Integer, primary_key=True),
 
23
                   Column('c2', String(30)))
 
24
 
 
25
        # do a "compile" ahead of time to load
 
26
        # deferred imports
 
27
        t1.insert().compile()
 
28
 
 
29
        # go through all the TypeEngine
 
30
        # objects in use and pre-load their _type_affinity
 
31
        # entries.
 
32
        for t in (t1, t2):
 
33
            for c in t.c:
 
34
                c.type._type_affinity
 
35
        from sqlalchemy import types
 
36
        for t in list(types._type_map.values()):
 
37
            t._type_affinity
 
38
 
 
39
        cls.dialect = default.DefaultDialect()
 
40
 
 
41
    @profiling.function_call_count()
 
42
    def test_insert(self):
 
43
        t1.insert().compile(dialect=self.dialect)
 
44
 
 
45
    @profiling.function_call_count(variance=.15)
 
46
    def test_update(self):
 
47
        t1.update().compile(dialect=self.dialect)
 
48
 
 
49
    def test_update_whereclause(self):
 
50
        t1.update().where(t1.c.c2 == 12).compile(dialect=self.dialect)
 
51
 
 
52
        @profiling.function_call_count()
 
53
        def go():
 
54
            t1.update().where(t1.c.c2 == 12).compile(dialect=self.dialect)
 
55
        go()
 
56
 
 
57
    def test_select(self):
 
58
        # give some of the cached type values
 
59
        # a chance to warm up
 
60
        s = select([t1], t1.c.c2 == t2.c.c1)
 
61
        s.compile(dialect=self.dialect)
 
62
 
 
63
        @profiling.function_call_count()
 
64
        def go():
 
65
            s = select([t1], t1.c.c2 == t2.c.c1)
 
66
            s.compile(dialect=self.dialect)
 
67
        go()
 
68
 
 
69
    def test_select_labels(self):
 
70
        # give some of the cached type values
 
71
        # a chance to warm up
 
72
        s = select([t1], t1.c.c2 == t2.c.c1).apply_labels()
 
73
        s.compile(dialect=self.dialect)
 
74
 
 
75
        @profiling.function_call_count()
 
76
        def go():
 
77
            s = select([t1], t1.c.c2 == t2.c.c1).apply_labels()
 
78
            s.compile(dialect=self.dialect)
 
79
        go()