~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to test/aaa_profiling/test_orm.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from test.lib.testing import eq_, assert_raises, \
 
1
from sqlalchemy.testing import eq_, assert_raises, \
2
2
    assert_raises_message
3
3
from sqlalchemy import exc as sa_exc, util, Integer, String, ForeignKey
4
4
from sqlalchemy.orm import exc as orm_exc, mapper, relationship, \
5
5
    sessionmaker, Session
6
 
from test.lib import testing, profiling
7
 
from test.lib import fixtures
8
 
from test.lib.schema import Table, Column
 
6
from sqlalchemy import testing
 
7
from sqlalchemy.testing import profiling
 
8
from sqlalchemy.testing import fixtures
 
9
from sqlalchemy.testing.schema import Table, Column
9
10
import sys
10
11
 
11
12
class MergeTest(fixtures.MappedTest):
58
59
        # down from 185 on this this is a small slice of a usually
59
60
        # bigger operation so using a small variance
60
61
 
61
 
        @profiling.function_call_count()
62
 
        def go():
 
62
        @profiling.function_call_count(variance=0.10)
 
63
        def go1():
63
64
            return sess2.merge(p1, load=False)
64
 
        p2 = go()
 
65
        p2 = go1()
65
66
 
66
67
        # third call, merge object already present. almost no calls.
67
68
 
68
 
        @profiling.function_call_count()
69
 
        def go():
 
69
        @profiling.function_call_count(variance=0.10)
 
70
        def go2():
70
71
            return sess2.merge(p2, load=False)
71
 
        p3 = go()
 
72
        go2()
72
73
 
73
74
    def test_merge_load(self):
74
75
        Parent = self.classes.Parent
89
90
 
90
91
        # one more time, count the SQL
91
92
 
 
93
        def go2():
 
94
            p2 = sess2.merge(p1)
92
95
        sess2 = sessionmaker(testing.db)()
93
 
        self.assert_sql_count(testing.db, go, 2)
 
96
        self.assert_sql_count(testing.db, go2, 2)
94
97
 
95
98
class LoadManyToOneFromIdentityTest(fixtures.MappedTest):
96
99
    """test overhead associated with many-to-one fetches.
159
162
        parents = sess.query(Parent).all()
160
163
 
161
164
 
162
 
        @profiling.function_call_count()
 
165
        @profiling.function_call_count(variance=.2)
163
166
        def go():
164
167
            for p in parents:
165
168
                p.child
239
242
        ])
240
243
        s.commit()
241
244
 
242
 
    @profiling.function_call_count()
 
245
    @profiling.function_call_count(variance=.10)
243
246
    def test_merge_pending_with_all_pks(self):
244
247
        A, B, C, D = self.classes.A, self.classes.B, \
245
248
                    self.classes.C, self.classes.D